@joker.front/core
Version:
Joker is a framework platform engineered to support all development scenarios. Within its ecosystem, Joker.front stands as a front-end development framework. It delivers standardized front-end development protocols and employs an object-oriented, componen
40 lines (39 loc) • 1.41 kB
TypeScript
export type EventCallBackItem<T> = {
callBack: EventCallBackType<T>;
once?: Boolean;
};
export type EventCallBackType<T> = (e: {
eventName: string | number | Symbol;
stopPropagation: Function;
callTimes: Number;
}, params: T) => boolean | void | Promise<boolean | void>;
export declare class EventBus<T extends Record<string, any>> {
private eventDatas;
/**
* Register an event
* @param eventName Event name
* @param callBack Callback function
* @returns Event destruction function
*/
on<K extends keyof T>(eventName: K | "*", callBack: EventCallBackType<T[K]>): () => void;
/**
* Register a one-time event (triggers once)
* @param eventName Event name
* @param callBack Callback function
* @returns Event destruction function
*/
once<K extends keyof T>(eventName: K, callBack: EventCallBackType<T[K]>): () => void;
/**
* Remove event listeners
* @param eventName Event name (optional)
* @param callBack Specific callback to remove (optional)
*/
off<K extends keyof T>(eventName?: K, callBack?: EventCallBackType<T[K]>): void;
/**
* Trigger an event
* @param eventName Event name
* @param param Event parameter
* @returns Whether the event was stopped (`false` if stopped)
*/
trigger<K extends keyof T>(eventName: K, param?: T[K]): Promise<false | undefined>;
}