I've got a Redux app with a fairly flat state tree. All sub reducers handle one separate part of the state, and they are tied together with
My problem is that in a few cases I need to access state part
A in the sub reducer for state part
B. The Redux FAQ has a section on this, with three suggestions:
- Reorganize the state tree.
- Don't use
- Use thunks to dispatch actions with the relevant parts of the state in them.
For me, #1 is not an option since my tree is already highly normalized. I feel that #2 would make my code unnececarily complex just to handle an edge case. So currently I am going with #3, but I don't really like it. To me, it makes more sense to keep the logic describing how the new state depends on the old state in the reducers, and not in the action creators.
This has led me to consider a fourth option, namely writing my own
combineReducersWithFullState that gives the sub reducers the following signature:
(localState, action, fullState) => newLocalState
Is this a bad idea? Am I institutionalizing an anti-pattern here?