@@ -173,9 +173,17 @@ export default function makeServiceMutations() {
173
173
const isIdOk = idToBeRemoved !== null && idToBeRemoved !== undefined
174
174
const index = state . ids . findIndex ( i => i === idToBeRemoved )
175
175
176
+ const Model = _get ( models , `[${ state . serverAlias } ][${ state . modelName } ]` )
177
+ const copiesById = state . keepCopiesInStore
178
+ ? state . copiesById
179
+ : Model . copiesById
180
+
176
181
if ( isIdOk && index !== null && index !== undefined ) {
177
182
Vue . delete ( state . ids , index )
178
183
Vue . delete ( state . keyedById , idToBeRemoved )
184
+ if ( copiesById . hasOwnProperty ( idToBeRemoved ) ) {
185
+ Vue . delete ( copiesById , idToBeRemoved )
186
+ }
179
187
}
180
188
} ,
181
189
@@ -211,8 +219,17 @@ export default function makeServiceMutations() {
211
219
map [ id ] = true
212
220
return map
213
221
} , { } )
222
+
223
+ const Model = _get ( models , `[${ state . serverAlias } ][${ state . modelName } ]` )
224
+ const copiesById = state . keepCopiesInStore
225
+ ? state . copiesById
226
+ : Model . copiesById
227
+
214
228
idsToRemove . forEach ( id => {
215
229
Vue . delete ( state . keyedById , id )
230
+ if ( copiesById . hasOwnProperty ( id ) ) {
231
+ Vue . delete ( copiesById , id )
232
+ }
216
233
} )
217
234
218
235
// Get indexes to remove from the ids array.
@@ -242,6 +259,18 @@ export default function makeServiceMutations() {
242
259
clearAll ( state ) {
243
260
state . ids = [ ]
244
261
state . keyedById = { }
262
+
263
+ if ( state . keepCopiesInStore ) {
264
+ state . copiesById = { }
265
+ } else {
266
+ const Model = _get (
267
+ models ,
268
+ `[${ state . serverAlias } ].byServicePath[${ state . servicePath } ]`
269
+ )
270
+ Object . keys ( Model . copiesById ) . forEach ( k =>
271
+ Vue . delete ( Model . copiesById , k )
272
+ )
273
+ }
245
274
} ,
246
275
247
276
// Creates a copy of the record with the passed-in id, stores it in copiesById
@@ -322,15 +351,15 @@ export default function makeServiceMutations() {
322
351
// Removes the copy from copiesById
323
352
clearCopy ( state , id ) {
324
353
const { keepCopiesInStore } = state
325
- if ( keepCopiesInStore ) {
326
- Vue . delete ( state . copiesById , id )
327
- } else {
328
- const { serverAlias , servicePath } = state
329
- const Model = _get (
330
- models ,
331
- `[ ${ serverAlias } ].byServicePath[ ${ servicePath } ]`
332
- )
333
- Vue . delete ( Model . copiesById , id )
354
+ const Model = _get (
355
+ models ,
356
+ `[ ${ state . serverAlias } ].byServicePath[ ${ state . servicePath } ]`
357
+ )
358
+
359
+ const copiesById = keepCopiesInStore ? state . copiesById : Model . copiesById
360
+
361
+ if ( copiesById [ id ] ) {
362
+ Vue . delete ( copiesById , id )
334
363
}
335
364
} ,
336
365
0 commit comments