How does one use Svelte store with tree-like nested object? From this answer:
Note: bindings only works when it's the same variable. That is, you can't put the bound variable in an intermediate variable, and have Svelte keep tracking this binding.
This, and my own testing, seems to imply that one cannot reactively update the nested store (update the store and have this update the state) from a script external to a Svelte component. As far as I can see, the only way to do it is to manually call store.update()
in the script after making changes to the store. Is this correct?
I am looking to refactor my code: my main component's code is getting too unwieldy and I would like to introduce more components, and possibly keep state-updating functions in .js
files out of components for reusability.
Some questions on performance:
- Would doing manual updates be less performant than what Svelte does automatically?
- My app needs to handle a pretty big nested store, with hundreds of branches. In the answer linked above, it is proposed to create a nested store, with branches wrapped in their own stores. Would having hundreds of (nested) stores significantly increase the memory footprint of the app compared to just using a single store?