export function createEventBus() {
    const handlers = new Map();
    const on = (name, handler) => {
        const set = handlers.get(name) || new Set();
        set.add(handler);
        handlers.set(name, set);
        return () => {
            const current = handlers.get(name);
            if (!current) {
                return;
            }
            current.delete(handler);
            if (current.size === 0) {
                handlers.delete(name);
            }
        };
    };
    const once = (name, handler) => {
        const off = on(name, (event) => {
            off();
            handler(event);
        });
        return off;
    };
    const emit = (name, event) => {
        const set = handlers.get(name);
        if (!set || set.size === 0) {
            return;
        }
        for (const handler of set) {
            handler(event);
        }
    };
    return {
        on,
        once,
        emit,
    };
}
//# sourceMappingURL=event-bus.js.map