@jay-js/system
Version:
A powerful and flexible TypeScript library for UI, state management, lazy loading, routing and managing draggable elements in modern web applications.
76 lines (75 loc) • 2.15 kB
TypeScript
/**
* Singleton class responsible for managing the lifecycle of lazy-loaded modules.
* Implements garbage collection and idle detection to optimize memory usage.
*
* Features:
* - Automatic garbage collection of unused modules
* - Idle detection to pause collection when app is inactive
* - Dynamic configuration through lazyOptions
*/
declare class ModuleCollector {
private static instance;
private collectorInterval;
private idleTime;
private idleOptions;
private constructor();
/**
* Returns the singleton instance of ModuleCollector.
* Creates a new instance if one doesn't exist.
*
* @returns {ModuleCollector} The singleton collector instance
*/
static getInstance(): ModuleCollector;
/**
* Handles changes in lazy loading configuration.
* Restarts the collector with new settings if running.
*
* @param {TLazyOptions} options - New configuration options
* @private
*/
private handleConfigChange;
/**
* Sets up event listeners for mousemove and keypress events
* to detect user activity.
*
* @private
*/
private setupEventListeners;
/**
* Resets the idle timer and restarts collection if stopped.
* Called when user activity is detected.
*
* @private
*/
private resetIdle;
/**
* Starts the garbage collection interval.
* Uses gcInterval from lazyOptions for timing.
*
* @private
*/
private startCollector;
/**
* Runs a garbage collection cycle.
* - Increments usage counters for all modules
* - Removes modules that exceed gcThreshold
* - Manages collection pausing during idle periods
*
* @private
*/
private runCollector;
/**
* Sets up the idle monitoring interval.
* Resets module usage counters during extended idle periods.
*
* @private
*/
private setupIdleMonitor;
/**
* Disposes of the collector instance.
* Cleans up event listeners and intervals.
*/
dispose(): void;
}
export declare const moduleCollector: ModuleCollector;
export {};