Using SvelteMap with runes and stores
#14376
Replies: 2 comments 4 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.
-
Yeah, having better docs would be really nice. I've been trying to figure out how to use SvelteMap correctly. I wrote this code to figure out the behavior. It seems like, probably for most people they should be doing: Using If you only use Then this doesn't trigger updates. However, this does. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
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
Fooinstances 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 Mapwithnew 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 theSvelteMapinside 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