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.

Mechanism to listen for all events

See original GitHub issue

Is there already such a mechanism? If so, can I help document it?

If not, I’ll like to have a method or API that I could call to listen for all synthetic events. Something like…

React.Events.listenTo('*', function (event) { console.log(event) });

I’d like to be able to stopPropagation and preventDefault on those events, as well.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:4
  • Comments:23 (10 by maintainers)

github_iconTop GitHub Comments

8reactions
nwwellscommented, Jun 29, 2015

Because I don’t want my event handling dependent on my rendering library. And business-as-usual sucks. Whatever happened to “rethinking best practices”?

3reactions
javierfernandescommented, Jun 8, 2020

This is probably useless after 5 years, but I was just reading it because I also would love to be able to intercept all events, in my case to measure selectors recomputations/time on each event. Performance tracking lets say.

I was thinking that a way to do this if there’s still no API to intercept all events would be to use a custom JSX pragma function (https://babeljs.io/docs/en/babel-plugin-transform-react-jsx)

  • intercept all React.createElement call
  • wrap all values passed to well-known event attributes like onClick, onMouseOver etc. with a wrapper function to do whatever you want.

I haven’t tried it, but sounds like it should to the trick if you use JSX. Of course it has an overhead, in my case I can use it just for dev purpose. Sort of a cross-cutting concern.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introduction to events - Learn web development | MDN
js event model relies on listeners to listen for events and emitters to emit events periodically — it doesn't sound that different, but...
Read more >
How can I add an event listener for all events in javascript ...
To listen for all these manually triggered events, we can proxy the dispatchEvent method globally and install our listener just-in-time for ...
Read more >
How does an event listener work?
When an event occurs, the event handler iterates over its list and executes each callback.
Read more >
Handling Events :: Eloquent JavaScript
The addEventListener method is used to register such a handler. Each event has a type ( "keydown" , "focus" , and so on)...
Read more >
SWT provides two kinds of event listening mechanism
A typed listener can be used to listen for only one particular typed event. For example, SelectionListener is a typed listener for event...
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