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.
// given this example store
const counterState = createStore({ counter: 0 });
// editing a draft writes a new immutable state
edit(counterState, (draft) => (draft.counter += 1));
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 { edit } from "@watchable/store-edit"; // for esm
const { edit } = require("@watchable/store-edit"); // for commonjs
npm install @watchable/store-edit
Selected
Example Counter Apps offer
minimal demonstrations of @watchable/store-edit
. See the following...