Skip to content

Instantly share code, notes, and snippets.

@nsisodiya
Last active October 24, 2015 09:55
Show Gist options
  • Select an option

  • Save nsisodiya/ec4b69d76530f2e3ef9e to your computer and use it in GitHub Desktop.

Select an option

Save nsisodiya/ec4b69d76530f2e3ef9e to your computer and use it in GitHub Desktop.
TODO Reducer - Alternate Syntax
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