-
-
Save grabbou/16484dfb1aa9f787bb2d0b8f7dd08d29 to your computer and use it in GitHub Desktop.
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
// Wrap every object before passing to createReducer | |
export default function createReducer(initialState: ?{}, handlers: {}) { | |
return function reducer(state: ?{} = initialState, action: {type: string, payload: Object}) { | |
return typeof handlers[action.type] === 'function' | |
? handlers[action.type](state, action) | |
: state; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment