NB: This is a question, very similar to Redux; accessing other parts... but it has nothing to do with Router :( thus cannot be solved same way
When I reduce one part of the state, I "feel" like I need to access other parts as well. I admit that I just might "misfeel" the core principals of the Redux, or have flaws in my app's architecture.
My current solution would be to modify github:combineReducers.js's code:
var finalState = mapValues(finalReducers, (reducer, key) => {
var previousStateForKey = state[key]
var nextStateForKey = reducer(previousStateForKey, action)
...
}
from
var nextStateForKey = reducer(previousStateForKey, action)
to
var nextStateForKey = reducer(previousStateForKey, action, state)
which would allow me to do what I need:
function reducer(state, action, root) {
if (root.otherPart.get("isSomething")) {
return state.set("anotherThing", true);
}
return state;
}
Question is if I am on the right way to do it, or is it something that should be solved using different architectural approaches, without having a need to access one part of state from other parts?
** UPDATE 5h Dec, 2018 **
Due to relatively high interest to this question (15 up-votes atm), I am adding my own answer below, hope it helps to those who is looking for that answer.
combineReducers
because your reducers aren't actually decoupled." You can still separate logic out by extracting functions that take pieces of the whole state. That said, your custom solution seems pretty decent to me, especially ifroot
is really immutable.combineReducers
result in a gigantic, monolithic reducer file?combineReducers
basically works, but without the flexibility).