@@ -145,28 +145,6 @@ export default function makeServiceMutations (servicePath, { debug, globalModels
145
145
}
146
146
} ,
147
147
148
- clearAll ( state ) {
149
- state . ids = [ ]
150
- state . currentId = null
151
- state . copy = null
152
- state . keyedById = { }
153
- } ,
154
-
155
- clearList ( state ) {
156
- let currentId = state . currentId
157
- let current = state . keyedById [ currentId ]
158
-
159
- if ( currentId && current ) {
160
- state . keyedById = {
161
- [ currentId ] : current
162
- }
163
- state . ids = [ currentId ]
164
- } else {
165
- state . keyedById = { }
166
- state . ids = [ ]
167
- }
168
- } ,
169
-
170
148
setCurrent ( state , itemOrId ) {
171
149
const { idField } = state
172
150
const Model = globalModels . byServicePath [ servicePath ]
@@ -190,13 +168,6 @@ export default function makeServiceMutations (servicePath, { debug, globalModels
190
168
state . copy = null
191
169
} ,
192
170
193
- // Removes the copy from copiesById
194
- clearCopy ( state , id ) {
195
- const newCopiesById = Object . assign ( { } , state . copiesById )
196
- delete newCopiesById [ id ]
197
- state . copiesById = newCopiesById
198
- } ,
199
-
200
171
// Creates a copy of the record with the passed-in id, stores it in copiesById
201
172
createCopy ( state , id ) {
202
173
const current = state . keyedById [ id ]
@@ -211,8 +182,8 @@ export default function makeServiceMutations (servicePath, { debug, globalModels
211
182
}
212
183
} ,
213
184
214
- // Resets the copy to match the original record, locally
215
- rejectCopy ( state , id ) {
185
+ // Deep assigns copy to original record, locally
186
+ commitCopy ( state , id ) {
216
187
const isIdOk = checkId ( id , undefined , debug )
217
188
const current = isIdOk ? state . keyedById [ id ] : state . keyedById [ state . currentId ]
218
189
const Model = globalModels . byServicePath [ servicePath ]
@@ -224,11 +195,13 @@ export default function makeServiceMutations (servicePath, { debug, globalModels
224
195
copy = Model . copiesById [ id ]
225
196
}
226
197
227
- _merge ( copy , current )
228
- } ,
198
+ updateOriginal ( copy , current )
229
199
230
- // Deep assigns copy to original record, locally
231
- commitCopy ( state , id ) {
200
+ // Object.assign(current, copy)
201
+ } ,
202
+
203
+ // Resets the copy to match the original record, locally
204
+ rejectCopy ( state , id ) {
232
205
const isIdOk = checkId ( id , undefined , debug )
233
206
const current = isIdOk ? state . keyedById [ id ] : state . keyedById [ state . currentId ]
234
207
const Model = globalModels . byServicePath [ servicePath ]
@@ -240,9 +213,36 @@ export default function makeServiceMutations (servicePath, { debug, globalModels
240
213
copy = Model . copiesById [ id ]
241
214
}
242
215
243
- updateOriginal ( copy , current )
216
+ _merge ( copy , current )
217
+ } ,
244
218
245
- // Object.assign(current, copy)
219
+ // Removes the copy from copiesById
220
+ clearCopy ( state , id ) {
221
+ const newCopiesById = Object . assign ( { } , state . copiesById )
222
+ delete newCopiesById [ id ]
223
+ state . copiesById = newCopiesById
224
+ } ,
225
+
226
+ clearAll ( state ) {
227
+ state . ids = [ ]
228
+ state . currentId = null
229
+ state . copy = null
230
+ state . keyedById = { }
231
+ } ,
232
+
233
+ clearList ( state ) {
234
+ let currentId = state . currentId
235
+ let current = state . keyedById [ currentId ]
236
+
237
+ if ( currentId && current ) {
238
+ state . keyedById = {
239
+ [ currentId ] : current
240
+ }
241
+ state . ids = [ currentId ]
242
+ } else {
243
+ state . keyedById = { }
244
+ state . ids = [ ]
245
+ }
246
246
} ,
247
247
248
248
// Stores pagination data on state.pagination based on the query identifier (qid)
0 commit comments