Skip to content

Instantly share code, notes, and snippets.

@andrei-cacio
Last active October 21, 2016 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrei-cacio/f0f7142cbdaafcb692c44e8fe989176d to your computer and use it in GitHub Desktop.
Save andrei-cacio/f0f7142cbdaafcb692c44e8fe989176d to your computer and use it in GitHub Desktop.
Redux reducers refactored using ES2015 enhanced object literals
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