@@ -166,20 +166,25 @@ export function objectCacheReducer(state = initialState, action: ObjectCacheActi
166166 * the new state, with the object added, or overwritten.
167167 */
168168function addToObjectCache ( state : ObjectCacheState , action : AddToObjectCacheAction ) : ObjectCacheState {
169- const existing = state [ action . payload . objectToCache . _links . self . href ] || { } as any ;
169+ const cacheLink = hasValue ( action . payload . objectToCache ?. _links ?. self ) ? action . payload . objectToCache . _links . self . href : action . payload . alternativeLink ;
170+ const existing = state [ cacheLink ] || { } as any ;
170171 const newAltLinks = hasValue ( action . payload . alternativeLink ) ? [ action . payload . alternativeLink ] : [ ] ;
171- return Object . assign ( { } , state , {
172- [ action . payload . objectToCache . _links . self . href ] : {
173- data : action . payload . objectToCache ,
174- timeCompleted : action . payload . timeCompleted ,
175- msToLive : action . payload . msToLive ,
176- requestUUIDs : [ action . payload . requestUUID , ...( existing . requestUUIDs || [ ] ) ] ,
177- dependentRequestUUIDs : existing . dependentRequestUUIDs || [ ] ,
178- isDirty : isNotEmpty ( existing . patches ) ,
179- patches : existing . patches || [ ] ,
180- alternativeLinks : [ ...( existing . alternativeLinks || [ ] ) , ...newAltLinks ]
181- } as ObjectCacheEntry
182- } ) ;
172+ if ( hasValue ( cacheLink ) ) {
173+ return Object . assign ( { } , state , {
174+ [ cacheLink ] : {
175+ data : action . payload . objectToCache ,
176+ timeCompleted : action . payload . timeCompleted ,
177+ msToLive : action . payload . msToLive ,
178+ requestUUIDs : [ action . payload . requestUUID , ...( existing . requestUUIDs || [ ] ) ] ,
179+ dependentRequestUUIDs : existing . dependentRequestUUIDs || [ ] ,
180+ isDirty : isNotEmpty ( existing . patches ) ,
181+ patches : existing . patches || [ ] ,
182+ alternativeLinks : [ ...( existing . alternativeLinks || [ ] ) , ...newAltLinks ]
183+ } as ObjectCacheEntry
184+ } ) ;
185+ } else {
186+ return state ;
187+ }
183188}
184189
185190/**
0 commit comments