angularangular-state-managmement

Updating selected entities updates all entities in ngneat/elf repository


I'm facing an issue where I try to update an entity in the store but every entity gets updated instead. Now I have defined the entities and their ids as such:

const { state, config } = createState(
  withEntities<IDossier, StateGlobConf.ENTITY_ID_KEY>({ idKey: StateGlobConf.ENTITY_ID_KEY }),

and later when I wish to update and entity I proceed to do the following (as per Documentation):

updateDossier(id: IDossier[StateGlobConf.ENTITY_ID_KEY], dossier: Partial<IDossier>): void {
  store.update(updateEntities(id, dossier));
}

As far as I understand the only entity that should be updated is the one with the passed id, or if I am doing something wrong, I don't understand what it is.


Solution

  • The shown code was good, but the problem was the type I was sending. So my model was structured as such:

    {
        StateGlobConf.ENTITY_ID_KEY: number
    }
    

    meaning the key was named StateGlobConf.ENTITY_ID_KEY but its value was of different type (type number).

    The fix looks like:

    updateDossier(id: number, dossier: Partial<IDossier>): void {
      store.update(updateEntities(id, dossier));
    }