Immer

Data Strategy

Signal actions

import { Store, HasSignalStore, InjectStore } from "ng-state";
import { TodoModel } from "./todo.model";

@InjectStore('todos')
export class TodosStateActions extends HasSignalStore<List<any>> {
    addTodo(item: TodoModel) {
        this.store.update(state => {
            state.push(item);
        })
    }

    deleteTodo(index: number) {
        this.store.update(state => {
             if (index > -1) {
                state.splice(index, 1);
            }
        });
    }

    get todos() {
      return this.state();
    }
}

State actions

Last updated

Was this helpful?