Description
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.