@watchable/store-edit
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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...

/@watchable/store-edit/

    Package Sidebar

    Install

    npm i @watchable/store-edit

    Weekly Downloads

    1

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    10.7 kB

    Total Files

    14

    Last publish

    Collaborators

    • cefn