Skip to content

Instantly share code, notes, and snippets.

@codemilli
Created February 12, 2016 14:06
Show Gist options
  • Select an option

  • Save codemilli/fe5cafc90e686b660f78 to your computer and use it in GitHub Desktop.

Select an option

Save codemilli/fe5cafc90e686b660f78 to your computer and use it in GitHub Desktop.
2 type of reducer.
function visibilityFilter(state = 'SHOW_ALL', action) {
switch (action.type) {
case 'SET_VISIBILITY_FILTER':
return action.filter;
default:
return state;
}
}
function todos(state = [], action) {
switch (action.type) {
case 'ADD_TODO':
return [
...state,
{
text: action.text,
completed: false
}
];
case 'COMPLETE_TODO':
return [
...state.slice(0, action.index),
Object.assign({}, state[action.index], {
completed: true
}),
...state.slice(action.index + 1)
];
default:
return state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment