/** * Hooks infrastructure for intercepting store operations. * * This module provides a pure hooks system. Effect tracking and * selector tracking are implemented by consumers via withHooks(). */ /** * Hook event for property read. */ export interface ReadEvent { /** Unique key for this dependency (storeId.prop) */ key: string; /** Value read */ value: unknown; /** Subscribe to changes - returns cleanup function */ subscribe: (listener: VoidFunction) => VoidFunction; } /** * Hook event for property write. */ export interface WriteEvent { /** Unique key for this property (storeId.prop) */ key: string; /** New value */ next: unknown; /** Previous value */ prev: unknown; } /** * Hooks for intercepting store operations. * Useful for devtools, logging, debugging, and dependency tracking. */ export interface Hooks { /** Called when a store property is read */ onRead?: (event: ReadEvent) => void; /** Called when a store property is written */ onWrite?: (event: WriteEvent) => void; scheduleNotification: (notify: () => void, key?: unknown) => void; /** * Schedule a function to run an effect. * @param runEffect - Function to run effect and return dispose effect function */ scheduleEffect(runEffect: (options?: import('./effect').RunEffectOptions) => VoidFunction): void; } /** * Get current hooks. */ export declare function getHooks(): Hooks; /** * Check if onRead hook is active. * Used by proxies to skip trackRead overhead when not needed. */ export declare function hasReadHook(): boolean; /** * Check if onWrite hook is active. * Used by proxies to skip trackWrite overhead when not needed. */ export declare function hasWriteHook(): boolean; /** * Execute function with modified hooks (scoped). * * Hooks are restored after function completes, even if it throws. * * @overload Partial merge + scoped execution * @param hooks - Partial hooks to merge with current * @param fn - Function to execute with modified hooks * * @overload Setup function + scoped execution * @param setup - Function that receives current hooks and returns new hooks * @param fn - Function to execute with modified hooks * * @example * // Partial merge * withHooks({ onRead: myHandler }, () => { * // globalHooks.onRead is myHandler here * }); * // globalHooks restored * * @example * // Setup function - compose with existing hooks * withHooks((current) => ({ * onRead: (event) => { * current.onRead?.(event); // Call existing hook (devtools) * trackDependency(event); // Add your tracking * } * }), () => { * // Both hooks active * }); */ export declare function withHooks(hooks: Partial, fn: () => T, onFinish?: () => void): T; export declare function withHooks(setup: (current: Hooks) => Partial, fn: () => T, onFinish?: () => void): T; /** Subscribe function type for trackRead */ export type SubscribeFn = (listener: VoidFunction) => VoidFunction; /** * Track a property read. * Called by state proxies when a property is accessed. * * @param storeId - Store instance ID * @param prop - Property name * @param value - Value read * @param subscribe - Function to subscribe to changes for this property */ export declare function trackRead(storeId: string, prop: string, value: unknown, subscribe: SubscribeFn): void; /** * Track a property write. * Called by state proxies when a property is set. */ export declare function trackWrite(storeId: string, prop: string, next: unknown, prev: unknown): void; /** * Execute function without triggering hooks. * * Use this to read state without creating dependencies. * * @example * effect((ctx) => { * const tracked = state.count; // Creates dependency * const ignored = untrack(() => state.name); // No dependency * }); */ export declare function untrack(fn: () => T): T; /** * Schedule a notification via current hooks. * * By default, notifications are called immediately. * Inside batch(), notifications are collected and deduped by key. * * @param notify - The notification function to schedule * @param key - Optional key for deduplication (defaults to notify function itself) */ export declare function scheduleNotification(notify: () => void, key?: unknown): void; /** * Batch multiple operations. * * Notifications scheduled during batch are collected, deduped by key, * and flushed after batch completes. * * @example * batch(() => { * state.a = 1; * state.b = 2; * state.c = 3; * // Only one notification per subscriber, not three * }); */ export declare function batch(fn: () => T): T; //# sourceMappingURL=tracking.d.ts.map