Use abort controllers to remove events
See original GitHub issueEither internally or just for the public API, it could support abort controllers instead of returning .destroy()
Examples for the public API:
// User-defined controller
const controller = new AbortController();
delegate(document, 'a', 'click', handler, {signal: controller.signal});
controller.abort();
// Always create a controller instead of `.destroy()`
const controller = delegate(document, 'a', 'click', handler);
controller.abort();
Unfortunately, Safari does not support the signal natively on addEventListener
, so internally it should keep using removeEventListener
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Using AbortController as an Alternative for Removing ...
Here's a super simple example using AbortController to cancel a fetch() request: const controller = new AbortController(); ...
Read more >When to use AbortController to remove event listeners?
OLD ANSWER: The Abort Controller object is for aborting fetch calls, not for removing event listeners. If you need to remove multiple listener's ......
Read more >AbortSignal: abort event - Web APIs - MDN Web Docs - Mozilla
The abort event of the AbortSignal is fired when the associated request is aborted, i.e. using AbortController.abort().
Read more >TIL — Removing DOM Event Handlers using AbortController
Today I learned about the ability to remove DOM event handlers using AbortController. There is plenty of other good use cases for this ......
Read more >Cancel JavaScript Event Listeners with AbortController
By calling controller.abort(); , you can remove the listener from the event target, just like when calling element.removeEventListener .
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s Safari 15+, it’s good enough for me, this will be a breaking release anyway 👍
I’ve implemented this, but I can’t update the tests because JSDOM doesn’t support
AbortSignal
inaddEventListener
yet: https://github.com/jsdom/jsdom/issues/3327. I guess I’ll take a stab at it