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

Multiple event listeners per node #2688

Closed
LostKobrakai opened this issue May 5, 2019 · 3 comments
Closed

Multiple event listeners per node #2688

LostKobrakai opened this issue May 5, 2019 · 3 comments

Comments

@LostKobrakai
Copy link
Contributor

LostKobrakai commented May 5, 2019

It would be quite neat to allow for multiple event listeners per node even if they're of the same type. It already works when one is using a modifier and the other doesn't, but otherwise there will be an error about Attributes need to be unique. I've already looked into the code and it could be changed by moving the check for unique attributes a few lines lower and giving it an extra case for EventHandlers. Tests are still green after the change.

<script>
  import Component from './Component.svelte';
  function onInput(event) {
    console.log(event)
  }
</script>

<Component let:listener>
  <input on:input={listener} on:input={onInput} />
</Component>
@EmilTholin
Copy link
Member

EmilTholin commented May 5, 2019

Hi @LostKobrakai! Could you not do something like the following:

<script>
  import Component from './Component.svelte';
  function onInput(event) {
    console.log(event)
  }
</script>

<Component let:listener>
  <input on:input={e => { listener(e); onInput(e); }} />
</Component>

@LostKobrakai
Copy link
Contributor Author

LostKobrakai commented May 5, 2019

Sure, but I don't see much reason against supporting the notation I proposed especially given it already works with different modifiers. It currently seems to be more of an accidental restriction of the unique attributes check. Having the ability to attach multiple handlers is imho more in line with using multiple addEventListeners and seems easier to change, as the functions are not arbitrarily entangled.

@LostKobrakai
Copy link
Contributor Author

This is now merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants