combineReducers is a good template because it tends to provide the idea that gears should be tied to non-overlapping subsets of the store, separated from the structure of the store itself. Express the view that you should reduce leaves, not branches, and handle branch reduction.
However, there may be good reasons to use an alternative template. As I mentioned in the question higher order function . It may be hard to understand, but here's how I approach it:
- We know that
setupReducer takes a reducer as an argument because we pass the result of combineReducers . - We know that the reducer signature returned by
combineReducers is (state, action) => state . - We also know that
setupReducer must return a reducer, which, again, is a signature function (state, action) => state .
In other words, it takes the gearbox and returns the gearbox: ((state, action) => state) => ((state, action) => state) . So it might look like this:
function setupReducer(subReducer) { return (state, action) => {
I saved your logical stream above, but, as a warning, you can unconditionally call subReducer and then change its output. Otherwise, you will need to make sure that your branches, where it is not called, always create an object of the same shape that seems to be a potential sticky adhesion point.
source share