Using SvelteMap
with runes and stores
#14376
Replies: 1 comment 2 replies
-
Depending on what the keys are and possibly other factors like performance, this could potentially just be a plain object wrapped in Wrapping the I would not introduce new stores, they restrict you to an inferior syntax compared to runes. If you need to interact with existing stores, use |
Beta Was this translation helpful? Give feedback.
-
Hi,
I have a question about how
SvelteMap
(and generally all convenience classes fromsvelte/reactivity
) should be used to offer reactive values across files.Say I have a global storage of
Foo
instances with their IDs, which I would like to implement with aMap
-like structure. So say I have a filesrc/lib/fooStorage.svelte.ts
:Now my question is what is the recommended way of making this reactive? I understand from the docs that I should use a
SvelteMap
, but is it enough on its own? (just replacingnew Map
withnew SvelteMap
) Or should I put it inside a state? (cosnt fooStorage = $state(new SvelteMap(...))
)? If I am using stores (for example because the values in the map depend on another store like a query from@tanstack/svetle-query
), should I put theSvelteMap
inside the store? Or are those two incompatible?If possible, I'd like to improve the docs for
svelte/reactivity
(willing to make a PR) to clearly state all these.Beta Was this translation helpful? Give feedback.
All reactions