-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Closed
Description
I am thinking of using store.replaceReducer
to swap reducers so that an action type can target a particular reducer. This pattern would help with reusing action types on different pages of an application.
For example:
- on /pageA we have reducer A and the following state tree:
{ A: { ... } }
MY_ACTION
is dispatched and handled by A and produces a new state A.- User goes to /pageB, we replaces reducer A with reducer B and end up with
{ A: { ... }, B: { ... } }
MY_ACTION
is dispatched that B handles and updates state B but not state A.
The problem with the above approach is that Redux does not currently provide any safety while replacing a reducer. For example the following scenario is a problem:
fetch().then(dispatch(action));
store.replaceReducer(B);
// dispatch happens by might not have been intended for reducer B - a race condition!
Is there something I'm missing here? Or would you be willing to consider a PR to make this possible?
Metadata
Metadata
Assignees
Labels
No labels