ImmutaleJs
Data Strategy
todos.actions.ts
import { List, fromJS } from 'immutable';
import { Store, HasStore, InjectStore } from "ng-state";
import { TodoModel } from "./todo.model";
@InjectStore('todos')
export class TodosStateActions extends HasStore<List<any>> {
addTodo(item: TodoModel) {
this.store.update(state => {
state.push(fromJS(item));
})
}
deleteTodo(index: number) {
this.store.update(state => {
state.delete(index);
}, false);
}
get todos() {
return this.store.map((state) => {
return state.toArray();
});
} // async way
/// OR
get todos() {
return this.state.toArray();
} // non async way
}
Last updated