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`

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    13
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.2
    13
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i svelte-bound-store

Weekly Downloads

13

Version

1.0.2

License

MIT

Unpacked Size

4.92 kB

Total Files

6

Last publish

Collaborators

  • nasso