remos-immer
v0.3.0
Published
An Immer wrapper for Remos
Downloads
26
Maintainers
Readme
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),
];
},
});