Created
January 5, 2016 12:43
-
-
Save kitze/7e65eede3208e12ba021 to your computer and use it in GitHub Desktop.
redux action without switch
This file contains hidden or 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 * as types from '../actions/actionTypes'; | |
const initialState = { | |
count: 0 | |
}; | |
export default counter = (state = initialState, action = {}) => { | |
return { | |
[types.INCREMENT]: { | |
...state, | |
count: state.count + 1 | |
}, | |
[types.DECREMENT]: { | |
...state, | |
count: state.count - 1 | |
} | |
}[action.type] || state; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment