Last active
October 21, 2016 08:49
-
-
Save andrei-cacio/f0f7142cbdaafcb692c44e8fe989176d to your computer and use it in GitHub Desktop.
Redux reducers refactored using ES2015 enhanced object literals
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
import { combineReducers } from 'redux'; | |
import { LOGIN, LOGOUT } from './action-types'; | |
const initialState = {}; | |
const user = (state = initialState, action) => { | |
const actionTypeHandlerMap = { | |
[LOGIN]: ({ status, userInfo }) => ({ ...state, status, userInfo }), | |
[LOGOUT]: ({ status }) => ({ ...state, status, userInfo: {}}), | |
[undefined]: () => state | |
} | |
return actionTypeHandlerMap[action.type](action); | |
} | |
export default combineReducers({ user }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment