@watchable/store-edit
v1.0.2
Published
Intuitive editing of @watchable/store state, (using Immer drafts)
Downloads
15
Maintainers
Readme
Edit a store's immutable state
An idiot-proof mechanism to write @watchable/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, or browse the source on Github.
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 "@watchable/store-edit"; // for esm
const { edit } = require("@watchable/store-edit"); // for commonjs
Getting Started
Install
npm install @watchable/store-edit
Demonstration Apps
Selected
Example Counter Apps offer
minimal demonstrations of @watchable/store-edit
. See the following...