events: getEventListeners static#35991
Closed
benjamingr wants to merge 1 commit intonodejs:masterfrom
Closed
Conversation
addaleax
reviewed
Nov 6, 2020
doc/api/events.md
Outdated
Member
There was a problem hiding this comment.
Suggested change
| 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 |
aduh95
reviewed
Nov 6, 2020
Contributor
aduh95
left a comment
There was a problem hiding this comment.
It seems unlikely this will be backported to v12 (going to maintenance this month), so we may as well use optional chaining
aduh95
reviewed
Nov 6, 2020
aduh95
reviewed
Nov 6, 2020
Collaborator
4 tasks
Collaborator
aduh95
reviewed
Nov 7, 2020
Contributor
There was a problem hiding this comment.
That seems unnecessary:
Suggested change
| // Flags: --expose-internals --no-warnings |
Member
Author
There was a problem hiding this comment.
This is needed for NodeEventTarget no?
Member
Author
There was a problem hiding this comment.
Oh, I ended up not needing it, fun
jasnell
approved these changes
Nov 7, 2020
4a25a04 to
b104cad
Compare
Collaborator
b104cad to
6ac986b
Compare
Trott
reviewed
Nov 8, 2020
Trott
reviewed
Nov 8, 2020
doc/api/events.md
Outdated
Member
There was a problem hiding this comment.
Suggested change
| ### `events.getEventListeners(emitterOrTarget, eventName)` | |
| ## `events.getEventListeners(emitterOrTarget, eventName)` |
6ac986b to
7bf4ac3
Compare
Collaborator
Member
Author
Contributor
|
Landed in ad98cf0...1a6d4dc |
nodejs-github-bot
pushed a commit
that referenced
this pull request
Nov 9, 2020
PR-URL: #35991 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
danielleadams
pushed a commit
that referenced
this pull request
Nov 9, 2020
PR-URL: #35991 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Merged
danielleadams
added a commit
that referenced
this pull request
Nov 10, 2020
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
danielleadams
added a commit
that referenced
this pull request
Nov 10, 2020
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
danielleadams
added a commit
that referenced
this pull request
Nov 10, 2020
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
targos
pushed a commit
to targos/node
that referenced
this pull request
Apr 24, 2021
PR-URL: nodejs#35991 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
targos
pushed a commit
to targos/node
that referenced
this pull request
Apr 26, 2021
PR-URL: nodejs#35991 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
targos
pushed a commit
to targos/node
that referenced
this pull request
Apr 30, 2021
PR-URL: nodejs#35991 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Merged
deokjinkim
added a commit
to deokjinkim/node
that referenced
this pull request
Apr 28, 2023
Use `getEventListeners` instead of `listenerCount` because nodejs#35991 was landed. Refs: nodejs#35991 Refs: nodejs#36006
MoLow
pushed a commit
to MoLow/node
that referenced
this pull request
Jul 6, 2023
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a static
getEventListenerstoevents. The major difference between it and.listenersis that it works withEventTargets and not just EventEmitters.This is useful after talking to users of
EventTargetandAbortControllerfor two main reasons:AbortSignals 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
EventTargetitself (from the public #whatwg IRC channel):Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes