Redux reducers can compose in a couple of different ways:
combineReducers
creates a new state tree with the composed reducers owning/controlling leaves (subtrees).
Or a straight merge, something like:
const reducer = (state, action) => ({
...reducerA(state, action),
...reducerB(state, action)
});
Or sequential ("traditional"?) composition:
const reducer = (state, action) =>
reducerB(reducerA(state, action), action);
Both of the merge styles are disaster-prone, as we could imagine...
Actions/Action-creators (ignoring middleware) compose as a straight union of the set of all actions.
A possible composition of Redux stores into a new store:
-
The composed store's
dispatch
sends all actions to all composed stores. -
getState
's value composes in the same way as reducers, above. -
subscribe
would act as if you passed the same subscription callback to each store individually.