1

Multiple store instances in a React Redux app, I know it's not recommended but I think in my case they are.

I am doing an elevator logic app for a building with 2 elevators. When an elevator is requested on any floor selected, is the one that could arrive at the floor the earliest time (after going through all other called floors in its cue). I was thinking of having a main store of the building, which checks availability according to the above logic, and then adds the call to the selected elevator's cue.

Each elevator will have its own store for managing the elevator cue, for going, arriving and moving to the next floor in the cue.

Is this a good example for React Reudx subapps / substores ?

oguz ismail
  • 1
  • 16
  • 47
  • 69
Shai Kimchi
  • 746
  • 1
  • 4
  • 22

1 Answers1

0

If you have exactly two elevators, you can have a store shape like

{
  elevator1: {},
  elevator2: {}
}

And then you can use the same reducer for each elevator. Even with n elevators you can create a state that takes the form of

{
  [elevatorId]: ElevatorState
}

So, to answer your question, no I don't think having multiple stores is necessary.

flq
  • 22,247
  • 8
  • 55
  • 77
  • That is how I implemented it, but then thought, that a million states can change inside the elevator that the building store doesn't have to know about. Let's say that upon arrival to every floor the music in the elevator should change, or the AC will toggle on/off, better yet, the state of people entering and leaving the elevator and the weight control check is the responsibility of the elevator itself. – Shai Kimchi Oct 04 '18 at 04:48