Skip to content

Instantly share code, notes, and snippets.

@bodhi
Created June 12, 2016 13:32
Show Gist options
  • Save bodhi/4b4330c75b637ed065dc5620e53a7fbd to your computer and use it in GitHub Desktop.
Save bodhi/4b4330c75b637ed065dc5620e53a7fbd to your computer and use it in GitHub Desktop.
Quick thoughts on composing parts of Redux

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment