- From: Cyril Auburtin <notifications@github.com>
- Date: Thu, 29 Apr 2021 12:50:29 -0700
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Thursday, 29 April 2021 19:50:41 UTC
Oh great feature, so something like that below can be rewritten with AbortController ```js button.addEventListener('click', () => { // ... function closeByClick() { // ... do stuff closeButton.removeEventListener('click', closeByClick); window.removeEventListener('keydown', closeByEscape); } function closeByEscape(e) { if (e.key !== 'Escape') return; // ... do stuff closeButton.removeEventListener('click', closeByClick); window.removeEventListener('keydown', closeByEscape); } closeButton.addEventListener('click', closeByClick); window.addEventListener('keydown', closeByEscape); }); ``` like this: ```js button.addEventListener('click', () => { // ... const controller = new AbortController(); closeButton.addEventListener('click', () => { // ... do stuff controller.abort(); }, { signal: controller.signal }); window.addEventListener('keydown', e => { if (e.key !== 'Escape') return; // ignore other keys than Escape // ... do stuff controller.abort(); }, { signal: controller.signal }); }); ``` -- 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/911#issuecomment-829547030
Received on Thursday, 29 April 2021 19:50:41 UTC