Skip to content

Instantly share code, notes, and snippets.

@raineorshine
Last active February 5, 2017 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save raineorshine/635101019e979c8ecca25c087e7b3f0e to your computer and use it in GitHub Desktop.
Save raineorshine/635101019e979c8ecca25c087e7b3f0e to your computer and use it in GitHub Desktop.
React reducers keyed by action type
const reducers = {}
// these could be easily split up across different files
reducers.FETCH_RESULT = (state, result) => Object.assign({}, { myData: result.myData }, state }
reducers.ADD_ITEM = (state, item) => Object.assign({}, { items: state.items.concat(item) }, state }
reducers.REMOVE_ITEM = (state, item) => Object.assign({}, { items: ... }, state }
// the main reducer
reducer = (state, action) => {
return reducers[action.type](state, action.data)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment