Skip to content

EventTarget in Node - should it expose capabilities like removeAllListeners? #33558

Closed
@benjamingr

Description

@benjamingr

Work is currently underway to add support for EventTarget in Node.js, this was discussed in several summits in the past and is a stepping stone for AbortController and fetch in Node 🎉

(that PR lands it as experimental and with no open API surface so this issue should not block or delay that PR IMO anyway).

There are (at least) two possible approaches for EventTarget in Node.js:

  • We can make EventTarget as close as possible in terms of capabilities to the DOM version.
  • We can make EventTarget as compatible with EventEmitter as possible.

Note that to my understanding the API does not prohibit us from exposing additional things (like removeAllListeners) but it would still be a violation of the liskov substitution principle (users might expect event listeners to not be removable or discoverable).

Note the APIs are quite different from each other.

The second approach has advantages of probably easier gradual migration and the first approach has the advantage of more closely being universal. Namely: code using the second approach would have to limit itself to not using these APIs in order to be universal in the first place anyway.

Note as prior art, abort-controller in NPM supports these methods but browsers do not.

cc @jasnell @ljharb @nodejs/events @mcollina

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussIssues opened for discussions and feedbacks.eventsIssues and PRs related to the events subsystem / EventEmitter.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions