Last active
April 29, 2019 02:50
-
-
Save cartant/3eb44d88dace3a50f1ca077b152ee9c4 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, props } from "@ngrx/store"; | |
import { on } from "ts-action-immer"; | |
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 }) => { | |
state.todos.push({ | |
done: false, | |
text | |
}); | |
}), | |
on(reset, () => initialState) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment