|
|
|
|
|
by apd_
1384 days ago
|
|
I believe you're referring to $ not being fired when another $ below it updates the variable the first $ subscribes to. This is an expected behavior. In Svelte the order of $ matters to prevent infinite loops. In this example the second $ won't trigger the first $: let a = 1;
let b = 1;
$: if (a > 0) { b += 1 }
$: if (b > 0) { a += 1 }
With React's useEffect one can easily falls into the trap of an infinite re-rendering: let a = 1;
let b = 1;
useEffect(() => {
b += 1;
}, [a]);
useEffect(() => {
a += 1;
}, [b]);
Great framework are supposed to prevent this kind of loophole. |
|
https://github.com/sveltejs/svelte/issues/6730
https://github.com/sveltejs/svelte/issues/6732
So basically, reactive blocks are only allowed to run once per tick; if a dependency changes after a block has run, too bad, the block won't run again. That is really shocking to me. (I won't say more due to my inexperience with Svelte...)