import { type Accessor } from "solid-js"; import { type EmitterEmit, type EmitterListen, type EmitterOn } from "./emitter.js"; import { createEventBus, type Emit, type Listen } from "./eventBus.js"; export type EventHubPayloadMap = { [K in keyof M]: M[K] extends { emit: Emit; } ? T : never; }; export type EventHubValue = { [K in keyof M]: M[K] extends { value: Accessor; } ? T : never; }; /** * Required interface of a EventBus, to be able to be used as a channel in the EventHub */ export interface EventHubChannel { readonly listen: Listen; readonly emit: Emit; readonly value?: Accessor; } export type EventHub; }> = Readonly & { readonly on: EmitterOn>; readonly emit: EmitterEmit>; readonly listen: EmitterListen>; readonly value: EventHubValue; }; /** * Provides helpers for using a group of event buses. * * Can be used with `createEventBus`, `createEventStack` or any emitter that has the same api. * * @param defineChannels object with defined channels or a defineChannels function returning channels. * * @returns hub functions: `{on, emit, listen, value}` + channels available by their key * * @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/event-bus#createEventHub * * @example * const hub = createEventHub({ * busA: createEventBus(), * busB: createEventBus(), * busC: createEventStack<{ text: string }>() * }); * // can be destructured * const { busA, busB, on, listen, emit } = hub; * * hub.on("busA", e => {}); * hub.on("busB", e => {}); * * hub.emit("busA", 0); * hub.emit("busB", "foo"); */ export declare function createEventHub; }>(defineChannels: ((bus: typeof createEventBus) => M) | M): EventHub;