kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Dont override cached key/value pairs if new value is undefined
rodzic
7944de8305
commit
a5ce268de3
|
@ -3,7 +3,13 @@ import type { Entity, EntityStore, EntityList, EntityCache, EntityListState, Imp
|
|||
/** Insert the entities into the store. */
|
||||
const updateStore = (store: EntityStore, entities: Entity[]): EntityStore => {
|
||||
return entities.reduce<EntityStore>((store, entity) => {
|
||||
store[entity.id] = entity;
|
||||
const cachedEntity = store[entity.id];
|
||||
|
||||
store[entity.id] = {
|
||||
// Don't allow "undefined" values to override previously set values
|
||||
...(cachedEntity ? JSON.parse(JSON.stringify(cachedEntity)) : undefined),
|
||||
...JSON.parse(JSON.stringify(entity)),
|
||||
};
|
||||
return store;
|
||||
}, { ...store });
|
||||
};
|
||||
|
|
Ładowanie…
Reference in New Issue