-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
events: getEventListeners static #35991
Conversation
doc/api/events.md
Outdated
For `EventEmitter`s this behaves exactly the same as calling `.listeners` on | ||
the emitter. | ||
|
||
For `EventTargegt`s this is the only way to get the event listeners for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For `EventTargegt`s this is the only way to get the event listeners for the | |
For `EventTarget`s this is the only way to get the event listeners for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems unlikely this will be backported to v12 (going to maintenance this month), so we may as well use optional chaining
@@ -0,0 +1,37 @@ | |||
// Flags: --expose-internals --no-warnings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems unnecessary:
// Flags: --expose-internals --no-warnings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed for NodeEventTarget no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I ended up not needing it, fun
4a25a04
to
b104cad
Compare
b104cad
to
6ac986b
Compare
doc/api/events.md
Outdated
@@ -829,6 +829,39 @@ class MyClass extends EventEmitter { | |||
} | |||
``` | |||
|
|||
### `events.getEventListeners(emitterOrTarget, eventName)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### `events.getEventListeners(emitterOrTarget, eventName)` | |
## `events.getEventListeners(emitterOrTarget, eventName)` |
6ac986b
to
7bf4ac3
Compare
Landed in ad98cf0...1a6d4dc |
PR-URL: #35991 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
PR-URL: #35991 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Notable changes: * events: * getEventListeners static (Benjamin Gruenbaum) (#35991) * fs: * support abortsignal in writeFile (Benjamin Gruenbaum) (#35993) * add support for AbortSignal in readFile (Benjamin Gruenbaum) (#35911) * stream: * fix thrown object reference (Gil Pedersen) (#36065) PR URL: #36055
Notable changes: * events: * getEventListeners static (Benjamin Gruenbaum) (#35991) * fs: * support abortsignal in writeFile (Benjamin Gruenbaum) (#35993) * add support for AbortSignal in readFile (Benjamin Gruenbaum) (#35911) * stream: * fix thrown object reference (Gil Pedersen) (#36065) PR URL: #36055
Notable changes: * events: * getEventListeners static (Benjamin Gruenbaum) (#35991) * fs: * support abortsignal in writeFile (Benjamin Gruenbaum) (#35993) * add support for AbortSignal in readFile (Benjamin Gruenbaum) (#35911) * stream: * fix thrown object reference (Gil Pedersen) (#36065) PR URL: #36055
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR-URL: nodejs#35991 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
PR-URL: nodejs#35991 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
PR-URL: nodejs#35991 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Use `getEventListeners` instead of `listenerCount` because nodejs#35991 was landed. Refs: nodejs#35991 Refs: nodejs#36006
Use `getEventListeners` instead of `listenerCount` because nodejs#35991 was landed. Refs: nodejs#35991 Refs: nodejs#36006 PR-URL: nodejs#47759 Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Mestery <mestery@protonmail.com>
This adds a static
getEventListeners
toevents
. The major difference between it and.listeners
is that it works withEventTarget
s and not just EventEmitters.This is useful after talking to users of
EventTarget
andAbortController
for two main reasons:AbortSignal
s potentially.cc @bterlson
This has to be a static because we are not allowed to add this method on
EventTarget.prototype
. I checked with WHATWG and the only way I could come up with that is both spec compliant and addresses the use case.The web platform itself does not have a way to do this (due to encapsulation) but I double checked we are allowed to expose this functionality as long as it's not on
EventTarget
itself (from the public #whatwg IRC channel):Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes