npm.io
0.3.0 • Published 4 years ago

remos-immer

Licence
ISC
Version
0.3.0
Deps
0
Size
6 kB
Vulns
0
Weekly
0

remos-immer

An Immer wrapper for Remos

Installation

NPM

npm i remos-immer --save

YARN

yarn add remos-immer

Usages

With remos-immer

import { create, inject } from "remos";
import { withImmer } from "remos-immer";

inject(withImmer());

const todoModel = create({
  todos: [],
  add(todo) {
    this.todos.push(todo);
  },
  remove(id) {
    const index = this.todos.findIndex((x) => x.id === id);
    this.todos.splice(index, 1);
  },
});

Without remos-immer

import { create, configure } from "remos";

const todoModel = create({
  todos: [],
  add(todo) {
    this.todos = [...this.todos, todo];
  },
  remove(id) {
    const index = this.todos.findIndex((x) => x.id === id);
    this.todos = [
      ...this.todos.slice(0, index),
      ...this.todos.slice(index + 1),
    ];
  },
});

Keywords