question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

handleEvent for the win :)

See original GitHub issue

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:open
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
katywingscommented, Dec 28, 2019

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 😂

2reactions
CitrusFruitscommented, Dec 27, 2019

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 use addEventListener instead of setting properties directly. Alternatively, we could introduce a domain specific VNodeProperties member such as onEvent 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found