MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / debounce

Function debounce

packages/core/utils/shared.ts:9–21  ·  view source on GitHub ↗
(fn: any, delay = 300, { leading }: { leading?: boolean } = {})

Source from the content-addressed store, hash-verified

7 * @returns A new debounced function
8 */
9export function debounce(fn: any, delay = 300, { leading }: { leading?: boolean } = {}) {
10 let timer: NodeJS.Timeout;
11 return (...args: Array<any>) => {
12 if (timer === undefined && leading) {
13 fn.apply(this, args);
14 }
15 clearTimeout(timer);
16 timer = setTimeout(() => {
17 fn.apply(this, args);
18 timer = undefined;
19 }, delay);
20 };
21}
22
23/**
24 * Creates a throttled function that only invokes the provided function at most once per specified delay

Callers 2

queueGCFunction · 0.90
queueGCFunction · 0.90

Calls 3

clearTimeoutFunction · 0.50
setTimeoutFunction · 0.50
applyMethod · 0.45

Tested by

no test coverage detected