Skip to content

Instantly share code, notes, and snippets.

@lancetw
Last active January 11, 2016 10:10
Show Gist options
  • Save lancetw/2434b7ddf6fd4dc6b634 to your computer and use it in GitHub Desktop.
Save lancetw/2434b7ddf6fd4dc6b634 to your computer and use it in GitHub Desktop.
// borrow from react-redux-starter-kit
// https://github.com/davezuko/react-redux-starter-kit
export function createConstants (...constants) {
return constants.reduce((acc, constant) => {
return Object.assign({}, acc, { [constant]: constant })
}, {})
}
export function createReducer (initialState, reducerMap) {
return (state = initialState, action) => {
const reducer = reducerMap[action.type]
return reducer ? Object.assign({}, state, reducer(state, action)) : state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment