type HookallCallbackParams any> = T extends (initialValue: any, ...params: infer R) => any ? R : never; type HookallLifeCycle = K; type DefaultListener = { [k: string]: (...args: any) => Promise; }; type ListenerSignature = { [K in keyof M]: (...args: any) => Promise; }; type HookallOnCallback, K extends keyof M> = (initialValue: Awaited>, ...params: HookallCallbackParams) => Promise>>; type HookallTriggerCallback, K extends keyof M> = (initialValue: Parameters[0], ...params: HookallCallbackParams) => Promise>>; type HookallCallbackWrapper, K extends keyof M> = { callback: HookallOnCallback; command: HookallLifeCycle<(keyof M) & string>; repeat: number; }; type HookallCallbackMap, K extends keyof M> = Map[]>; export interface IHookall = DefaultListener> { onBefore(command: HookallLifeCycle, callback: HookallOnCallback): this; onAfter(command: HookallLifeCycle, callback: HookallOnCallback): this; onceBefore(command: HookallLifeCycle, callback: HookallOnCallback): this; onceAfter(command: HookallLifeCycle, callback: HookallOnCallback): this; offBefore(command: HookallLifeCycle, callback?: HookallOnCallback): this; offAfter(command: HookallLifeCycle, callback?: HookallOnCallback): this; trigger(command: K & string, initialValue: Awaited>, callback: HookallTriggerCallback, ...params: HookallCallbackParams): Promise>>; } declare class Hookall> implements IHookall { static readonly Global: {}; private static readonly _Store; protected readonly beforeHooks: HookallCallbackMap; protected readonly afterHooks: HookallCallbackMap; /** * Create hook system. you can pass a target object or undefined. * If you pass a object, the hook system will be work for object locally. You're going to want this kind of usage in general. * If not specified, will be work for global. This is useful when you want to share your work with multiple files. * @param target The object to work with locally. If not specified, will be work for global. */ constructor(target: object); private _ensureCommand; private _createWrapper; private _on; /** * You register a preprocessing function, which is called before the callback function of the `trigger` method. * The value returned by this function is passed as a parameter to the `trigger` method's callback function. * If you register multiple preprocessing functions, they are executed in order, with each function receiving the value returned by the previous one as a parameter. * @param command Command to work. * @param callback Preprocessing function to register. */ onBefore(command: HookallLifeCycle, callback: HookallOnCallback): this; /** * Similar to the `onBefore` method, but it only runs once. * For more details, please refer to the `onBefore` method. * @param command Command to work. * @param callback Preprocessing function to register. */ onceBefore(command: HookallLifeCycle, callback: HookallOnCallback): this; /** * You register a post-processing function which is called after the callback function of the `trigger` method finishes. * This function receives the value returned by the `trigger` method's callback function as a parameter. * If you register multiple post-processing functions, they are executed in order, with each function receiving the value returned by the previous one as a parameter. * @param command Command to work. * @param callback Post-preprocessing function to register. */ onAfter(command: HookallLifeCycle, callback: HookallOnCallback): this; /** * Similar to the `onAfter` method, but it only runs once. * For more details, please refer to the `onAfter` method. * @param command Command to work. * @param callback Post-preprocessing function to register. */ onceAfter(command: HookallLifeCycle, callback: HookallOnCallback): this; private _off; /** * You remove the preprocessing functions registered with `onBefore` or `onceBefore` methods. * If you don't specify a callback parameter, it removes all preprocessing functions registered for that command. * @param command Commands with preprocessing functions to be deleted. * @param callback Preprocessing function to be deleted. */ offBefore(command: HookallLifeCycle, callback?: HookallOnCallback): this; /** * You remove the post-preprocessing functions registered with `onAfter` or `onceAfter` methods. * If you don't specify a callback parameter, it removes all post-preprocessing functions registered for that command. * @param command Commands with post-preprocessing functions to be deleted. * @param callback post-Preprocessing function to be deleted. */ offAfter(command: HookallLifeCycle, callback?: HookallOnCallback): this; private _hookWith; /** * You execute the callback function provided as a parameter. This callback function receives the 'initialValue' parameter. * * If preprocessing functions are registered, they run first, and the value returned by the preprocessing functions becomes the 'initialValue' parameter. * After the callback function finishes, post-processing functions are called. * These post-processing functions receive the value returned by the callback function as a parameter and run sequentially. * * The final value returned becomes the result of the `trigger` method. * @param command Command to work. * @param initialValue Initial value to be passed to the callback function. * @param callback The callback function to be executed. */ trigger(command: HookallLifeCycle, initialValue: Awaited>, callback: HookallTriggerCallback, ...params: HookallCallbackParams): Promise>>; } /** * Create hook system. you can pass a target object or undefined. * If you pass a object, the hook system will be work for object locally. You're going to want this kind of usage in general. * If not specified, will be work for global. This is useful when you want to share your work with multiple files. * @param target The object to work with locally. If not specified, will be work for global. Default is `Hookall.Global`. */ export declare function useHookall = DefaultListener>(target?: object): Hookall; export {};