I'm in a context similar to the one below:
Some DOM element (here a button), which when clicked should call a callback function (test), which may change depending on a certain state (the variable bool)
let bool = false
let foo = () => console.log("foo")
let bar = () => console.log("bar")
$: test = bool ? foo : bar;
When the variable bool change, the callback is only updated when writing the directive like this:
<button on:click={() => test()} />
But if written that way, the callback will keep its first value even if the state change:
<button on:click={test} />
I would expect the two declarations to behave in the same way.
Replicate:
https://svelte.dev/repl/ca0fbda83f654f5a8829282a59f511f1?version=3.18.1
swap() function instead directly assigned either foo or bar to test, this would work), but apparently it's not taking this reactive declaration into account.This is fixed in 3.18.2 - https://svelte.dev/repl/ca0fbda83f654f5a8829282a59f511f1?version=3.18.2
Most helpful comment
This is fixed in 3.18.2 - https://svelte.dev/repl/ca0fbda83f654f5a8829282a59f511f1?version=3.18.2