Skip to content

Instantly share code, notes, and snippets.

@carlesba
Last active February 11, 2017 20:03
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 carlesba/30ee52d4762acb58defe65c76740c344 to your computer and use it in GitHub Desktop.
Save carlesba/30ee52d4762acb58defe65c76740c344 to your computer and use it in GitHub Desktop.
Create Reducer
const createReducer = (initialState, actionMap) => (state = initialState, action) => {
const {signals} = action
if (signals) {
const signal = signals.find(
(stepAction) => actionMap[stepAction.type]
)
if (signal) {
const reducer = actionMap[signal.type]
return reducer(state, signal)
} else {
return state
}
} else {
const reducer = actionMap[action.type]
if (reducer) return reducer(state, action)
return state
}
}
export default createReducer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment