@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.
59 lines • 1.91 kB
JavaScript
/**
* Global configuration options for the lazy loading system.
* Default values:
* - gcThreshold: 300000 (5 minutes)
* - gcInterval: 60000 (1 minute)
*/
export const lazyOptions = {
gcThreshold: 300000, // 5 minutes in milliseconds
gcInterval: 60000, // 1 minute in milliseconds
};
/**
* Global cache for storing imported modules and their metadata.
* The key is the module name and the value contains:
* - module: The actual module function/class
* - lastUsed: Counter for tracking module usage
* - collect: Whether the module can be garbage collected
*/
export const moduleCache = new Map();
/**
* Set of callbacks to be called when configuration changes.
* @private
*/
const configChangeListeners = new Set();
/**
* Registers a callback to be called when lazy loading configuration changes.
*
* @param {ConfigChangeCallback} callback - Function to be called with new options
*/
export function addConfigChangeListener(callback) {
configChangeListeners.add(callback);
}
/**
* Removes a previously registered configuration change callback.
*
* @param {ConfigChangeCallback} callback - The callback to remove
*/
export function removeConfigChangeListener(callback) {
configChangeListeners.delete(callback);
}
/**
* Updates the lazy loading configuration options.
* Undefined values are removed from the update to preserve existing values.
* Triggers all registered configuration change listeners.
*
* @param {Partial<TLazyOptions>} options - Partial configuration object
*/
export function setLazyOptions(options) {
for (const key of Object.keys(options)) {
const typedKey = key;
if (options[typedKey] === undefined) {
delete options[typedKey];
}
}
Object.assign(lazyOptions, options);
for (const listener of configChangeListeners) {
listener(lazyOptions);
}
}
//# sourceMappingURL=configuration.js.map