An Immer wrapper for Remos
NPM
npm i remos-immer --save
YARN
yarn add remos-immer
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),
];
},
});