/**
 * A small, type-safe in-process event bus.
 */
export class EventBus {
    listeners = new Map();
    on(event, handler) {
        const set = this.listeners.get(event) ?? new Set();
        set.add(handler);
        this.listeners.set(event, set);
    }
    off(event, handler) {
        const set = this.listeners.get(event);
        if (!set)
            return;
        set.delete(handler);
        if (set.size === 0) {
            this.listeners.delete(event);
        }
    }
    emit(event, payload) {
        const set = this.listeners.get(event);
        if (!set)
            return;
        for (const handler of set) {
            handler(payload);
        }
    }
}
//# sourceMappingURL=event-bus.js.map