Skip to content

Instantly share code, notes, and snippets.

@daveharmswebdev
Last active February 10, 2019 19:00
Show Gist options
  • Save daveharmswebdev/34b12bf890d9185592297860eb722d7f to your computer and use it in GitHub Desktop.
Save daveharmswebdev/34b12bf890d9185592297860eb722d7f to your computer and use it in GitHub Desktop.
Todo Reducer with todo interface
export function todoReducer(
state: ITodoState = initialTodoState,
action: TodoActions
): ITodoState {
switch (action.type) {
case TodoActionTypes.AddTodo: {
const todo = {
...action.payload.todo,
id: uuid()
};
return todoAdapter.addOne(todo, state);
}
case TodoActionTypes.DeleteTodo: {
return todoAdapter.removeOne(action.payload.id, state);
}
case TodoActionTypes.UpdateDescription: {
return todoAdapter.updateOne(action.payload, state);
}
case TodoActionTypes.ToggleComplete: {
return todoAdapter.updateOne(action.payload, state);
}
case TodoActionTypes.MarkAllAsComplete: {
return todoAdapter.updateMany(action.payload, state);
}
default:
return state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment