/** * Batch Update Scheduler * * Batches multiple state updates into a single DOM update cycle. * * This prevents: * - Multiple re-renders when setting multiple properties * - Layout thrashing from interleaved reads/writes * - Unnecessary work when the same property is updated multiple times * * @example * // Without batching: 3 re-renders * state.count = 1; * state.name = "hello"; * state.items.push(newItem); * * // With batching: 1 re-render * batch(() => { * state.count = 1; * state.name = "hello"; * state.items.push(newItem); * }); */ type FlushCallback = () => void; type SchedulerJob = FlushCallback & { id?: number; pre?: boolean; active?: boolean; }; /** * Schedules a job to run in the next microtask. * Jobs are deduplicated by id - if the same job is queued multiple times, * it only runs once. * * @param job - The update function to schedule * @returns The job id for tracking */ export declare function queueJob(job: SchedulerJob): number; /** * Creates a scheduler job with a stable id for deduplication. * Use this to ensure the same logical update only runs once per flush. * * @param fn - The update function * @param id - Optional stable id (uses auto-increment if not provided) * @returns A scheduler job with an id */ export declare function createSchedulerJob(fn: FlushCallback, id?: number): SchedulerJob; /** * Wait for the current flush to complete. * * @returns Promise that resolves after the current flush * * @example * state.count = 1; * await nextTick(); * // DOM is now updated * console.log(element.textContent); */ export declare function nextTick(): Promise; /** * Execute multiple state updates in a single batch. * All updates within the callback are deferred and * applied together in one DOM update cycle. * * @param fn - Function containing multiple state updates * * @example * batch(() => { * state.firstName = "John"; * state.lastName = "Doe"; * state.age = 30; * }); * // Only one DOM update occurs */ export declare function batch(fn: () => void): void; /** * Force an immediate synchronous flush of all pending updates. * Use sparingly - async batching is usually preferred. */ export declare function flushSync(): void; /** * Schedules a component update with automatic deduplication. * Multiple calls for the same component in the same tick * result in only one update. * * @param componentId - Unique component identifier * @param updateFn - The component's update function */ export declare function scheduleComponentUpdate(componentId: string, updateFn: () => void): void; /** * Removes a component from the scheduler registry. * Call this in disconnectedCallback to prevent memory leaks. * * @param componentId - The component ID to unregister */ export declare function unregisterComponent(componentId: string): void; export {};