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.
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.
MIT (copy of Svelte's license)
everything else: Unlicense (public domain)