UNPKG

@empathyco/x-components

Version:
21 lines 1.24 kB
import type { XEvent, XEventPayload, XEventsTypes } from '../wiring/events.types'; import type { WireMetadata } from '../wiring/wiring.types'; import type { EventPayload, SubjectPayload } from '../x-bus'; /** * Composable which injects the current location, returns the `on` and `emit` functions * using the bus and applying component metadata. Also unsubscribe from events when components is * unmounted. * * @remarks This composable tries to use the `XPlugin` bus and catches the exception thrown * by the `XPlugin` if it was not instantiated and uses the default `xBus` as fallback. * * @returns An object with the `on` and `emit` functions. * @public */ export declare function useXBus(): { on: <Event extends XEvent, Metadata extends boolean>(event: Event, withMetadata: Metadata) => { subscribe: (callback: (payload: Metadata extends true ? SubjectPayload<EventPayload<XEventsTypes, Event>, WireMetadata> : EventPayload<XEventsTypes, Event>) => void) => void; }; emit: <Event extends XEvent>(event: Event, payload?: XEventPayload<Event>, metadata?: Omit<WireMetadata, "moduleName">) => Promise<import("../x-bus").EmittedData<XEventsTypes, Event, WireMetadata>>; }; //# sourceMappingURL=use-x-bus.d.ts.map