@@ -126,10 +126,6 @@ export default class ApiStore<S> implements StoreOptions<S> {
126126 ) => {
127127 const state = myState [ model . plural ] ;
128128 forEach ( state . actionQueue , ( actionList , action ) => {
129- if ( action === "patch" ) {
130- forEach ( actionList , ( item , id ) => this . revertOriginItem ( state , id ) ) ;
131- }
132-
133129 state . actionQueue [ action ] = isArray ( actionList ) ? [ ] : { } ;
134130 } ) ;
135131 } ;
@@ -174,7 +170,9 @@ export default class ApiStore<S> implements StoreOptions<S> {
174170 } else {
175171 this . saveOriginItem ( state , data ) ;
176172 forEach ( model . references , ( modelName , prop ) => {
177- this . saveOrigins ( store , this . models [ modelName ] , data [ prop ] ) ;
173+ if ( data [ prop ] ) {
174+ this . saveOrigins ( store , this . models [ modelName ] , data [ prop ] ) ;
175+ }
178176 } ) ;
179177 }
180178 } catch ( e ) {
@@ -214,31 +212,34 @@ export default class ApiStore<S> implements StoreOptions<S> {
214212 entity : IndexedObject
215213 // eslint-disable-next-line @typescript-eslint/no-explicit-any
216214 ) : IndexedObject {
217- // Patch references
218- if ( model . references ) {
219- forEach ( model . references , ( modelName , prop ) => {
220- entity [ prop ] = this . patchReference ( store , entity , modelName , prop ) ;
221- } ) ;
222- }
215+ if ( entity && entity . id ) {
216+ // Patch references
217+ if ( model . references ) {
218+ forEach ( model . references , ( modelName , prop ) => {
219+ entity [ prop ] = this . patchReference ( store , entity , modelName , prop ) ;
220+ } ) ;
221+ }
223222
224- const state = store [ model . plural ] ;
223+ const state = store [ model . plural ] ;
225224
226- if ( has ( state . items , entity . id ) ) {
227- const storeEntity = state . items [ entity . id ] ;
228- forEach ( entity , ( value , name : string ) => {
229- if ( ! isFunction ( value ) && ! has ( model . references , name ) ) {
230- if ( has ( entity , name ) && ! isEqual ( value , get ( storeEntity , name ) ) ) {
231- Vue . set ( storeEntity , name , value ) ;
225+ if ( has ( state . items , entity . id ) ) {
226+ const storeEntity = state . items [ entity . id ] ;
227+ forEach ( entity , ( value , name : string ) => {
228+ if ( ! isFunction ( value ) && ! has ( model . references , name ) ) {
229+ if ( has ( entity , name ) && ! isEqual ( value , get ( storeEntity , name ) ) ) {
230+ Vue . set ( storeEntity , name , value ) ;
231+ }
232232 }
233- }
234- } ) ;
233+ } ) ;
235234
236- return state . items [ entity . id ] ;
237- } else {
238- state . items = { ...state . items , ...this . getIndexedMap ( entity ) } ;
235+ return state . items [ entity . id ] ;
236+ } else {
237+ state . items = { ...state . items , ...this . getIndexedMap ( entity ) } ;
239238
240- return entity ;
239+ return entity ;
240+ }
241241 }
242+ return entity ;
242243 }
243244
244245 private patchReference (
0 commit comments