Mechanism to listen for all events
See original GitHub issueIs 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:
- Created 8 years ago
- Reactions:4
- Comments:23 (10 by maintainers)
Top 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 >
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
Because I don’t want my event handling dependent on my rendering library. And business-as-usual sucks. Whatever happened to “rethinking best practices”?
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)
React.createElement
callonClick
,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.