-
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
EventTarget in Node - should it expose capabilities like removeAllListeners? #33558
Comments
Please see the initial discussion in the PR here #33556 (comment) Personally I see compelling point both ways and I'm not sure what's the better approach. |
Carried my response over to here as the flow suggests. The quotes are from #33556
Sorry for the intervention but are these guarantees codified anywhere, or, in other words, could theoretically relying on such be ever considered basically some sort of bad habit instead?
It may be worthwhile to consider if sticking to a definitely incomplete and asymmetrical, but possibly also crippled and/or irrational implementation for whatever reason is of any actual benefit. For development, this is immensely helpful (and please let me point out that an implementation ("circumvention") is quite easy simply by mutating the EventTarget's prototype before any event listeners are being added. |
@strongholdmedia they are codified on the web, I believe. The discussion on WHATWG imo was overwhelmingly in favor of not exposing this API. The primary security JS offers is in first-run code; pretty much anything that requires prior modification is indefensible and thus not a concern. |
The latest solution in the PR:
I think that approach makes sense although we would still have to answer what flavor the emitters we ship ourselves are. |
The plan for |
Indeed, you seemed quite overwhelmed to make it appear so.
I believe this is an elegant and excellent solution. |
@strongholdmedia better naming suggestions welcome :]
Can you explain this? I just checked really quickly and I don't think |
Ah! I was mistaken about the abort-controller module! There was an impl that I came across that did support both but for the life of me I can't remember the name of it and for some reason had it in my mind that it was abort-controller! The remove functions in event emitter are absolutely question marks either way. The only ones that I absolutely think we need to have are on/once/addListener. Everything else is optional. |
@jasnell p I think Node.js can be helpful (by providing these) as long as we make sure all our internal methods don't rely on this behavior (and work with the regular AbortController API). It seems to me that the major issue people have with extending these interfaces is we'd be shipping a different API from the DOM's with the same names. I think we can:
|
There is a PR to only land EventTarget and remove NodeEventTarget #33665 If anyone has strong reasons about whether or not Node should land the extensions or not - now is a good time to bring them up :] Also - it's worth mentioning that landing EventTarget now without the extensions doesn't mean we can't add the extensions later on. |
Let's keep |
Well.. If the latest implementation has something along
After I spent the whole day working with the legacy/browser As most of you surely know, the current legacy But then again, please note that I realize that even this approach does not try to solve the problems (if they even are, judged subjectively). I would just like to pinpoint that sometimes it may be justifiable to observe the proposed evolution from more than a single angle. If anything it is exactly stuff like this that I consider worthwhile updating/extending/enhancing. Also sorry for the late reply - I mixed up the comments here with those at the PR, and as such, I thought the discussion passed me by long since. |
After reviewing the code and finding that there is no means to retrieve the current listeners, I think the |
@strongholdmedia ActionScript's Although, you might have it backwards, the event model in ActionScript 3 is based on the DOM's and not vice versa:
FWIW they didn't actually implement the spec which meant code wasn't portable between flash and browser JavaScript and there was a mental overhead regarding differences. |
I think we can close this for now. We have separated out NodeEventTarget and EventTarget and will keep the EventEmitter emulation limited to |
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:
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
The text was updated successfully, but these errors were encountered: