UNPKG

@daiso-tech/core

Version:

The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.

38 lines (37 loc) 1.35 kB
/** * @module EventBus */ import type { InvokableFn } from "../../utilities/_module-exports.js"; /** * * IMPORT_PATH: `"@daiso-tech/core/event-bus/contracts"` * @group Contracts */ export type BaseEvent = Record<string, unknown>; /** * * IMPORT_PATH: `"@daiso-tech/core/event-bus/contracts"` * @group Contracts */ export type EventListenerFn<TEvent> = InvokableFn<[event: TEvent]>; /** * The `IEventBusAdapter` contract defines a way for dispatching and listening to events independent of underlying technology. * This contract is not meant to be used directly, instead you should use `IEventBus` * * IMPORT_PATH: `"@daiso-tech/core/event-bus/contracts"` * @group Contracts */ export type IEventBusAdapter = { /** * The `addListener` method is used for adding {@link EventListenerFn | `listener`} for certain `eventName`. */ addListener(eventName: string, listener: EventListenerFn<BaseEvent>): PromiseLike<void>; /** * The `removeListener` method is used for removing {@link EventListenerFn | `listener`} for certain `eventName`. */ removeListener(eventName: string, listener: EventListenerFn<BaseEvent>): PromiseLike<void>; /** * The `dispatch` method is used for dispatching one or multiple `events`. */ dispatch(eventName: string, eventData: BaseEvent): PromiseLike<void>; };