In an app with store support, any component can do this...
<input bind:value=$whatever>
...but this doesn't work:
<Widget bind:x=$y/>
It just sets $y on the parent component, rather than setting y on the store.
Thanks, @Rich-Harris . Unfortunately this doesn't seem to solve my original issue, that updating the inputs in the child components does not fire the store.onchange handler:
https://stackoverflow.com/questions/48177495/svelte-store-not-firing-onchange-when-nested-components-update (whoops, put the wrong link first, thanks @paulocoghi)
Updated to 1.54.2 and still reproducible here:
https://nonstop-hourglass.glitch.me/
Does store.onchange only watch for changes to top-level elements? Is that by design? If so it seems that the workaround you suggested on SO would always be necessary?
@nvioli , you posted a different SO question. I believe that the question is:
Anyway, the issue is well reported. :)
Fixed (again! hopefully for good) in 1.55 — thanks
This doesn't seems to be fixed yet, i have 3 files:
store.js
export const windowWidth = writable(1000);
2.svelte
<svelte:window bind:innerWidth={$windowWidth} />
<p>{$windowWidth}</p>
3.svelte
<p>{$windowWidth}</p>
But when i change the window size the value in 3.svelte doesn't update at all and in 2.svelte it does.
I'm working in a sapper project that has svelte version: "svelte": "^3.0.0",
A temperately solution seems to be this:
2.svelte
<svelte:window on:resize={() => ($windowWidth = window.innerWidth)} />
In the script tag of 2.svelte
onMount(() => ($windowWidth = window.innerWidth));
Found this as an unclosed item on the project page, and just leaving a note to self — it looks like the issue in the last comment was fixed at some point: https://svelte.dev/repl/4c0e43f14ddb4232addc784d35e03baf?version=3.22.2
Most helpful comment
Fixed (again! hopefully for good) in 1.55 — thanks