Skip to content

Instantly share code, notes, and snippets.

@cartant
Last active April 29, 2019 02:50
Show Gist options
  • Save cartant/3eb44d88dace3a50f1ca077b152ee9c4 to your computer and use it in GitHub Desktop.
Save cartant/3eb44d88dace3a50f1ca077b152ee9c4 to your computer and use it in GitHub Desktop.
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