interface IEvent { cb: (...args: any[]) => any; ctx: any; } interface IEventMap { [event: string]: IEvent; } /** * Event Handler * @desc * - only enabled event can be emitted * - If the callback of an event is not set, alert will be called by default on the browser, and Error will be triggered in nodejs * @author kinghand@foxmail.com */ export default class EventHandler { protected _defaultCb: (...args: any[]) => any; protected _eventMap: IEventMap; protected _supportedEvents: string[]; constructor(supportedEvents?: string[] | IEventMap); /** * enable event names * @param {Array | Object} supportedEvents - keys will be used when it's an object */ enableEvents(supportedEvents: any): void; /** * set callback of an event name * @param {string} event - event name * @param {Function} fnCallback - if there is already a callback, then the new one will cover the previous one. * @param {*} instance - the instance of the callback. * @return {EventHandler} - for pipeline */ setEvent(event: string, fnCallback: (...args: any[]) => any, instance: any): this; /** * trigger an event by name * @param {string} event - event name * @param {Array} args - arguments */ emitEvent(event: string, ...args: any[]): any; } export {};