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

Element event directives reactivity #4388

Closed
Oreilles opened this issue Feb 8, 2020 · 2 comments · Fixed by #4394
Closed

Element event directives reactivity #4388

Oreilles opened this issue Feb 8, 2020 · 2 comments · Fixed by #4394
Assignees
Labels

Comments

@Oreilles
Copy link

Oreilles commented Feb 8, 2020

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

@Conduitry
Copy link
Member

Conduitry commented Feb 8, 2020

#3836 and a few followup PRs added support for dynamic event handler when the compiler can see that the event handler is getting reassigned (e.g,, if the 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.

@Conduitry
Copy link
Member

This is fixed in 3.18.2 - https://svelte.dev/repl/ca0fbda83f654f5a8829282a59f511f1?version=3.18.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.

2 participants