Last active
February 11, 2017 20:03
-
-
Save carlesba/30ee52d4762acb58defe65c76740c344 to your computer and use it in GitHub Desktop.
Create Reducer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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