UNPKG

corehook-utility

Version:

This is a slicing programming tool class based on front-end objects or functions

90 lines (89 loc) 3.55 kB
/** * CoreHook is an advanced proxy utility for adding hooks before/after object operations and function calls * Features: Intercept property access (get), property setting (set), property deletion (delete), and function invocation (apply) */ export declare class CoreHook { private static hooks; private static proxyToTarget; /** * Register hooks for property access (get) operations * @param target Target object * @param callbackList Array of callback functions * @param before Whether to trigger before operation (default: true) * @returns Proxy object */ static registerGetHook<T extends object>(target: T, callbackList: Array<(target: T, key: string | symbol) => void>, before?: boolean): T; /** * Register hooks for property setting (set) operations * @param target Target object * @param callbackList Array of callback functions * @param before Whether to trigger before operation (default: true) * @returns Proxy object */ static registerSetHook<T extends object>(target: T, callbackList: Array<(target: T, key: string | symbol, value: any) => void>, before?: boolean): T; /** * Register hooks for property deletion (delete) operations * @param target Target object * @param callbackList Array of callback functions * @param before Whether to trigger before operation (default: true) * @returns Proxy object */ static registerDeleteHook<T extends object>(target: T, callbackList: Array<(target: T, key: string | symbol) => void>, before?: boolean): T; /** * Register hooks for function invocation (apply) operations * @param target Target function * @param callbackList Array of callback functions * @param before Whether to trigger before operation (default: true) * @returns Proxy function */ static registerApplyHook<T extends Function>(target: T, callbackList: Array<(target: T, thisArg: any, args: any[]) => void>, before?: boolean): T; /** * Save hooks to storage * @param target Target object or function * @param callbacks Array of callback functions * @param type Hook type identifier */ private static saveHooks; /** * Trigger hook notifications * @param target Target object or function * @param type Hook type identifier * @param args Arguments for callback functions */ private static notifyHooks; /** * Create proxy wrapper * @param target Target object or function * @param handler Proxy handler configuration * @returns Proxy instance */ private static createProxy; /** * Get original target (unwraps proxies) * @param target Potential proxy object * @returns Original target object */ private static getRawTarget; /** * Validate target type * @param target Target to validate * @param expectedType Expected type ('object' or 'function') */ private static validateTarget; /** * Validate callback list * @param callbackList Callbacks to validate */ private static validateCallbacks; /** * Clear all hooks for a target * @param target Target object or function */ static clearTargetHooks(target: object | Function): void; /** * Get all hooks for a target * @param target Target object or function * @returns Map of hook types and their callbacks */ static getTargetHooks(target: object | Function): Map<string, Function[]> | undefined; }