0

I have a one EntityStates of the same model assigned to a few properties in the single state. Can I manipulate all of them using a single adapter? They have the same initial state but will contain values with various status.

interface myState {
   entity1: EntityState,
   entity2: EntityState
   entity3: EntityState
}

export interface EntityState extends EntityState<MyModel> {}

export const adapter: EntityAdapter<MyModel> = createEntityAdapter<MyModel>();

export const myInitialState: EntityState = adapter.getInitialState({
  loaded: false
});

export const initialState = {
   entity1: myInitialState,
   entity2: myInitialState
   entity3: myInitialState 
}

and then I would like to is with a single entity instance like that

state{
...state
entity1: adapter.addMany(payload {
  ...state.entity1
  loaded: true
 )
}
Stefan
  • 1,431
  • 2
  • 17
  • 33
  • 1
    Yes, you can do it, since adapter is just a function, that returns new state. But I am not sure what exactly you want to achieve. Usually the same entities are stored and managed by the same reducer. – Borys Kupar Feb 14 '19 at 16:34
  • They have the same model but hold entities with different status, an I prefer to hold them in separate property. – Stefan Feb 14 '19 at 16:56

1 Answers1

1

Yes, this will work. The adapter's function is pure, it takes some state and a "payload" and will returns a new updated state.

The snippet you posted is valid.

timdeschryver
  • 14,415
  • 1
  • 19
  • 32