handleEvent for the win :)
See original GitHub issueIssue Description
Hey dear friends!
Do you know about this? https://www.thecssninja.com/javascript/handleevent
I think it would be a nice addition if your eventhandling would accept objects like in vanilla js!
var app = {
state: { title: 'Example' },
handleEvent: function(evt) { ....
render: function() {
return h('button', { onclick: this })
}
...
}
....
No bind is required when you use vanilla htmlButton.addEventListener('click', app)
!
Thanks for your feedback in advance!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
handleEvent(_:) | Apple Developer Documentation
Tells the Cocoa text input system to handle mouse or key events. macOS 10.6+. Declaration. func handleEvent(_ event: NSEvent ) -> Bool. Parameters....
Read more >EventTarget.addEventListener() - Web APIs | MDN
The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered ...
Read more >Using Event Objects (Synchronization) - Win32 - Microsoft Learn
First, the master thread uses the CreateEvent function to create a manual-reset event object whose initial state is nonsignaled. Then it creates ...
Read more >DOM handleEvent: a cross-platform standard since year 2000
This is a mandatory TL;DR for all developers believing they fully understood what is handleEvent about and what does it solve: it's the...
Read more >Comparison between passing an object with a handleEvent ...
var listener = { handleEvent: function (evt) { this === listener; // true // and evt === classic event object } }; document.addEventListener("click",...
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
Hi @CitrusFruits Thanks a lot for your investigation! Yeah sadly the handleEvent only works with addEventHandler 😕. Personally I would then keep it as is, its not like hundereds of peeps asked for this in the past years 😂
Stumbled upon this issue today and decided to give it a go. After working on it a bit, I don’t think this is possible without making significant accommodations in Maquette. This is due to the difference between adding an event listener with
addEventListener(...)
vs directly setting properties on a DOM node, e.g.myNode.oninput = myFunction()...
If you take a look at this codepen you can see the difference plainly.
If we wanted to make this work, Maquette would need to adjust all implementations of
on*
properties to useaddEventListener
instead of setting properties directly. Alternatively, we could introduce a domain specificVNodeProperties
member such asonEvent
that could accommodate either function or object handlers.But, both of those approaches seem like unnecessary complexity, especially with Maquette’s goal to be as small/lightweight as possible.