Skip to content

Instantly share code, notes, and snippets.

@darrenmothersele
Created December 20, 2018 15:12
Show Gist options
  • Save darrenmothersele/b72cdecb4a1e03241e5297cc4d2bcb1b to your computer and use it in GitHub Desktop.
Save darrenmothersele/b72cdecb4a1e03241e5297cc4d2bcb1b to your computer and use it in GitHub Desktop.
import { TodoActions } from './todo.actions';
import { Task } from './interfaces/task.interface';
import produce from 'immer';
export const initialState: Array<Task> = [];
export const producer = (draft, action) => TodoActions.match(action, {
NewTask: task => {
draft.push(task);
},
ToggleTask: ({ id }) => {
const task = draft.find(t => t.id === id);
task.done = !task.done;
},
ClearCompleted: () => draft.filter(task => !task.done),
default: () => {}
});
export const reducer = produce(producer, initialState);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment