@lauf/store-edit
v2.0.0
Published
Intuitive editing of @lauf/store state, (using Immer drafts)
Downloads
59
Readme
Edit a store's immutable state
An idiot-proof mechanism to write @lauf/store state without breaking immutability. Guarantees safe Immutable edits without needing to learn Immutable update patterns
Read the API Reference or the reference usages below.
Usage
Making Edits
// given this example store
const counterState = createStore({ counter: 0 });
// editing a draft writes a new immutable state
edit(counterState, (draft) => (draft.counter += 1));
How it works
Your editor function is passed a draft object matching store state. Edit the
draft using any javascript syntax. Immer
then efficiently composes a new Immutable state to reflect your drafted changes,
leaving the old state intact. The new state is passed to store.write(...)
.
Import OR Require
import { edit } from "@lauf/store-edit"; // for esm
const { edit } = require("@lauf/store-edit"); // for commonjs
Getting Started
Install
npm install @lauf/store-edit
Demonstration Apps
Selected Example Counter Apps offer minimal demonstrations of @lauf/store-edit
. See the following...