Skip to content

Instantly share code, notes, and snippets.

@hugooliveirad
Created August 12, 2015 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugooliveirad/ac8a567d74cadbcf353a to your computer and use it in GitHub Desktop.
Save hugooliveirad/ac8a567d74cadbcf353a to your computer and use it in GitHub Desktop.
function createReducer(handlers, initialState) {
return function reducer(state = initialState, action) {
return handlers[action.type] ?
handlers[action.type](state, action)
: state
}
}
const math = createReducer({
INCREMENT: (state) => state + 1,
DECREMENT: (state) => state - 1
}, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment