UNPKG

toolset.io

Version:

前端开发常用工具集。

64 lines (63 loc) 1.93 kB
export declare class EventBus { private events; private static instance; /** * Get all registered events. */ static getEvents(): Map<string, CallableFunction>; /** * Get the number of registered events. */ static getEventsSize(): number; /** * Get the callback function of a specific event. * @param name Event name */ static getEvent(name: string): CallableFunction | undefined; /** * Check if an event is registered. * @param name Event name */ static hasEvent(name: string): boolean; /** * Delete an event. * @param name Event name * @returns Whether the event was deleted */ static deleteEvent(name: string): boolean; /** * Register or overwrite an event. * @param name Event name * @param callback Callback function */ static setEvent(name: string, callback: CallableFunction): Map<string, CallableFunction>; /** * Bind an event. * @param name Event name * @param callback Callback function */ static on(name: string, callback: CallableFunction): Map<string, CallableFunction>; /** * Trigger an event. * @param name Event name * @param payload Arguments passed to the callback */ static emit(name: string, ...payload: any[]): any; /** * Trigger an event once and then remove it. * @param name Event name * @param payload Arguments passed to the callback */ static once(name: string, ...payload: any[]): any; /** * Remove one or more events. * @param name Event name or array of names * @returns Whether all events were removed */ static off(name: string | string[]): boolean; /** * Get the singleton instance of EventBus. */ static getInstance(): EventBus; private static isFunction; }