Created
March 9, 2017 14:06
-
-
Save ppsreejith/c8139c5c9ed9067dba10374a30ca1bf4 to your computer and use it in GitHub Desktop.
A template for object function based reducers.
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 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