-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Use EventTarget.prototype.addEventListener instead of the method (#…
- Loading branch information
1 parent
16efff7
commit a988b93
Showing
9 changed files
with
137 additions
and
86 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
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,28 @@ | ||
export class MockEventTarget { | ||
public listeners: { [k: string]: EventListener[] } = {} | ||
|
||
addEventListener(type: string, listener: EventListener, _options?: boolean | AddEventListenerOptions): void { | ||
if (!this.listeners[type]) { | ||
this.listeners[type] = [] | ||
} | ||
|
||
this.listeners[type].push(listener) | ||
} | ||
|
||
removeEventListener(type: string, listener: EventListenerOrEventListenerObject) { | ||
if (!this.listeners[type]) { | ||
throw new Error(`Can't remove a listener. Event "${type}" doesn't exits.`) | ||
} | ||
|
||
this.listeners[type] = this.listeners[type].filter((lst) => listener !== lst) | ||
} | ||
|
||
dispatchEvent(event: Event): boolean { | ||
if (this.listeners[event.type]) { | ||
this.listeners[event.type].forEach((listener) => { | ||
listener.apply(this, [event]) | ||
}) | ||
} | ||
return true | ||
} | ||
} |
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
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