Skip to content

Commit 57a53c6

Browse files
committed
call mutations for isIdPending state in actions
1 parent 71cdd57 commit 57a53c6

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/service-module/service-module.actions.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export default function makeServiceActions(service: Service<any>) {
9999
params = params || {}
100100

101101
commit('setPending', 'create')
102+
commit('setIdPending', { method: 'create', id: tempIds })
102103

103104
return service
104105
.create(data, params)
@@ -121,34 +122,39 @@ export default function makeServiceActions(service: Service<any>) {
121122

122123
// response = state.keyedById[id]
123124
}
124-
commit('unsetPending', 'create')
125125
commit('removeTemps', tempIds)
126126
return response
127127
})
128128
.catch(error => {
129129
commit('setError', { method: 'create', error })
130-
commit('unsetPending', 'create')
131130
return Promise.reject(error)
132131
})
132+
.finally(() => {
133+
commit('unsetPending', 'create')
134+
commit('unsetIdPending', { method: 'create', id: tempIds })
135+
})
133136
},
134137

135138
update({ commit, dispatch, state }, [id, data, params]) {
136139
commit('setPending', 'update')
140+
commit('setIdPending', { method: 'update', id })
137141

138142
params = fastCopy(params)
139143

140144
return service
141145
.update(id, data, params)
142146
.then(async function (item) {
143147
dispatch('addOrUpdate', item)
144-
commit('unsetPending', 'update')
145148
return state.keyedById[id]
146149
})
147150
.catch(error => {
148151
commit('setError', { method: 'update', error })
149-
commit('unsetPending', 'update')
150152
return Promise.reject(error)
151153
})
154+
.finally(() => {
155+
commit('unsetPending', 'update')
156+
commit('unsetIdPending', { method: 'update', id })
157+
})
152158
},
153159

154160
/**
@@ -157,6 +163,7 @@ export default function makeServiceActions(service: Service<any>) {
157163
*/
158164
patch({ commit, dispatch, state }, [id, data, params]) {
159165
commit('setPending', 'patch')
166+
commit('setIdPending', { method: 'patch', id })
160167

161168
params = fastCopy(params)
162169

@@ -171,14 +178,16 @@ export default function makeServiceActions(service: Service<any>) {
171178
.patch(id, data, params)
172179
.then(async function (item) {
173180
dispatch('addOrUpdate', item)
174-
commit('unsetPending', 'patch')
175181
return state.keyedById[id]
176182
})
177183
.catch(error => {
178184
commit('setError', { method: 'patch', error })
179-
commit('unsetPending', 'patch')
180185
return Promise.reject(error)
181186
})
187+
.finally(() => {
188+
commit('unsetPending', 'patch')
189+
commit('unsetIdPending', { method: 'patch', id })
190+
})
182191
},
183192

184193
remove({ commit }, idOrArray) {
@@ -196,19 +205,22 @@ export default function makeServiceActions(service: Service<any>) {
196205
params = fastCopy(params)
197206

198207
commit('setPending', 'remove')
208+
commit('setIdPending', { method: 'remove', id })
199209

200210
return service
201211
.remove(id, params)
202212
.then(item => {
203213
commit('removeItem', id)
204-
commit('unsetPending', 'remove')
205214
return item
206215
})
207216
.catch(error => {
208217
commit('setError', { method: 'remove', error })
209-
commit('unsetPending', 'remove')
210218
return Promise.reject(error)
211219
})
220+
.finally(() => {
221+
commit('unsetPending', 'remove')
222+
commit('unsetIdPending', { method: 'remove', id })
223+
})
212224
}
213225
}
214226

0 commit comments

Comments
 (0)