Re: [whatwg/dom] Expose EventListenerOptions to the event listener when invoked (#501)

Now that you have the signal argument and don't care about a reference to the listener for `removeEventListener` you can just register the "same" listener multiple times by wrapping it:

```js
// Added multiple times, the anonymous functions are no longer an issue
// because we don't need a reference for removeEventListener
target.addEventListener('foo', (e) => myFn(e), { signal });
target.addEventListener('foo', (e) => myFn(e), { signal });
```

That said, doing what you describe is pretty easy? (and pretty small), just adding a signal to:

```
If eventTarget’s event listener list does not contain an event listener whose type is listener’s type, callback is listener’s callback, and capture is listener’s capture, then append listener to eventTarget’s event listener list.
```

I am not sure if it introduces complexity to browsers so I'm hesitant to offer to open a spec PR/WPTs if it's problematic for browsers to add that check when you add or remove a listener.

(A potential downside is that it would probably imply `removeEventListener` wouldn't work without passing the same `signal` in)

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/501#issuecomment-740810368

Received on Tuesday, 8 December 2020 18:10:39 UTC