retrobus
Version:
An event bus that allows listeners to be retroactive
20 lines (19 loc) • 919 B
TypeScript
type Callback = (...args: any[]) => void;
interface Options {
retro?: boolean;
retroStrategy?: 'last-one' | 'all';
once?: boolean;
unique?: boolean;
}
export declare const addEventBusListener: (name: string | Symbol, callback: Callback, options?: Options) => (() => void);
export declare const removeEventBusListener: (name: string | Symbol, callback: Callback) => void;
export declare const clearEventBusListeners: (name?: string | Symbol) => void;
export declare const emit: <T extends unknown>(name: string | Symbol, ...args: T[]) => void;
export declare const clearEmittedEvents: (name?: string | Symbol) => void;
export declare const createEventBus: <T>(event?: string | Symbol) => {
emit: (payload: T) => void;
clearEmittedEvents: () => void;
addEventBusListener: (callback: (payload: T) => void, options?: Options) => () => void;
clearEventBusListeners: () => void;
};
export {};