svelte-bound-store
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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`

Package Sidebar

Install

npm i svelte-bound-store

Weekly Downloads

10

Version

1.0.2

License

MIT

Unpacked Size

4.92 kB

Total Files

6

Last publish

Collaborators

  • nasso