Skip to content

Instantly share code, notes, and snippets.

@ericelliott
Created August 28, 2016 00:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericelliott/54fb771a2dedc60ff58a3e104ccc340e to your computer and use it in GitHub Desktop.
Save ericelliott/54fb771a2dedc60ff58a3e104ccc340e to your computer and use it in GitHub Desktop.
Reducer, sans boilerplate
const chatReducer = (state = defaultState, action = {}) => {
const { type, payload } = action;
switch (type) {
case ADD_CHAT:
return Object.assign({}, state, {
chatLog: state.chatLog.concat(payload)
});
// Catch all simple changes
case CHANGE_STATUS:
case CHANGE_USERNAME:
return Object.assign({}, state, payload);
default: return state;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment