123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- export class WorkboxEventTarget {
- constructor() {
- this._eventListenerRegistry = new Map();
- }
-
- addEventListener(type, listener) {
- const foo = this._getEventListenersByType(type);
- foo.add(listener);
- }
-
- removeEventListener(type, listener) {
- this._getEventListenersByType(type).delete(listener);
- }
-
- dispatchEvent(event) {
- event.target = this;
- const listeners = this._getEventListenersByType(event.type);
- for (const listener of listeners) {
- listener(event);
- }
- }
-
- _getEventListenersByType(type) {
- if (!this._eventListenerRegistry.has(type)) {
- this._eventListenerRegistry.set(type, new Set());
- }
- return this._eventListenerRegistry.get(type);
- }
- }
|