66import { FeathersVuexOptions } from './types'
77import { globalModels , prepareAddModel } from './global-models'
88import { mergeWithAccessors , checkNamespace , getId } from '../utils'
9- import _merge from 'lodash/merge'
9+ import _merge from 'lodash/merge'
1010import _get from 'lodash/get'
1111
1212// A hack to prevent error with this.constructor.preferUpdate
@@ -105,10 +105,10 @@ export default function makeModel(options: FeathersVuexOptions) {
105105 ? store . state [ namespace ] . copiesById
106106 : copiesByIdOnModel
107107
108-
109- const existingItem = hasValidId && ! options . clone
110- ? getFromStore . call ( this . constructor , id )
111- : null
108+ const existingItem =
109+ hasValidId && ! options . clone
110+ ? getFromStore . call ( this . constructor , id )
111+ : null
112112
113113 // If it already exists, update the original and return
114114 if ( existingItem ) {
@@ -118,12 +118,16 @@ export default function makeModel(options: FeathersVuexOptions) {
118118 }
119119
120120 // If cloning and a clone already exists, update and return the original clone. Only one clone is allowed.
121- const existingClone = ( hasValidId || hasValidTempId ) && options . clone
122- ? copiesById [ id ] || copiesById [ tempId ]
123- : null
121+ const existingClone =
122+ ( hasValidId || hasValidTempId ) && options . clone
123+ ? copiesById [ id ] || copiesById [ tempId ]
124+ : null
124125 if ( existingClone ) {
125126 // This must be done in a mutation to avoid Vuex errors.
126- _commit . call ( this . constructor , 'merge' , { dest : existingClone , source : data } )
127+ _commit . call ( this . constructor , 'merge' , {
128+ dest : existingClone ,
129+ source : data
130+ } )
127131 return existingClone
128132 }
129133
@@ -137,7 +141,8 @@ export default function makeModel(options: FeathersVuexOptions) {
137141
138142 // Setup instanceDefaults
139143 if ( instanceDefaults && typeof instanceDefaults === 'function' ) {
140- const defaults = instanceDefaults . call ( this , data , { models, store } ) || data
144+ const defaults =
145+ instanceDefaults . call ( this , data , { models, store } ) || data
141146 mergeWithAccessors ( this , defaults )
142147 }
143148
@@ -152,7 +157,7 @@ export default function makeModel(options: FeathersVuexOptions) {
152157
153158 // Add the item to the store
154159 // Make sure originalData wasn't an empty object.
155- if ( ! options . clone && options . commit !== false && store && originalData ) {
160+ if ( ! options . clone && options . commit !== false && store ) {
156161 _commit . call ( this . constructor , 'addItem' , this )
157162 }
158163 return this
@@ -239,7 +244,8 @@ export default function makeModel(options: FeathersVuexOptions) {
239244 if ( this . __isClone ) {
240245 throw new Error ( 'You cannot clone a copy' )
241246 }
242- const id = getId ( this , idField ) != null ? getId ( this , idField ) : this [ tempIdField ]
247+ const id =
248+ getId ( this , idField ) != null ? getId ( this , idField ) : this [ tempIdField ]
243249 return this . _clone ( id )
244250 }
245251
@@ -264,7 +270,10 @@ export default function makeModel(options: FeathersVuexOptions) {
264270 . constructor as typeof BaseModel
265271
266272 if ( this . __isClone ) {
267- const id = getId ( this , idField ) != null ? getId ( this , idField ) : this [ tempIdField ]
273+ const id =
274+ getId ( this , idField ) != null
275+ ? getId ( this , idField )
276+ : this [ tempIdField ]
268277 _commit . call ( this . constructor , 'resetCopy' , id )
269278 return this
270279 } else {
@@ -279,7 +288,10 @@ export default function makeModel(options: FeathersVuexOptions) {
279288 const { idField, tempIdField, _commit, _getters } = this
280289 . constructor as typeof BaseModel
281290 if ( this . __isClone ) {
282- const id = getId ( this , idField ) != null ? getId ( this , idField ) : this [ tempIdField ]
291+ const id =
292+ getId ( this , idField ) != null
293+ ? getId ( this , idField )
294+ : this [ tempIdField ]
283295 _commit . call ( this . constructor , 'commitCopy' , id )
284296
285297 return _getters . call ( this . constructor , 'get' , id )
@@ -324,17 +336,11 @@ export default function makeModel(options: FeathersVuexOptions) {
324336
325337 if ( id == null ) {
326338 const error = new Error (
327- `Missing ${
328- idField
329- } property. You must create the data before you can patch with this data`
339+ `Missing ${ idField } property. You must create the data before you can patch with this data`
330340 )
331341 return Promise . reject ( error )
332342 }
333- return _dispatch . call ( this . constructor , 'patch' , [
334- id ,
335- this ,
336- params
337- ] )
343+ return _dispatch . call ( this . constructor , 'patch' , [ id , this , params ] )
338344 }
339345
340346 /**
@@ -347,17 +353,11 @@ export default function makeModel(options: FeathersVuexOptions) {
347353
348354 if ( ! id ) {
349355 const error = new Error (
350- `Missing ${
351- idField
352- } property. You must create the data before you can update with this data`
356+ `Missing ${ idField } property. You must create the data before you can update with this data`
353357 )
354358 return Promise . reject ( error )
355359 }
356- return _dispatch . call ( this . constructor , 'update' , [
357- id ,
358- this ,
359- params
360- ] )
360+ return _dispatch . call ( this . constructor , 'update' , [ id , this , params ] )
361361 }
362362
363363 /**
@@ -373,7 +373,7 @@ export default function makeModel(options: FeathersVuexOptions) {
373373 if ( params && params . eager ) {
374374 _commit . call ( this . constructor , 'removeItem' , id )
375375 }
376- return _dispatch . call ( this . constructor , 'remove' , [ id , params ] )
376+ return _dispatch . call ( this . constructor , 'remove' , [ id , params ] )
377377 } else {
378378 _commit . call ( this . constructor , 'removeTemps' , [ this [ tempIdField ] ] )
379379 return Promise . resolve ( this )
0 commit comments