16 lines
375 B
JavaScript
16 lines
375 B
JavaScript
|
|
|
|
export class EventHandler {
|
|
constructor() {
|
|
this.subscribers = {};
|
|
}
|
|
|
|
addEventListener(type, handler) {
|
|
if (!this.subscribers[type]) this.subscribers[type] = [];
|
|
this.subscribers[type].push(handler);
|
|
}
|
|
|
|
emit(type, ...data) {
|
|
if (this.subscribers[type]) this.subscribers[type].forEach(handler => handler(...data));
|
|
}
|
|
} |