UNPKG

@zubridge/electron

Version:

A streamlined state management library for Electron applications using Zustand.

70 lines (69 loc) 2.17 kB
import { AnyState, Handlers } from "@zubridge/types"; //#region src/batching/types.d.ts interface BatchingConfig { windowMs: number; maxBatchSize: number; priorityFlushThreshold: number; /** Timeout (ms) for waiting on batch/dispatch acknowledgments from the main process. */ ackTimeoutMs: number; } interface BatchStats { totalBatches: number; totalActions: number; averageBatchSize: number; currentQueueSize: number; isFlushing: boolean; rejectedActions: number; queueLimit: number; } //#endregion //#region src/types/thunkProcessor.d.ts interface ThunkProcessorOptions { /** * Maximum number of pending actions allowed in the queue (default: 100) * When this limit is exceeded, new actions will throw a QueueOverflowError */ maxQueueSize?: number; /** * Timeout for action completion in milliseconds * Platform-specific defaults: Linux=60000ms, others=30000ms */ actionCompletionTimeoutMs?: number; } //#endregion //#region src/types/preload.d.ts /** * Configuration options for preload bridge * * @example * ```typescript * // Configure with custom queue size and timeout * const options: PreloadOptions = { * maxQueueSize: 50, // Allow up to 50 pending actions * actionCompletionTimeoutMs: 15000 // 15 second timeout * }; * * // Use in preload * const bridge = preloadBridge<MyState>(options); * ``` */ interface PreloadOptions extends ThunkProcessorOptions { enableBatching?: boolean; batching?: Partial<BatchingConfig>; } //#endregion //#region src/preload.d.ts interface PreloadZustandBridgeReturn<S extends AnyState> { handlers: Handlers<S>; initialized: boolean; /** Returns current batch stats, or null if batching is disabled. */ getBatchStats: () => BatchStats | null; } /** * Creates and returns handlers that the window.zubridge object will expose * This uses the Electron IPC bridge to communicate with the main process */ declare const preloadBridge: <S extends AnyState>(options?: PreloadOptions) => PreloadZustandBridgeReturn<S>; type PreloadBridge = typeof preloadBridge; //#endregion export { PreloadBridge, PreloadZustandBridgeReturn, preloadBridge };