This repository was archived by the owner on Oct 14, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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" ) ;
You can’t perform that action at this time.
0 commit comments