- Updated import paths for types and utilities in config-service, menu-service, script-execution-service, script-store-service, and window-service to reflect new structure. - Moved utility functions like debounce and cloneDeep to shared utilities. - Created new runtime and script types files to centralize type definitions. - Removed deprecated task-types and locale messages files. - Updated constants to use shared definitions and added new placeholders for providers. - Enhanced provider type information with additional placeholders for different languages.
34 lines
766 B
TypeScript
34 lines
766 B
TypeScript
export function debounce<T extends (...args: any[]) => any>(
|
|
fn: T,
|
|
delay: number,
|
|
): (...args: Parameters<T>) => void {
|
|
let timer: NodeJS.Timeout | null = null;
|
|
|
|
return function debounced(this: unknown, ...args: Parameters<T>) {
|
|
if (timer) {
|
|
clearTimeout(timer);
|
|
}
|
|
timer = setTimeout(() => {
|
|
fn.apply(this, args);
|
|
}, delay);
|
|
};
|
|
}
|
|
|
|
export function cloneDeep<T>(obj: T): T {
|
|
if (obj === null || typeof obj !== 'object') {
|
|
return obj;
|
|
}
|
|
|
|
if (Array.isArray(obj)) {
|
|
return obj.map((item) => cloneDeep(item)) as T;
|
|
}
|
|
|
|
const clone = Object.assign({}, obj);
|
|
for (const key in clone) {
|
|
if (Object.prototype.hasOwnProperty.call(clone, key)) {
|
|
clone[key] = cloneDeep(clone[key]);
|
|
}
|
|
}
|
|
return clone;
|
|
}
|