@@ -174,20 +174,25 @@ export function objectCacheReducer(state = initialState, action: ObjectCacheActi
174174 * the new state, with the object added, or overwritten.
175175 */
176176function addToObjectCache ( state : ObjectCacheState , action : AddToObjectCacheAction ) : ObjectCacheState {
177- const existing = state [ action . payload . objectToCache . _links . self . href ] || { } as any ;
177+ const cacheLink = hasValue ( action . payload . objectToCache ?. _links ?. self ) ? action . payload . objectToCache . _links . self . href : action . payload . alternativeLink ;
178+ const existing = state [ cacheLink ] || { } as any ;
178179 const newAltLinks = hasValue ( action . payload . alternativeLink ) ? [ action . payload . alternativeLink ] : [ ] ;
179- return Object . assign ( { } , state , {
180- [ action . payload . objectToCache . _links . self . href ] : {
181- data : action . payload . objectToCache ,
182- timeCompleted : action . payload . timeCompleted ,
183- msToLive : action . payload . msToLive ,
184- requestUUIDs : [ action . payload . requestUUID , ...( existing . requestUUIDs || [ ] ) ] ,
185- dependentRequestUUIDs : existing . dependentRequestUUIDs || [ ] ,
186- isDirty : isNotEmpty ( existing . patches ) ,
187- patches : existing . patches || [ ] ,
188- alternativeLinks : [ ...( existing . alternativeLinks || [ ] ) , ...newAltLinks ] ,
189- } as ObjectCacheEntry ,
190- } ) ;
180+ if ( hasValue ( cacheLink ) ) {
181+ return Object . assign ( { } , state , {
182+ [ cacheLink ] : {
183+ data : action . payload . objectToCache ,
184+ timeCompleted : action . payload . timeCompleted ,
185+ msToLive : action . payload . msToLive ,
186+ requestUUIDs : [ action . payload . requestUUID , ...( existing . requestUUIDs || [ ] ) ] ,
187+ dependentRequestUUIDs : existing . dependentRequestUUIDs || [ ] ,
188+ isDirty : isNotEmpty ( existing . patches ) ,
189+ patches : existing . patches || [ ] ,
190+ alternativeLinks : [ ...( existing . alternativeLinks || [ ] ) , ...newAltLinks ] ,
191+ } as ObjectCacheEntry ,
192+ } ) ;
193+ } else {
194+ return state ;
195+ }
191196}
192197
193198/**
0 commit comments