Skip to content

Instantly share code, notes, and snippets.

@ppsreejith
Created March 9, 2017 14:06
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 ppsreejith/c8139c5c9ed9067dba10374a30ca1bf4 to your computer and use it in GitHub Desktop.
Save ppsreejith/c8139c5c9ed9067dba10374a30ca1bf4 to your computer and use it in GitHub Desktop.
A template for object function based reducers.
import Immutable from 'immutable';
import _ from 'lodash';
const initialState = Immutable.Map({
data: 5
})
const reducers = {
FILTER_EDIT: (state, {data}) => state.merge({data}),
FILTER_INC: (state) => state.updateIn(['data'], val => val+1),
};
export default function reducer(state = initialState, action = {}) {
if (action.type in reducers)
return reducers[action.type](state, action.payload);
return state;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment