diff --git a/packages/core/utils/utils-common.ts b/packages/core/utils/utils-common.ts index ae78b2335..f67ebbb2d 100644 --- a/packages/core/utils/utils-common.ts +++ b/packages/core/utils/utils-common.ts @@ -155,10 +155,35 @@ export function throttle(fn: any, delay = 300) { }; } +let throttledGC: Map void>; +let debouncedGC: Map void>; + export function queueGC(delay = 900, useThrottle?: boolean) { + /** + * developers can use different queueGC settings to optimize their own apps + * each setting is stored in a Map to reuse each time app calls it + */ if (useThrottle) { - throttle(() => GC(), delay); + if (!throttledGC) { + throttledGC = new Map(); + } + if (!throttledGC.get(delay)) { + throttledGC.set( + delay, + throttle(() => GC(), delay) + ); + } + throttledGC.get(delay)(); } else { - debounce(() => GC(), delay); + if (!debouncedGC) { + debouncedGC = new Map(); + } + if (!debouncedGC.get(delay)) { + debouncedGC.set( + delay, + debounce(() => GC(), delay) + ); + } + debouncedGC.get(delay)(); } }