Last active
February 5, 2017 16:32
-
-
Save raineorshine/635101019e979c8ecca25c087e7b3f0e to your computer and use it in GitHub Desktop.
React reducers keyed by action type
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 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