Created
August 21, 2016 22:36
-
-
Save jdmorlan/25f72991146805311449a21e4e5acd09 to your computer and use it in GitHub Desktop.
Remove the switch statement from Redux reducers!
This file contains hidden or 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 updateLocation = (state, action) => { | |
return Object.assign({}, state, ...) | |
} | |
const actionHandlers = { | |
'UPDATE_LOCATION': updateLocation | |
} | |
const reducer = (state = initialState, action) => { | |
const handler = actionHandlers[action.type] | |
if (!handler) return state | |
return handler(state, action) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment