Last active
April 25, 2019 03:22
-
-
Save cartant/08c1a53806ac63925f4cb0a01b6df678 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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