blob: 9ae8241f2a1a8a93addbedf8956bd46fed31e53d (
plain) (
tree)
|
|
const EventSystem = {
listeners: new Map(),
on(event, callback) {
if (!this.listeners.has(event)) {
this.listeners.set(event, new Set());
}
this.listeners.get(event).add(callback);
},
emit(event, data) {
if (this.listeners.has(event)) {
this.listeners.get(event).forEach(callback => callback(data));
}
}
};
|