Files
snek/src/snek/static/event-handler.js
T
2025-03-16 04:47:03 +00:00

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));
}
}