I have a reducer tree that looks like this:
module.exports = combineReducers({
routing: routeReducer,
app: combineReducers({
setup: combineReducers({
sets,
boosters
}),
servers: combineReducers({
servers
})
})
});
Now the setup
key holds a form that needs to be reset once we've submitted it. However I have no way to access the entire setup
tree because using combineReducers means the reducers only manipulate the data at the leaf nodes of the tree (sets
and boosters
in this case).
My first impulse is to make a function that reduces the entire setup tree like this:
function setup(state, action){
//If there's an action that affects this whole tree, handle it
switch(action.type){
case "FORM_SUBMIT": //DO STUFF
break;
}
//Otherwise just let the reducers care about their own data
return combineReducers({
sets,
boosters
})(state);
}
But that doesn't work, and also messes up the nice tree structure of my first code example.
Is there a better solution for this with redux?