UNPKG

@logicflow/engine

Version:

a process engine for javascript

38 lines (37 loc) 1.08 kB
export interface EventType { readonly callback: (params?: any) => void; readonly once: boolean; } export type EventArgs = Record<string, unknown>; export type EventsType = Record<string, EventType[]>; export type CallbackType = (...args: unknown[]) => void; export default class EventEmitter { private _events; constructor(); /** * 添加一个监听事件 * @param evtKey 事件名称 * @param callback 回调方法 * @param once 是否触发一次 * @returns 当前 EventEmitter 实例 */ on(evtKey: string, callback: CallbackType, once?: boolean): void; /** * 取消监听一个事件,或者一个 Channel * @param evtKey * @param callback */ off(evtKey: string, callback?: CallbackType): void; /** * 主动触发事件 * @param evtKey 触发事件名称 * @param eventArgs 事件参数 */ emit(evtKey: string, eventArgs: EventArgs): void; /** * 获取当前所有事件 * @returns _events */ getEvents(): EventsType; } export { EventEmitter };