4

I'm trying to update or rather insert new value into dictionary under ngrx Entity.

Here is simplified view of Entity:

interface Dictionary<T> { [key: number]: T }

export class Item {
  id: number;
  partsDescriptions: Dictionary<string[]>;
}

export interface ItemsState extends EntityState<Item> {
}

Here is app state:

export interface AppState {
  items: ItemsState
}

In reducer I'm trying to do following:

on(MyActions.partDescriptionsLoaded, (state, action) => {
    return {
      ...state,
      items: adapter.updateOne({
        id: action.id,
        changes: {
          ...state.items[action.id],
          partsDescriptions: {
            ...(state.items[action.id] && state.items[action.id].partsDescriptions),
            [action.partId]: action.partDescriptions
          }
        }
      }, state.items)
    }
  })

PartDescriptions dictionary is not extended, it's always replaced. Do you have any idea how to solve this issue?

rwasik
  • 296
  • 4
  • 17
  • All you have to do to make it working is to use entities property from EntityState iterface: ...(state.items.entities[action.id] && state.items.entities[action.id].partsDescriptions) – rwasik Dec 20 '21 at 12:00

0 Answers0