change code to use `.addEventListener` instead?
See original GitHub issueWhen using addEventListener, one could pass an object onclick=${{ handleEvent }}
.
This article explains it in more details what potential benefits this can have: https://medium.com/@WebReflection/dom-handleevent-a-cross-platform-standard-since-year-2000-5bf17287fd38
I guess it would need only a single change here: https://github.com/shama/bel/blob/68b261e6892170fb972f4488ab4dfc200b125213/browser.js#L76
el[p] = val
would become
el.addEventListener(key.slice(2), val)
I can make the PR if this change would be desirable. If there are reasons why this would not be desirable, I’d be curious to learn about the reasons too 😃
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
addEventListener vs onclick - javascript - Stack Overflow
onclick can be added as an HTML attribute, whereas an addEventListener can only be added within <script> elements. addEventListener can take a third...
Read more >EventTarget.addEventListener() - Web APIs | MDN
It allows adding more than one handler for an event. This is particularly useful for libraries, JavaScript modules, or any other kind of...
Read more >The addEventListener() Method – JavaScript Event Listener ...
This tutorial shows you how you can implement addEventListener() in your code. Understanding Events and Event Handlers Events are actions ...
Read more >AddEventListener JavaScript: What It Is and How To Use It
For instance, use “change” rather than “onchange.” Some DOM events are click , change , drag , copy , etc. function is a...
Read more >addEventListener() function vs on property - this vs that
The other way is to use the onclick property or inline onclick attribute such ... the third parameter of addEventListener to true or...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@serapath you might be interested in #102 if you didn’t see it yet!
@goto-bus-stop I just checked your PR and the issue you linked that motivated it.
I personally would prefer a more minimal change, because:
{ handleEvent }
object{ handleEvent }
objectSo i would just pass for any listener
on${event.type}
the same{ handleEvent }
object of the component the template belongs to. Each individual tag in that template would would then have adata-call=handlerName
attribute, which makes the{ handleEvent }
actually pretty generic…but of course, just passing
this
currently doesn’t work, because bel does not support the{ handleEvent }
standard