JSPM

svelte-bound-store

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 32
  • Score
    100M100P100Q68995F
  • License MIT

Monadic binding for Svelte stores

Package Exports

  • svelte-bound-store

Readme

svelte-bound-store

bound is like derived, but the function returns another store.

Usage

import { writable } from "svelte/store";
import { bound } from "svelte-bound-store";

const foo = writable("foo");
const bar = writable("bar");
const baz = writable("baz");
const state = writable({
  index: 0,
  items: [foo, bar, baz],
});

const current = bound(state, ({ index, items }) => items[index]);

current.subscribe(console.log); // "foo"

foo.set("foo2"); // "foo2"

// change the index
state.update((state) => ({ ...state, index: 1 })); // "bar"

foo.set("foo3"); // logs nothing because `current` is no longer bound to `foo`