-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Reactive assignment doesn't work when dependent variable is hidden in function #2956
Comments
This is intentional actually, but perhaps it should be documented. The functions themselves could also be reassigned at runtime, which would break any dependence that we could figure out at compile time. And, although it's not generally recommended, it's also occasionally convenient to be able to 'hide' dependencies from the compiler. |
But also, if you do want to use separate functions and have your dependencies still counted, you can make all of the relevant dependencies be arguments to those functions, so the compiler can see them in the reactive block. |
That's actuually what I'm doing now and it works for me. Thanks for the clarification! |
If I understand it right, in JS there are four immutable data types: Where it behaves differently than I'd expect is that @Conduitry says you can pass the variables as arguments, and |
@BennyHinrichs I think you have a misunderstanding about how the compiler interprets reactive assignments. The compiler looks for the dependencies of a reactive statement by determining which reactive variables are read. In the "unsupported" example, even though |
@Conduitry I'd be happy to take on this issue, if no one else has up to this point! |
This is documented now: https://svelte.dev/docs#3_$_marks_a_statement_as_reactive |
Broken or unsupported
Working
For more enhanced or reusable calculations it would be nice to be able to wrap the reactive assignements inside functions. I didn't find any information about this limitation in the tutorial or the documentation but maybe I missed it.
The text was updated successfully, but these errors were encountered: