Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component bindings can't access store #1100

Closed
Rich-Harris opened this issue Jan 12, 2018 · 6 comments · Fixed by #1153
Closed

Component bindings can't access store #1100

Rich-Harris opened this issue Jan 12, 2018 · 6 comments · Fixed by #1153
Labels

Comments

@Rich-Harris
Copy link
Member

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.

Rich-Harris added a commit that referenced this issue Feb 4, 2018
Rich-Harris added a commit that referenced this issue Feb 9, 2018
@nvioli
Copy link

nvioli commented Feb 10, 2018

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?

@paulocoghi
Copy link
Contributor

@nvioli , you posted a different SO question. I believe that the question is:

https://stackoverflow.com/questions/48177495/svelte-store-not-firing-onchange-when-nested-components-update

@paulocoghi
Copy link
Contributor

Anyway, the issue is well reported. :)

Rich-Harris added a commit that referenced this issue Feb 11, 2018
@Rich-Harris
Copy link
Member Author

Fixed (again! hopefully for good) in 1.55 — thanks

@mjarkk
Copy link

mjarkk commented Nov 11, 2019

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));

@Rich-Harris
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants