Skip to content

Instantly share code, notes, and snippets.

@gdborton
Last active October 25, 2015 16:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdborton/2eccc361aa9cfd0b407c to your computer and use it in GitHub Desktop.
Save gdborton/2eccc361aa9cfd0b407c to your computer and use it in GitHub Desktop.
// Straight from documentation.
const reducer = combineReducers({
a: doSomethingWithA,
b: processB,
c: c
});
// This is functionally equivalent.
function reducer(state, action) {
return {
a: doSomethingWithA(state.a, action),
b: processB(state.b, action),
c: c(state.c, action)
};
}
// Simple change to pass the entire state to each reducer.
// You have to be extra careful to keep state immutable here.
function reducer(state, action) {
return {
a: doSomethingWithA(state.a, action, state),
b: processB(state.b, action, state),
c: c(state.c, action, state)
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment