UNPKG

class-event-handler

Version:
74 lines (73 loc) 2.79 kB
declare type CallableType = (...args: any[]) => void; /** * Class for implementing callback events */ export declare class EventHandler { private listeners; private onceListeners; private triggerdLabels; constructor(); /** * Helper-function for onReady and onceReady * the callbackfunction will execute, * if the label has already been triggerd with the last called parameters * * @param label lebel of callback * @param callback callback function */ private wasCalled; /** * Execute the callback everytime the label is trigger * @param label label of callback * @param callback callback function * @param checkPast check if the label had been already called * and if so excute the callback immediately with the same * parameters as last callback; default: `false` */ on<T extends CallableType>(label: string, callback: T, checkPast?: boolean): void; /** * Execute the callback everytime the label is triggered * check if the label had been already called * and if so excute the callback immediately with the same parameters for last callback * * @param label label of callback * @param callback callback function */ onReady<T extends CallableType>(label: string, callback: T): void; /** * * @param label label of callback * @param callback callback function * @param checkPast check if the label had been already called * and if so excute the callback immediately; default: `false` */ once<T extends CallableType>(label: string, callback: T, checkPast?: boolean): void; /** * Execute the callback onetime when the label is triggered * or execute the callback if the label had been called already * @param label Label of callback * @param callback Callback function */ onceReady<T extends CallableType>(label: string, callback: T): void; /** * Remove the callback for a label or for a single callback * @param label Label of callback * @param callback Callback function or boolean * @summary If callback is a function then only that functions is removed from callbacks; * Otherwise, all callbacks will be removed when callback parameter = `true` */ off<T extends CallableType>(label: string, callback?: boolean | T): void; /** * Remove all event listeners * @param label label of callback(s) */ removeAllEventListeners(label: string): void; /** * Trigger the event with the label * @param label Label of callback * @param args arggs to pass to callback * @returns `true` if a callback was called; Otherwise, `false` */ trigger(label: string, ...args: any[]): boolean; } export {};