Skip to content

Instantly share code, notes, and snippets.

@cartant
Last active April 25, 2019 03:22
Show Gist options
  • Save cartant/08c1a53806ac63925f4cb0a01b6df678 to your computer and use it in GitHub Desktop.
Save cartant/08c1a53806ac63925f4cb0a01b6df678 to your computer and use it in GitHub Desktop.
import { createAction, createReducer, on, props } from "@ngrx/store";
const add = createAction("[Todos] Add", props<{ text: string }>());
const reset = createAction("[Todos] Reset");
type Todo = {
done: boolean;
text: string;
};
const initialState = {
todos: [] as Todo[]
};
const reducer = createReducer(
initialState,
on(add, (state, { text }) => ({
todos: [
...state.todos,
{
done: false,
text
}
]
})),
on(reset, () => initialState)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment