Skip to content

Instantly share code, notes, and snippets.

@grabbou
Created November 7, 2016 14:49
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save grabbou/16484dfb1aa9f787bb2d0b8f7dd08d29 to your computer and use it in GitHub Desktop.
Save grabbou/16484dfb1aa9f787bb2d0b8f7dd08d29 to your computer and use it in GitHub Desktop.
// 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