ImutableJs

Data STrategy

todos.actions.ts
import { List } from 'immutable';
import { Store, HasStore, InjectStore } from "react-state-rxjs";
import { TodoModel } from "./todo.model";

@InjectStore('todos')
export class TodosStateActions extends HasStore<List<any>> {

    addTodo(item: TodoModel) {
        this.store.update(state => {
            state.push(Immutable.fromJS(item));
        })
    }

    deleteTodo(index: number) {
        this.store.update(state => {
            state.delete(index);
        }, false);
    }

    get todosAsync(): List<Map<any, any>> {
        return this.store.map((state) => {
            return state.toArray();
        }) as any;
    } // async way

    /// OR

    get todos() {
      return this.state.toArray();
    } // sync way
}

Last updated