Skip to content
This repository was archived by the owner on Oct 14, 2025. It is now read-only.

Commit 6b2899d

Browse files
committed
AbortController
1 parent 9971638 commit 6b2899d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
# Easy addEventListener
1+
# The Easiest
2+
3+
Using `AbortController` is the best approach and requires nothing additional. Therefore this repo will be archived.
4+
5+
```typescript
6+
const abortController = new AbortController();
7+
window.addEventListener("load", () => {}, abortController);
8+
9+
abortController.abort();
10+
```
11+
12+
---
13+
14+
# [ARCHIVED] Easy addEventListener
215

316
[![Test](https://github.com/ShaMan123/easyAddEventListener/actions/workflows/test.yml/badge.svg)](https://github.com/ShaMan123/easyAddEventListener/actions/workflows/test.yml)
417

index.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@ assert(
1010
addEventListenerFactory() === addEventListener,
1111
"should return addEventListener"
1212
);
13+
14+
const abortController = new AbortController();
15+
const target = new EventTarget();
16+
let i = 0;
17+
target.addEventListener("foo", () => i++, abortController);
18+
target.dispatchEvent(new CustomEvent("foo"));
19+
abortController.abort();
20+
target.dispatchEvent(new CustomEvent("foo"));
21+
assert(i === 1, "should remove event listener after calling abort");

0 commit comments

Comments
 (0)