@getloom/svelte-gettable-stores

0.2.3 • Public • Published

@feltcoop/svelte-gettable-stores

⚠️ use runes instead!!

npm: @feltcoop/svelte-gettable-stores

‼ This library can cause tricky bugs and there may be good reasons the Svelte team supports get and not .get(). (some discussion on this issue) Please do not use this unless you know what you're doing 🤒 The only benefit is performance, which may not be relevant for your usage.

Adds a non-reactive .get() to Svelte stores (as well as @feltcoop/svelte-mutable-store). It copypastes the original implementations and makes these changes and then this derived followup.

See the tests for more. The derived implementation was mostly copied from svelte-store2. Discussion is welcome in issues and privately.

motivation

Svelte offers the standalone get function to non-reactively access store values, but it costs more than necessary in most cases. From the Svelte docs:

"This works by creating a subscription, reading the value, then unsubscribing. It's therefore not recommended in hot code paths." (svelte.dev/docs)

In many cases, this cost is either negligible or architecturally irrelevant. In other cases, like nested stores and collections processed in non-reactive contexts like event handlers, the cost can be undesirably high.

This library adds .get() to the original store implementations to access values without the cost of a subscription+unsubscription in all cases except derived stores with zero subscribers. In that case, it uses the get builtin.

license

MIT (copy of Svelte's license)

everything else: Unlicense (public domain)

Readme

Keywords

none

Package Sidebar

Install

npm i @getloom/svelte-gettable-stores

Weekly Downloads

20

Version

0.2.3

License

MIT

Unpacked Size

29.4 kB

Total Files

16

Last publish

Collaborators

  • greatbacon