Dont override cached key/value pairs if new value is undefined

fix-data-override
Chewbacca 2023-07-19 13:14:20 -04:00
rodzic 7944de8305
commit a5ce268de3
1 zmienionych plików z 7 dodań i 1 usunięć

Wyświetl plik

@ -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 });
};