Skip to content
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

RFC - EventTarget API Enhancements #36073

Closed
benjamingr opened this issue Nov 10, 2020 · 1 comment
Closed

RFC - EventTarget API Enhancements #36073

benjamingr opened this issue Nov 10, 2020 · 1 comment
Labels
eventtarget Issues and PRs related to the EventTarget implementation.

Comments

@benjamingr
Copy link
Member

benjamingr commented Nov 10, 2020

I've started working on an API enhancement for EventTarget that allows passing a signal to the options dictionary of addEventListener. As a side node I've prototyped the same for Node.js EventEmitter at #35877 (currently blocked on something V8 is working on).

This would let uses do the following:

// Does not yet work, suggested:
const ac = new AbortController();
let { signal } = ac;
const et = new EventTarget();
et.addEventListener('foo', (e) => {
  
}, { signal } );
ac.abort(); // removes the listener from the event target, same as et.removeEventListener('foo', thatFunctionReference)

In node land - this would be for example: unsubscribing from "message" and abort at the same time on multiple workers.

I wanted this feature for Node but I also find it very useful for browsers. I'm pretty clueless at this (Bikeshed etc) and Anne and Domenic have been helping me a ton with the spec work.

I personally think this positively impacts Node because:

  • Node was in my mind when I started working on this
  • I will happily do the technical part of implementing this in our EventTarget

That said: too many times in the past Node was an afterthought in open standards the project participates in and I want to gather feedback in case there are unforeseen negative consequences from our side.

So - is there anything this should do differently?


I would personally strongly prefer it if comments were given in this issue first to reduce the noise for WHATWG folks who have been helping me on this but really don't owe me anything.

Currently I have a spec draft ready at: whatwg/dom#919
Initial Chromium implementation (by chromium at whatwg/dom#911 (comment) )
Implementor interest by Firefox and Chromium.

@benjamingr benjamingr added the eventtarget Issues and PRs related to the EventTarget implementation. label Nov 10, 2020
@jasnell
Copy link
Member

jasnell commented Nov 10, 2020

This is definitely interesting and useful. The spec will need to cover the full lifecycle including when the EventTarget unsubscribes from the signal but that's straightforward. Off the top of my head I can't think of any issues with this so I'd say go for it.

danielleadams pushed a commit that referenced this issue Dec 7, 2020
PR-URL: #36258
Fixes: #36073
Reviewed-By: James M Snell <jasnell@gmail.com>
cjihrig pushed a commit to cjihrig/node that referenced this issue Dec 8, 2020
PR-URL: nodejs#36258
Fixes: nodejs#36073
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eventtarget Issues and PRs related to the EventTarget implementation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants