-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b33248
commit 8302bec
Showing
8 changed files
with
1,344 additions
and
1,205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
type EventHandler = (event: Event) => void; | ||
type EventListenersMap = { [event: string]: EventHandler }; | ||
|
||
const eventListeners = new WeakMap<Element, EventListenersMap>(); | ||
|
||
export function addTrackedEventListener( | ||
element: Element, | ||
event: string, | ||
handler: EventHandler | ||
): void { | ||
if (!eventListeners.has(element)) { | ||
eventListeners.set(element, {}); | ||
} | ||
const listeners = eventListeners.get(element)!; | ||
listeners[event] = handler; | ||
element.addEventListener(event, handler); | ||
} | ||
|
||
export function hasEventListener(element: Element, event: string): boolean { | ||
return eventListeners.has(element) && !!eventListeners.get(element)?.[event]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.