Closed catinrage closed 1 month ago
It's different - untrack
does prevent any reads from counting towards dependencies, not writes. Giving this the documentation label so we can make it a more clear in the docs.
It's different -
untrack
does prevent any reads from counting towards dependencies, not writes. Giving this the documentation label so we can make it a more clear in the docs.
So writes
will always be counted and will trigger the signal, am i correct ?
Is there any way to achieve what i was trying to do in the issue ? (2 way state binding).
But the binding with two effects works.
Note that effects aren't synchronous. In your example, the following happens
b
is set to 10a
is set to 3$effect.pre
, but no such in the example$effect
in the order they are defined
5.1. the first effect does a = b
(10)
5.2. the second effect does b = a
(they are already equal, so b
doesn't change)$effect.pre
(for changed a
), but no such in the example@7nik Thanks for clarifications.
- runs
$effect
in the order they are defined
If $effects run in order they are defined i'd expect first effect to run first when i click a = 3
, which make a
to become 0 again, but in reality the second effect runs first, while the both are dependent to a
, provided an example here :
The other possiblity is that svelte is smart enough to know that don't re-run an effect only if written
states are chagned, in provided code a
get's written in the first effect so there is no need to re-run it.
while the both are dependent to
a
They aren't. $effects depend on only what they read (*) but not write: b
for the first and a
for the second.
*: in case of props, e.g. obj.foo.bar = 42
, obj.foo
is read, but .bar
isn't so that the effect will subscribe to obj
and obj.foo
here. Also, obj.foo.bar += 1
does read obj.foo.bar
.
Describe the bug
Hello guys,
My view on
untrack
function was such that if i useuntrack
inside an$effect
or$derived
rune all the states changes inside it would be ignored to other $effect and $dervied runes, and they would stop being triggered.As showed in the provided snippet, i have 2 states called
a
&b
which are both initially 0, my goal is to bind them both ways, meaning ifa
is changed theb
would be updated accordingly and ifb
is updateda
would be updated as well, but without falling into circular dependecy problem.My workaround (atleast what i thought would work), was to create 2
$effect
s with each one being dependent to eacha
&b
, and using untrack to stop the circular dependecy issue (please check snippet), at the result was not what i expected at all and it seems a little unpredictable to me, i guess i may have a incorrect idea about how it all works so i would appreciate any type of insight towards that.Thanks in advance.
Reproduction
Reproduction Snippet
Logs
No response
System Info
Severity
annoyance