@@ -34,8 +34,8 @@ export type PendingIdServiceMethodName = Exclude<
34
34
export default function makeServiceMutations ( ) {
35
35
function addItems ( state , items ) {
36
36
const { serverAlias, idField, tempIdField, modelName } = state
37
- const Model = _get ( models , `[ ${ serverAlias } ][ ${ modelName } ]` )
38
- const BaseModel = _get ( models , `[ ${ serverAlias } ]. BaseModel` )
37
+ const Model = _get ( models , [ serverAlias , modelName ] )
38
+ const BaseModel = _get ( models , [ serverAlias , ' BaseModel' ] )
39
39
40
40
for ( let item of items ) {
41
41
const id = getId ( item , idField )
@@ -69,8 +69,8 @@ export default function makeServiceMutations() {
69
69
70
70
function updateItems ( state , items ) {
71
71
const { idField, replaceItems, addOnUpsert, serverAlias, modelName } = state
72
- const Model = _get ( models , `[ ${ serverAlias } ][ ${ modelName } ]` )
73
- const BaseModel = _get ( models , `[ ${ state . serverAlias } ]. BaseModel` )
72
+ const Model = _get ( models , [ serverAlias , modelName ] )
73
+ const BaseModel = _get ( models , [ state . serverAlias , ' BaseModel' ] )
74
74
75
75
for ( let item of items ) {
76
76
const id = getId ( item , idField )
@@ -121,7 +121,7 @@ export default function makeServiceMutations() {
121
121
}
122
122
123
123
function mergeInstance ( state , item ) {
124
- const { serverAlias , idField, tempIdField , modelName } = state
124
+ const { idField } = state
125
125
const id = getId ( item , idField )
126
126
const existingItem = state . keyedById [ id ]
127
127
if ( existingItem ) {
@@ -172,7 +172,7 @@ export default function makeServiceMutations() {
172
172
}
173
173
174
174
// Add _id to temp's clone as well if it exists
175
- const Model = _get ( models , `[ ${ state . serverAlias } ][ ${ state . modelName } ]` )
175
+ const Model = _get ( models , [ state . serverAlias , state . modelName ] )
176
176
const tempClone = Model && Model . copiesById && Model . copiesById [ tempId ]
177
177
if ( tempClone ) {
178
178
tempClone [ state . idField ] = id
@@ -262,10 +262,7 @@ export default function makeServiceMutations() {
262
262
createCopy ( state , id ) {
263
263
const { servicePath, keepCopiesInStore, serverAlias } = state
264
264
const current = state . keyedById [ id ] || state . tempsById [ id ]
265
- const Model = _get (
266
- models ,
267
- `[${ serverAlias } ].byServicePath[${ servicePath } ]`
268
- )
265
+ const Model = _get ( models , [ serverAlias , 'byServicePath' , servicePath ] )
269
266
270
267
if ( Model ) {
271
268
var model = new Model ( current , { clone : true } )
@@ -291,13 +288,14 @@ export default function makeServiceMutations() {
291
288
// Resets the copy to match the original record, locally
292
289
resetCopy ( state , id ) {
293
290
const { servicePath, keepCopiesInStore } = state
294
- const Model = _get (
295
- models ,
296
- `[${ state . serverAlias } ].byServicePath[${ servicePath } ]`
297
- )
291
+ const Model = _get ( models , [
292
+ state . serverAlias ,
293
+ 'byServicePath' ,
294
+ servicePath
295
+ ] )
298
296
const copy = keepCopiesInStore
299
297
? state . copiesById [ id ]
300
- : Model && _get ( Model , `copiesById[ ${ id } ]` )
298
+ : Model && _get ( Model , [ 'copiesById' , id ] )
301
299
302
300
if ( copy ) {
303
301
const original =
@@ -311,13 +309,14 @@ export default function makeServiceMutations() {
311
309
// Deep assigns copy to original record, locally
312
310
commitCopy ( state , id ) {
313
311
const { servicePath, keepCopiesInStore } = state
314
- const Model = _get (
315
- models ,
316
- `[${ state . serverAlias } ].byServicePath[${ servicePath } ]`
317
- )
312
+ const Model = _get ( models , [
313
+ state . serverAlias ,
314
+ 'byServicePath' ,
315
+ servicePath
316
+ ] )
318
317
const copy = keepCopiesInStore
319
318
? state . copiesById [ id ]
320
- : Model && _get ( Model , `copiesById[ ${ id } ]` )
319
+ : Model && _get ( Model , [ 'copiesById' , id ] )
321
320
322
321
if ( copy ) {
323
322
const original =
@@ -397,10 +396,15 @@ export default function makeServiceMutations() {
397
396
state [ `is${ uppercaseMethod } Pending` ] = false
398
397
} ,
399
398
400
- setIdPending ( state , payload : { method : PendingIdServiceMethodName , id : Id | Id [ ] } ) : void {
399
+ setIdPending (
400
+ state ,
401
+ payload : { method : PendingIdServiceMethodName ; id : Id | Id [ ] }
402
+ ) : void {
401
403
const { method, id } = payload
402
404
const uppercaseMethod = method . charAt ( 0 ) . toUpperCase ( ) + method . slice ( 1 )
403
- const isIdMethodPending = state [ `isId${ uppercaseMethod } Pending` ] as ServiceState [ 'isIdCreatePending' ]
405
+ const isIdMethodPending = state [
406
+ `isId${ uppercaseMethod } Pending`
407
+ ] as ServiceState [ 'isIdCreatePending' ]
404
408
// if `id` is an array, ensure it doesn't have duplicates
405
409
const ids = Array . isArray ( id ) ? [ ...new Set ( id ) ] : [ id ]
406
410
ids . forEach ( id => {
@@ -409,10 +413,15 @@ export default function makeServiceMutations() {
409
413
}
410
414
} )
411
415
} ,
412
- unsetIdPending ( state , payload : { method : PendingIdServiceMethodName , id : Id | Id [ ] } ) : void {
416
+ unsetIdPending (
417
+ state ,
418
+ payload : { method : PendingIdServiceMethodName ; id : Id | Id [ ] }
419
+ ) : void {
413
420
const { method, id } = payload
414
421
const uppercaseMethod = method . charAt ( 0 ) . toUpperCase ( ) + method . slice ( 1 )
415
- const isIdMethodPending = state [ `isId${ uppercaseMethod } Pending` ] as ServiceState [ 'isIdCreatePending' ]
422
+ const isIdMethodPending = state [
423
+ `isId${ uppercaseMethod } Pending`
424
+ ] as ServiceState [ 'isIdCreatePending' ]
416
425
// if `id` is an array, ensure it doesn't have duplicates
417
426
const ids = Array . isArray ( id ) ? [ ...new Set ( id ) ] : [ id ]
418
427
ids . forEach ( id => {
0 commit comments