0.0.18 • Published 1 year ago

@crikey/stores-immer v0.0.18

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@crikey/stores-immer

Provide svelte compatible implementations of readable, writable, derived and get using immutible values via immer.

Strict inequality triggering semantics provide a store version of the functionality seen with <svelte:options immutable={true} /> in the svelte compiler.

Using immer, @crikey/stores-immer is able to provide copy-on-write semantics during updates.

See @crikey/stores-immer for full documentation.

codecov

API

Store creation functions:

  • constant - Create a Readable store with a fixed value
  • readable - Create a Readable store
  • writable - Create a Writable immer store
  • derive - Create a Readable store derived from the resolved values of other stores

Utility functions:

  • get - Retrieve the value of a store

Installation

# pnpm
$ pnpm add @crikey/stores-immer

# npm
$ npm add @crikey/stores-immer

# yarn
$ yarn add @crikey/stores-immer

Usage

Standard usage should be a drop in replacement for svelte/store. The key difference being that mutating a store value will use immer to perform copy-on-write semantics during an Writable.update | update.

Example

const initial = [1,2,3];
const store = writable([1,2,3]);
store.subscribe(value => console.log(value));
// > [ 1, 2, 3 ]

store.update(value => {
    value.push(4);
    return value;
})
// > [ 1, 2, 3, 4 ]

console.log(get(store) !== initial);
// > true
0.0.18

1 year ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.14

3 years ago

0.0.15

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.2

3 years ago