UNPKG

@empathyco/x-components

Version:
21 lines 1.3 kB
import { EventPayload, SubjectPayload } from '@empathyco/x-bus'; import { XEventPayload, XEventsTypes } from '../wiring/events.types'; import { WireMetadata } from '../wiring/wiring.types'; /** * 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_1 extends keyof XEventsTypes, Metadata extends boolean>(event: Event_1, withMetadata: Metadata) => { subscribe: (callback: (payload: Metadata extends true ? SubjectPayload<EventPayload<XEventsTypes, Event_1>, WireMetadata> : EventPayload<XEventsTypes, Event_1>) => void) => void; }; emit: <Event_2 extends keyof XEventsTypes>(event: Event_2, payload?: XEventPayload<Event_2> | undefined, metadata?: Omit<WireMetadata, 'moduleName'>) => Promise<import("@empathyco/x-bus").EmittedData<XEventsTypes, Event_2, WireMetadata>>; }; //# sourceMappingURL=use-x-bus.d.ts.map