UNPKG

phx-react

Version:

PHX REACT

20 lines 645 B
class EventBus { constructor() { this.events = new Map(); } on(event, callBack) { const handlers = this.events.get(event) || []; handlers.push(callBack); this.events.set(event, handlers); } off(event, callBack) { const handlers = this.events.get(event) || []; this.events.set(event, handlers.filter((h) => h !== callBack)); } emit(event, payload) { var _a; (_a = this.events.get(event)) === null || _a === void 0 ? void 0 : _a.forEach((callBack) => callBack(payload)); } } export const eventBus = new EventBus(); //# sourceMappingURL=eventBus.js.map