Last active
October 24, 2015 09:55
-
-
Save nsisodiya/ec4b69d76530f2e3ef9e to your computer and use it in GitHub Desktop.
TODO Reducer - Alternate Syntax
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
| var methods = { | |
| ADD_TODO(state, action){ | |
| return [...state, { | |
| text: action.text, | |
| completed: false | |
| }]; | |
| }, | |
| COMPLETE_TODO(state, action){ | |
| return [ | |
| ...state.slice(0, action.index), | |
| Object.assign({}, state[action.index], { | |
| completed: true | |
| }), | |
| ...state.slice(action.index + 1) | |
| ]; | |
| } | |
| } | |
| function todos(state = [], action) { | |
| var fun = methods[action.type]; | |
| if(typeof fun !== 'function'){ | |
| return state; | |
| }else{ | |
| return fun(state, action); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment