@tanstack/pacer 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/cjs/async-debouncer.cjs +109 -0
- package/dist/cjs/async-debouncer.cjs.map +1 -0
- package/dist/cjs/async-debouncer.d.cts +99 -0
- package/dist/cjs/async-queuer.cjs +293 -0
- package/dist/cjs/async-queuer.cjs.map +1 -0
- package/dist/cjs/async-queuer.d.cts +197 -0
- package/dist/cjs/async-rate-limiter.cjs +122 -0
- package/dist/cjs/async-rate-limiter.cjs.map +1 -0
- package/dist/cjs/async-rate-limiter.d.cts +132 -0
- package/dist/cjs/async-throttler.cjs +115 -0
- package/dist/cjs/async-throttler.cjs.map +1 -0
- package/dist/cjs/async-throttler.d.cts +93 -0
- package/dist/cjs/compare.cjs +72 -0
- package/dist/cjs/compare.cjs.map +1 -0
- package/dist/cjs/compare.d.cts +12 -0
- package/dist/cjs/debouncer.cjs +74 -0
- package/dist/cjs/debouncer.cjs.map +1 -0
- package/dist/cjs/debouncer.d.cts +96 -0
- package/dist/cjs/index.cjs +32 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +9 -0
- package/dist/cjs/queuer.cjs +231 -0
- package/dist/cjs/queuer.cjs.map +1 -0
- package/dist/cjs/queuer.d.cts +221 -0
- package/dist/cjs/rate-limiter.cjs +115 -0
- package/dist/cjs/rate-limiter.cjs.map +1 -0
- package/dist/cjs/rate-limiter.d.cts +147 -0
- package/dist/cjs/throttler.cjs +120 -0
- package/dist/cjs/throttler.cjs.map +1 -0
- package/dist/cjs/throttler.d.cts +139 -0
- package/dist/esm/async-debouncer.d.ts +99 -0
- package/dist/esm/async-debouncer.js +109 -0
- package/dist/esm/async-debouncer.js.map +1 -0
- package/dist/esm/async-queuer.d.ts +197 -0
- package/dist/esm/async-queuer.js +293 -0
- package/dist/esm/async-queuer.js.map +1 -0
- package/dist/esm/async-rate-limiter.d.ts +132 -0
- package/dist/esm/async-rate-limiter.js +122 -0
- package/dist/esm/async-rate-limiter.js.map +1 -0
- package/dist/esm/async-throttler.d.ts +93 -0
- package/dist/esm/async-throttler.js +115 -0
- package/dist/esm/async-throttler.js.map +1 -0
- package/dist/esm/compare.d.ts +12 -0
- package/dist/esm/compare.js +72 -0
- package/dist/esm/compare.js.map +1 -0
- package/dist/esm/debouncer.d.ts +96 -0
- package/dist/esm/debouncer.js +74 -0
- package/dist/esm/debouncer.js.map +1 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +32 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/queuer.d.ts +221 -0
- package/dist/esm/queuer.js +231 -0
- package/dist/esm/queuer.js.map +1 -0
- package/dist/esm/rate-limiter.d.ts +147 -0
- package/dist/esm/rate-limiter.js +115 -0
- package/dist/esm/rate-limiter.js.map +1 -0
- package/dist/esm/throttler.d.ts +139 -0
- package/dist/esm/throttler.js +120 -0
- package/dist/esm/throttler.js.map +1 -0
- package/package.json +150 -0
- package/src/async-debouncer.ts +197 -0
- package/src/async-queuer.ts +447 -0
- package/src/async-rate-limiter.ts +228 -0
- package/src/async-throttler.ts +194 -0
- package/src/compare.ts +105 -0
- package/src/debouncer.ts +164 -0
- package/src/index.ts +9 -0
- package/src/queuer.ts +394 -0
- package/src/rate-limiter.ts +236 -0
- package/src/throttler.ts +222 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for configuring an async throttled function
|
|
3
|
+
*/
|
|
4
|
+
export interface AsyncThrottlerOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Whether the throttler is enabled. When disabled, maybeExecute will not trigger any executions.
|
|
7
|
+
* Defaults to true.
|
|
8
|
+
*/
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Time window in milliseconds during which the function can only be executed once
|
|
12
|
+
* Defaults to 0ms
|
|
13
|
+
*/
|
|
14
|
+
wait: number;
|
|
15
|
+
/**
|
|
16
|
+
* Optional error handler for when the throttled function throws
|
|
17
|
+
*/
|
|
18
|
+
onError?: (error: unknown) => void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A class that creates an async throttled function.
|
|
22
|
+
*
|
|
23
|
+
* Throttling limits how often a function can be executed, allowing only one execution within a specified time window.
|
|
24
|
+
* Unlike debouncing which resets the delay timer on each call, throttling ensures the function executes at a
|
|
25
|
+
* regular interval regardless of how often it's called.
|
|
26
|
+
*
|
|
27
|
+
* This is useful for rate-limiting API calls, handling scroll/resize events, or any scenario where you want to
|
|
28
|
+
* ensure a maximum execution frequency.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const throttler = new AsyncThrottler(async (value: string) => {
|
|
33
|
+
* await saveToAPI(value);
|
|
34
|
+
* }, { wait: 1000 });
|
|
35
|
+
*
|
|
36
|
+
* // Will only execute once per second no matter how often called
|
|
37
|
+
* inputElement.addEventListener('input', () => {
|
|
38
|
+
* throttler.maybeExecute(inputElement.value);
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare class AsyncThrottler<TFn extends (...args: Array<any>) => Promise<any>, TArgs extends Parameters<TFn>> {
|
|
43
|
+
private fn;
|
|
44
|
+
private abortController;
|
|
45
|
+
private executionCount;
|
|
46
|
+
private isExecuting;
|
|
47
|
+
private isScheduled;
|
|
48
|
+
private lastArgs;
|
|
49
|
+
private nextExecutionTime;
|
|
50
|
+
private options;
|
|
51
|
+
constructor(fn: TFn, initialOptions: AsyncThrottlerOptions);
|
|
52
|
+
/**
|
|
53
|
+
* Updates the throttler options
|
|
54
|
+
* Returns the new options state
|
|
55
|
+
*/
|
|
56
|
+
setOptions(newOptions: Partial<AsyncThrottlerOptions>): Required<AsyncThrottlerOptions>;
|
|
57
|
+
/**
|
|
58
|
+
* Returns the number of times the function has been executed
|
|
59
|
+
*/
|
|
60
|
+
getExecutionCount(): number;
|
|
61
|
+
/**
|
|
62
|
+
* Returns the next execution time
|
|
63
|
+
*/
|
|
64
|
+
getNextExecutionTime(): number;
|
|
65
|
+
/**
|
|
66
|
+
* Cancels any pending execution
|
|
67
|
+
*/
|
|
68
|
+
cancel(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Attempts to execute the throttled function
|
|
71
|
+
* If a call is already in progress, it may be blocked or queued depending on the `wait` option
|
|
72
|
+
*/
|
|
73
|
+
maybeExecute(...args: TArgs): Promise<void>;
|
|
74
|
+
private delay;
|
|
75
|
+
private executeFunction;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Creates an async throttled function that limits how often the function can execute.
|
|
79
|
+
* The throttled function will execute at most once per wait period, even if called multiple times.
|
|
80
|
+
* If called while executing, it will wait until execution completes before scheduling the next call.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const throttled = asyncThrottle(async () => {
|
|
85
|
+
* await someAsyncOperation();
|
|
86
|
+
* }, { wait: 1000 });
|
|
87
|
+
*
|
|
88
|
+
* // This will execute at most once per second
|
|
89
|
+
* await throttled();
|
|
90
|
+
* await throttled(); // Waits 1 second before executing
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function asyncThrottle<TFn extends (...args: Array<any>) => Promise<any>>(fn: TFn, initialOptions: Omit<AsyncThrottlerOptions, 'enabled'>): (...args: Parameters<TFn>) => Promise<void>;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
const defaultOptions = {
|
|
2
|
+
enabled: true,
|
|
3
|
+
onError: () => {
|
|
4
|
+
},
|
|
5
|
+
wait: 0
|
|
6
|
+
};
|
|
7
|
+
class AsyncThrottler {
|
|
8
|
+
constructor(fn, initialOptions) {
|
|
9
|
+
this.fn = fn;
|
|
10
|
+
this.abortController = null;
|
|
11
|
+
this.executionCount = 0;
|
|
12
|
+
this.isExecuting = false;
|
|
13
|
+
this.isScheduled = false;
|
|
14
|
+
this.nextExecutionTime = 0;
|
|
15
|
+
this.options = {
|
|
16
|
+
...defaultOptions,
|
|
17
|
+
...initialOptions
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Updates the throttler options
|
|
22
|
+
* Returns the new options state
|
|
23
|
+
*/
|
|
24
|
+
setOptions(newOptions) {
|
|
25
|
+
this.options = {
|
|
26
|
+
...this.options,
|
|
27
|
+
...newOptions
|
|
28
|
+
};
|
|
29
|
+
return this.options;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Returns the number of times the function has been executed
|
|
33
|
+
*/
|
|
34
|
+
getExecutionCount() {
|
|
35
|
+
return this.executionCount;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Returns the next execution time
|
|
39
|
+
*/
|
|
40
|
+
getNextExecutionTime() {
|
|
41
|
+
return this.nextExecutionTime;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Cancels any pending execution
|
|
45
|
+
*/
|
|
46
|
+
cancel() {
|
|
47
|
+
if (this.abortController) {
|
|
48
|
+
this.abortController.abort();
|
|
49
|
+
this.abortController = null;
|
|
50
|
+
}
|
|
51
|
+
this.isScheduled = false;
|
|
52
|
+
this.lastArgs = void 0;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Attempts to execute the throttled function
|
|
56
|
+
* If a call is already in progress, it may be blocked or queued depending on the `wait` option
|
|
57
|
+
*/
|
|
58
|
+
async maybeExecute(...args) {
|
|
59
|
+
this.lastArgs = args;
|
|
60
|
+
if (this.isScheduled) return;
|
|
61
|
+
this.isScheduled = true;
|
|
62
|
+
this.abortController = new AbortController();
|
|
63
|
+
const signal = this.abortController.signal;
|
|
64
|
+
try {
|
|
65
|
+
while (this.isExecuting) {
|
|
66
|
+
await this.delay(this.options.wait, signal);
|
|
67
|
+
}
|
|
68
|
+
while (Date.now() < this.nextExecutionTime) {
|
|
69
|
+
await this.delay(this.nextExecutionTime - Date.now(), signal);
|
|
70
|
+
}
|
|
71
|
+
this.isScheduled = false;
|
|
72
|
+
this.isExecuting = true;
|
|
73
|
+
await this.executeFunction(...this.lastArgs);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
this.options.onError(error);
|
|
80
|
+
} catch {
|
|
81
|
+
}
|
|
82
|
+
} finally {
|
|
83
|
+
this.nextExecutionTime = Date.now() + this.options.wait;
|
|
84
|
+
this.isExecuting = false;
|
|
85
|
+
this.abortController = null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
delay(ms, signal) {
|
|
89
|
+
return new Promise((resolve, reject) => {
|
|
90
|
+
const timeout = setTimeout(resolve, ms);
|
|
91
|
+
signal.addEventListener(
|
|
92
|
+
"abort",
|
|
93
|
+
() => {
|
|
94
|
+
clearTimeout(timeout);
|
|
95
|
+
reject(new Error("AbortError"));
|
|
96
|
+
},
|
|
97
|
+
{ once: true }
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
async executeFunction(...args) {
|
|
102
|
+
if (!this.options.enabled) return;
|
|
103
|
+
this.executionCount++;
|
|
104
|
+
await this.fn(...args);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function asyncThrottle(fn, initialOptions) {
|
|
108
|
+
const asyncThrottler = new AsyncThrottler(fn, initialOptions);
|
|
109
|
+
return asyncThrottler.maybeExecute.bind(asyncThrottler);
|
|
110
|
+
}
|
|
111
|
+
export {
|
|
112
|
+
AsyncThrottler,
|
|
113
|
+
asyncThrottle
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=async-throttler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-throttler.js","sources":["../../src/async-throttler.ts"],"sourcesContent":["/**\n * Options for configuring an async throttled function\n */\nexport interface AsyncThrottlerOptions {\n /**\n * Whether the throttler is enabled. When disabled, maybeExecute will not trigger any executions.\n * Defaults to true.\n */\n enabled?: boolean\n /**\n * Time window in milliseconds during which the function can only be executed once\n * Defaults to 0ms\n */\n wait: number\n /**\n * Optional error handler for when the throttled function throws\n */\n onError?: (error: unknown) => void\n}\n\nconst defaultOptions: Required<AsyncThrottlerOptions> = {\n enabled: true,\n onError: () => {},\n wait: 0,\n}\n\n/**\n * A class that creates an async throttled function.\n *\n * Throttling limits how often a function can be executed, allowing only one execution within a specified time window.\n * Unlike debouncing which resets the delay timer on each call, throttling ensures the function executes at a\n * regular interval regardless of how often it's called.\n *\n * This is useful for rate-limiting API calls, handling scroll/resize events, or any scenario where you want to\n * ensure a maximum execution frequency.\n *\n * @example\n * ```ts\n * const throttler = new AsyncThrottler(async (value: string) => {\n * await saveToAPI(value);\n * }, { wait: 1000 });\n *\n * // Will only execute once per second no matter how often called\n * inputElement.addEventListener('input', () => {\n * throttler.maybeExecute(inputElement.value);\n * });\n * ```\n */\nexport class AsyncThrottler<\n TFn extends (...args: Array<any>) => Promise<any>,\n TArgs extends Parameters<TFn>,\n> {\n private abortController: AbortController | null = null\n private executionCount = 0\n private isExecuting = false\n private isScheduled = false\n private lastArgs: TArgs | undefined\n private nextExecutionTime = 0\n private options: Required<AsyncThrottlerOptions>\n\n constructor(\n private fn: TFn,\n initialOptions: AsyncThrottlerOptions,\n ) {\n this.options = {\n ...defaultOptions,\n ...initialOptions,\n }\n }\n\n /**\n * Updates the throttler options\n * Returns the new options state\n */\n setOptions(\n newOptions: Partial<AsyncThrottlerOptions>,\n ): Required<AsyncThrottlerOptions> {\n this.options = {\n ...this.options,\n ...newOptions,\n }\n return this.options\n }\n\n /**\n * Returns the number of times the function has been executed\n */\n getExecutionCount(): number {\n return this.executionCount\n }\n\n /**\n * Returns the next execution time\n */\n getNextExecutionTime(): number {\n return this.nextExecutionTime\n }\n\n /**\n * Cancels any pending execution\n */\n cancel(): void {\n if (this.abortController) {\n this.abortController.abort()\n this.abortController = null\n }\n this.isScheduled = false\n this.lastArgs = undefined\n }\n\n /**\n * Attempts to execute the throttled function\n * If a call is already in progress, it may be blocked or queued depending on the `wait` option\n */\n async maybeExecute(...args: TArgs): Promise<void> {\n this.lastArgs = args\n if (this.isScheduled) return\n this.isScheduled = true\n\n this.abortController = new AbortController()\n const signal = this.abortController.signal\n\n try {\n while (this.isExecuting) {\n await this.delay(this.options.wait, signal)\n }\n\n while (Date.now() < this.nextExecutionTime) {\n await this.delay(this.nextExecutionTime - Date.now(), signal)\n }\n\n this.isScheduled = false\n this.isExecuting = true\n\n await this.executeFunction(...this.lastArgs)\n } catch (error) {\n if (error instanceof Error && error.name === 'AbortError') {\n return // Silent return on cancellation\n }\n try {\n this.options.onError(error)\n } catch {\n // Ignore errors from error handler\n }\n } finally {\n this.nextExecutionTime = Date.now() + this.options.wait\n this.isExecuting = false\n this.abortController = null\n }\n }\n\n private delay(ms: number, signal: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(resolve, ms)\n signal.addEventListener(\n 'abort',\n () => {\n clearTimeout(timeout)\n reject(new Error('AbortError'))\n },\n { once: true },\n )\n })\n }\n\n private async executeFunction(...args: TArgs): Promise<void> {\n if (!this.options.enabled) return\n this.executionCount++\n await this.fn(...args)\n }\n}\n\n/**\n * Creates an async throttled function that limits how often the function can execute.\n * The throttled function will execute at most once per wait period, even if called multiple times.\n * If called while executing, it will wait until execution completes before scheduling the next call.\n *\n * @example\n * ```ts\n * const throttled = asyncThrottle(async () => {\n * await someAsyncOperation();\n * }, { wait: 1000 });\n *\n * // This will execute at most once per second\n * await throttled();\n * await throttled(); // Waits 1 second before executing\n * ```\n */\nexport function asyncThrottle<\n TFn extends (...args: Array<any>) => Promise<any>,\n>(fn: TFn, initialOptions: Omit<AsyncThrottlerOptions, 'enabled'>) {\n const asyncThrottler = new AsyncThrottler(fn, initialOptions)\n return asyncThrottler.maybeExecute.bind(asyncThrottler)\n}\n"],"names":[],"mappings":"AAoBA,MAAM,iBAAkD;AAAA,EACtD,SAAS;AAAA,EACT,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,MAAM;AACR;AAwBO,MAAM,eAGX;AAAA,EASA,YACU,IACR,gBACA;AAFQ,SAAA,KAAA;AATV,SAAQ,kBAA0C;AAClD,SAAQ,iBAAiB;AACzB,SAAQ,cAAc;AACtB,SAAQ,cAAc;AAEtB,SAAQ,oBAAoB;AAO1B,SAAK,UAAU;AAAA,MACb,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOF,WACE,YACiC;AACjC,SAAK,UAAU;AAAA,MACb,GAAG,KAAK;AAAA,MACR,GAAG;AAAA,IACL;AACA,WAAO,KAAK;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,EAMd,oBAA4B;AAC1B,WAAO,KAAK;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,EAMd,uBAA+B;AAC7B,WAAO,KAAK;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,EAMd,SAAe;AACb,QAAI,KAAK,iBAAiB;AACxB,WAAK,gBAAgB,MAAM;AAC3B,WAAK,kBAAkB;AAAA,IAAA;AAEzB,SAAK,cAAc;AACnB,SAAK,WAAW;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOlB,MAAM,gBAAgB,MAA4B;AAChD,SAAK,WAAW;AAChB,QAAI,KAAK,YAAa;AACtB,SAAK,cAAc;AAEd,SAAA,kBAAkB,IAAI,gBAAgB;AACrC,UAAA,SAAS,KAAK,gBAAgB;AAEhC,QAAA;AACF,aAAO,KAAK,aAAa;AACvB,cAAM,KAAK,MAAM,KAAK,QAAQ,MAAM,MAAM;AAAA,MAAA;AAG5C,aAAO,KAAK,QAAQ,KAAK,mBAAmB;AAC1C,cAAM,KAAK,MAAM,KAAK,oBAAoB,KAAK,OAAO,MAAM;AAAA,MAAA;AAG9D,WAAK,cAAc;AACnB,WAAK,cAAc;AAEnB,YAAM,KAAK,gBAAgB,GAAG,KAAK,QAAQ;AAAA,aACpC,OAAO;AACd,UAAI,iBAAiB,SAAS,MAAM,SAAS,cAAc;AACzD;AAAA,MAAA;AAEE,UAAA;AACG,aAAA,QAAQ,QAAQ,KAAK;AAAA,MAAA,QACpB;AAAA,MAAA;AAAA,IAER,UACA;AACA,WAAK,oBAAoB,KAAK,IAAI,IAAI,KAAK,QAAQ;AACnD,WAAK,cAAc;AACnB,WAAK,kBAAkB;AAAA,IAAA;AAAA,EACzB;AAAA,EAGM,MAAM,IAAY,QAAoC;AAC5D,WAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AAChC,YAAA,UAAU,WAAW,SAAS,EAAE;AAC/B,aAAA;AAAA,QACL;AAAA,QACA,MAAM;AACJ,uBAAa,OAAO;AACb,iBAAA,IAAI,MAAM,YAAY,CAAC;AAAA,QAChC;AAAA,QACA,EAAE,MAAM,KAAK;AAAA,MACf;AAAA,IAAA,CACD;AAAA,EAAA;AAAA,EAGH,MAAc,mBAAmB,MAA4B;AACvD,QAAA,CAAC,KAAK,QAAQ,QAAS;AACtB,SAAA;AACC,UAAA,KAAK,GAAG,GAAG,IAAI;AAAA,EAAA;AAEzB;AAkBgB,SAAA,cAEd,IAAS,gBAAwD;AACjE,QAAM,iBAAiB,IAAI,eAAe,IAAI,cAAc;AACrD,SAAA,eAAe,aAAa,KAAK,cAAc;AACxD;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function returns `a` if `b` is deeply equal.
|
|
3
|
+
* If not, it will replace any deeply equal children of `b` with those of `a`.
|
|
4
|
+
* This can be used for structural sharing between JSON values for example.
|
|
5
|
+
*/
|
|
6
|
+
export declare function replaceEqualDeep<T>(a: unknown, b: T): T;
|
|
7
|
+
/**
|
|
8
|
+
* Shallow compare objects.
|
|
9
|
+
*/
|
|
10
|
+
export declare function shallowEqualObjects<T extends Record<string, any>>(a: T, b: T | undefined): boolean;
|
|
11
|
+
export declare function isPlainArray(value: unknown): boolean;
|
|
12
|
+
export declare function isPlainObject(o: any): o is Object;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
function replaceEqualDeep(a, b) {
|
|
2
|
+
if (a === b) {
|
|
3
|
+
return a;
|
|
4
|
+
}
|
|
5
|
+
const array = isPlainArray(a) && isPlainArray(b);
|
|
6
|
+
if (array || isPlainObject(a) && isPlainObject(b)) {
|
|
7
|
+
const aItems = array ? a : Object.keys(a);
|
|
8
|
+
const aSize = aItems.length;
|
|
9
|
+
const bItems = array ? b : Object.keys(b);
|
|
10
|
+
const bSize = bItems.length;
|
|
11
|
+
const copy = array ? [] : {};
|
|
12
|
+
let equalItems = 0;
|
|
13
|
+
for (let i = 0; i < bSize; i++) {
|
|
14
|
+
const key = array ? i : bItems[i];
|
|
15
|
+
if ((!array && aItems.includes(key) || array) && a[key] === void 0 && b[key] === void 0) {
|
|
16
|
+
copy[key] = void 0;
|
|
17
|
+
equalItems++;
|
|
18
|
+
} else {
|
|
19
|
+
copy[key] = replaceEqualDeep(a[key], b[key]);
|
|
20
|
+
if (copy[key] === a[key] && a[key] !== void 0) {
|
|
21
|
+
equalItems++;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return aSize === bSize && equalItems === aSize ? a : copy;
|
|
26
|
+
}
|
|
27
|
+
return b;
|
|
28
|
+
}
|
|
29
|
+
function shallowEqualObjects(a, b) {
|
|
30
|
+
if (!b || Object.keys(a).length !== Object.keys(b).length) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
for (const key in a) {
|
|
34
|
+
if (a[key] !== b[key]) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
function isPlainArray(value) {
|
|
41
|
+
return Array.isArray(value) && value.length === Object.keys(value).length;
|
|
42
|
+
}
|
|
43
|
+
function isPlainObject(o) {
|
|
44
|
+
if (!hasObjectPrototype(o)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
const ctor = o.constructor;
|
|
48
|
+
if (ctor === void 0) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
const prot = ctor.prototype;
|
|
52
|
+
if (!hasObjectPrototype(prot)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
if (!prot.hasOwnProperty("isPrototypeOf")) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (Object.getPrototypeOf(o) !== Object.prototype) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
function hasObjectPrototype(o) {
|
|
64
|
+
return Object.prototype.toString.call(o) === "[object Object]";
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
isPlainArray,
|
|
68
|
+
isPlainObject,
|
|
69
|
+
replaceEqualDeep,
|
|
70
|
+
shallowEqualObjects
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=compare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.js","sources":["../../src/compare.ts"],"sourcesContent":["/**\n * This function returns `a` if `b` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between JSON values for example.\n */\nexport function replaceEqualDeep<T>(a: unknown, b: T): T\nexport function replaceEqualDeep(a: any, b: any): any {\n if (a === b) {\n return a\n }\n\n const array = isPlainArray(a) && isPlainArray(b)\n\n if (array || (isPlainObject(a) && isPlainObject(b))) {\n const aItems = array ? a : Object.keys(a)\n const aSize = aItems.length\n const bItems = array ? b : Object.keys(b)\n const bSize = bItems.length\n const copy: any = array ? [] : {}\n\n let equalItems = 0\n\n for (let i = 0; i < bSize; i++) {\n const key = array ? i : bItems[i]\n if (\n ((!array && aItems.includes(key)) || array) &&\n a[key] === undefined &&\n b[key] === undefined\n ) {\n copy[key] = undefined\n equalItems++\n } else {\n copy[key] = replaceEqualDeep(a[key], b[key])\n if (copy[key] === a[key] && a[key] !== undefined) {\n equalItems++\n }\n }\n }\n\n return aSize === bSize && equalItems === aSize ? a : copy\n }\n\n return b\n}\n\n/**\n * Shallow compare objects.\n */\nexport function shallowEqualObjects<T extends Record<string, any>>(\n a: T,\n b: T | undefined,\n): boolean {\n if (!b || Object.keys(a).length !== Object.keys(b).length) {\n return false\n }\n\n for (const key in a) {\n if (a[key] !== b[key]) {\n return false\n }\n }\n\n return true\n}\n\nexport function isPlainArray(value: unknown) {\n return Array.isArray(value) && value.length === Object.keys(value).length\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\n// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\nexport function isPlainObject(o: any): o is Object {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has no constructor\n const ctor = o.constructor\n if (ctor === undefined) {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Handles Objects created by Object.create(<arbitrary prototype>)\n if (Object.getPrototypeOf(o) !== Object.prototype) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any): boolean {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n"],"names":[],"mappings":"AAMgB,SAAA,iBAAiB,GAAQ,GAAa;AACpD,MAAI,MAAM,GAAG;AACJ,WAAA;AAAA,EAAA;AAGT,QAAM,QAAQ,aAAa,CAAC,KAAK,aAAa,CAAC;AAE/C,MAAI,SAAU,cAAc,CAAC,KAAK,cAAc,CAAC,GAAI;AACnD,UAAM,SAAS,QAAQ,IAAI,OAAO,KAAK,CAAC;AACxC,UAAM,QAAQ,OAAO;AACrB,UAAM,SAAS,QAAQ,IAAI,OAAO,KAAK,CAAC;AACxC,UAAM,QAAQ,OAAO;AACrB,UAAM,OAAY,QAAQ,CAAA,IAAK,CAAC;AAEhC,QAAI,aAAa;AAEjB,aAAS,IAAI,GAAG,IAAI,OAAO,KAAK;AAC9B,YAAM,MAAM,QAAQ,IAAI,OAAO,CAAC;AAChC,WACI,CAAC,SAAS,OAAO,SAAS,GAAG,KAAM,UACrC,EAAE,GAAG,MAAM,UACX,EAAE,GAAG,MAAM,QACX;AACA,aAAK,GAAG,IAAI;AACZ;AAAA,MAAA,OACK;AACA,aAAA,GAAG,IAAI,iBAAiB,EAAE,GAAG,GAAG,EAAE,GAAG,CAAC;AACvC,YAAA,KAAK,GAAG,MAAM,EAAE,GAAG,KAAK,EAAE,GAAG,MAAM,QAAW;AAChD;AAAA,QAAA;AAAA,MACF;AAAA,IACF;AAGF,WAAO,UAAU,SAAS,eAAe,QAAQ,IAAI;AAAA,EAAA;AAGhD,SAAA;AACT;AAKgB,SAAA,oBACd,GACA,GACS;AACL,MAAA,CAAC,KAAK,OAAO,KAAK,CAAC,EAAE,WAAW,OAAO,KAAK,CAAC,EAAE,QAAQ;AAClD,WAAA;AAAA,EAAA;AAGT,aAAW,OAAO,GAAG;AACnB,QAAI,EAAE,GAAG,MAAM,EAAE,GAAG,GAAG;AACd,aAAA;AAAA,IAAA;AAAA,EACT;AAGK,SAAA;AACT;AAEO,SAAS,aAAa,OAAgB;AACpC,SAAA,MAAM,QAAQ,KAAK,KAAK,MAAM,WAAW,OAAO,KAAK,KAAK,EAAE;AACrE;AAIO,SAAS,cAAc,GAAqB;AAC7C,MAAA,CAAC,mBAAmB,CAAC,GAAG;AACnB,WAAA;AAAA,EAAA;AAIT,QAAM,OAAO,EAAE;AACf,MAAI,SAAS,QAAW;AACf,WAAA;AAAA,EAAA;AAIT,QAAM,OAAO,KAAK;AACd,MAAA,CAAC,mBAAmB,IAAI,GAAG;AACtB,WAAA;AAAA,EAAA;AAIT,MAAI,CAAC,KAAK,eAAe,eAAe,GAAG;AAClC,WAAA;AAAA,EAAA;AAIT,MAAI,OAAO,eAAe,CAAC,MAAM,OAAO,WAAW;AAC1C,WAAA;AAAA,EAAA;AAIF,SAAA;AACT;AAEA,SAAS,mBAAmB,GAAiB;AAC3C,SAAO,OAAO,UAAU,SAAS,KAAK,CAAC,MAAM;AAC/C;"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for configuring a debounced function
|
|
3
|
+
*/
|
|
4
|
+
export interface DebouncerOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Whether the debouncer is enabled. When disabled, maybeExecute will not trigger any executions.
|
|
7
|
+
* Defaults to true.
|
|
8
|
+
*/
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Whether to execute on the leading edge of the timeout.
|
|
12
|
+
* Defaults to false.
|
|
13
|
+
*/
|
|
14
|
+
leading?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Whether to execute on the trailing edge of the timeout.
|
|
17
|
+
* Defaults to true.
|
|
18
|
+
*/
|
|
19
|
+
trailing?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Delay in milliseconds before executing the function
|
|
22
|
+
* Defaults to 0ms
|
|
23
|
+
*/
|
|
24
|
+
wait: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A class that creates a debounced function.
|
|
28
|
+
*
|
|
29
|
+
* Debouncing ensures that a function is only executed after a certain amount of time has passed
|
|
30
|
+
* since its last invocation. This is useful for handling frequent events like window resizing,
|
|
31
|
+
* scroll events, or input changes where you want to limit the rate of execution.
|
|
32
|
+
*
|
|
33
|
+
* The debounced function can be configured to execute either at the start of the delay period
|
|
34
|
+
* (leading edge) or at the end (trailing edge, default). Each new call during the wait period
|
|
35
|
+
* will reset the timer.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const debouncer = new Debouncer((value: string) => {
|
|
40
|
+
* saveToDatabase(value);
|
|
41
|
+
* }, { wait: 500 });
|
|
42
|
+
*
|
|
43
|
+
* // Will only save after 500ms of no new input
|
|
44
|
+
* inputElement.addEventListener('input', () => {
|
|
45
|
+
* debouncer.maybeExecute(inputElement.value);
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare class Debouncer<TFn extends (...args: Array<any>) => any, TArgs extends Parameters<TFn>> {
|
|
50
|
+
private fn;
|
|
51
|
+
private canLeadingExecute;
|
|
52
|
+
private executionCount;
|
|
53
|
+
private options;
|
|
54
|
+
private timeoutId;
|
|
55
|
+
constructor(fn: TFn, initialOptions: DebouncerOptions);
|
|
56
|
+
/**
|
|
57
|
+
* Updates the debouncer options
|
|
58
|
+
* Returns the new options state
|
|
59
|
+
*/
|
|
60
|
+
setOptions(newOptions: Partial<DebouncerOptions>): Required<DebouncerOptions>;
|
|
61
|
+
/**
|
|
62
|
+
* Returns the number of times the function has been executed
|
|
63
|
+
*/
|
|
64
|
+
getExecutionCount(): number;
|
|
65
|
+
/**
|
|
66
|
+
* Attempts to execute the debounced function
|
|
67
|
+
* If a call is already in progress, it will be queued
|
|
68
|
+
*/
|
|
69
|
+
maybeExecute(...args: TArgs): void;
|
|
70
|
+
private executeFunction;
|
|
71
|
+
/**
|
|
72
|
+
* Cancels any pending execution
|
|
73
|
+
*/
|
|
74
|
+
cancel(): void;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Creates a debounced function that delays invoking the provided function until after a specified wait time.
|
|
78
|
+
* Multiple calls during the wait period will cancel previous pending invocations and reset the timer.
|
|
79
|
+
*
|
|
80
|
+
* This the the simple function wrapper implementation pulled from the Debouncer class. If you need
|
|
81
|
+
* more control over the debouncing behavior, use the Debouncer class directly.
|
|
82
|
+
*
|
|
83
|
+
* If leading option is true, the function will execute immediately on the first call, then wait the delay
|
|
84
|
+
* before allowing another execution.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const debounced = debounce(() => {
|
|
89
|
+
* saveChanges();
|
|
90
|
+
* }, { wait: 1000 });
|
|
91
|
+
*
|
|
92
|
+
* // Called repeatedly but executes at most once per second
|
|
93
|
+
* inputElement.addEventListener('input', debounced);
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare function debounce<TFn extends (...args: Array<any>) => any>(fn: TFn, initialOptions: Omit<DebouncerOptions, 'enabled'>): (...args: Parameters<TFn>) => void;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const defaultOptions = {
|
|
2
|
+
enabled: true,
|
|
3
|
+
leading: false,
|
|
4
|
+
trailing: true,
|
|
5
|
+
wait: 0
|
|
6
|
+
};
|
|
7
|
+
class Debouncer {
|
|
8
|
+
constructor(fn, initialOptions) {
|
|
9
|
+
this.fn = fn;
|
|
10
|
+
this.canLeadingExecute = true;
|
|
11
|
+
this.executionCount = 0;
|
|
12
|
+
this.options = {
|
|
13
|
+
...defaultOptions,
|
|
14
|
+
...initialOptions
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Updates the debouncer options
|
|
19
|
+
* Returns the new options state
|
|
20
|
+
*/
|
|
21
|
+
setOptions(newOptions) {
|
|
22
|
+
this.options = {
|
|
23
|
+
...this.options,
|
|
24
|
+
...newOptions
|
|
25
|
+
};
|
|
26
|
+
return this.options;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns the number of times the function has been executed
|
|
30
|
+
*/
|
|
31
|
+
getExecutionCount() {
|
|
32
|
+
return this.executionCount;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Attempts to execute the debounced function
|
|
36
|
+
* If a call is already in progress, it will be queued
|
|
37
|
+
*/
|
|
38
|
+
maybeExecute(...args) {
|
|
39
|
+
if (this.options.leading && this.canLeadingExecute) {
|
|
40
|
+
this.executeFunction(...args);
|
|
41
|
+
this.canLeadingExecute = false;
|
|
42
|
+
}
|
|
43
|
+
if (this.timeoutId) clearTimeout(this.timeoutId);
|
|
44
|
+
this.timeoutId = setTimeout(() => {
|
|
45
|
+
this.canLeadingExecute = true;
|
|
46
|
+
if (this.options.trailing) {
|
|
47
|
+
this.executeFunction(...args);
|
|
48
|
+
}
|
|
49
|
+
}, this.options.wait);
|
|
50
|
+
}
|
|
51
|
+
executeFunction(...args) {
|
|
52
|
+
if (!this.options.enabled) return;
|
|
53
|
+
this.executionCount++;
|
|
54
|
+
this.fn(...args);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Cancels any pending execution
|
|
58
|
+
*/
|
|
59
|
+
cancel() {
|
|
60
|
+
if (this.timeoutId) {
|
|
61
|
+
clearTimeout(this.timeoutId);
|
|
62
|
+
this.canLeadingExecute = true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function debounce(fn, initialOptions) {
|
|
67
|
+
const debouncer = new Debouncer(fn, initialOptions);
|
|
68
|
+
return debouncer.maybeExecute.bind(debouncer);
|
|
69
|
+
}
|
|
70
|
+
export {
|
|
71
|
+
Debouncer,
|
|
72
|
+
debounce
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=debouncer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debouncer.js","sources":["../../src/debouncer.ts"],"sourcesContent":["/**\n * Options for configuring a debounced function\n */\nexport interface DebouncerOptions {\n /**\n * Whether the debouncer is enabled. When disabled, maybeExecute will not trigger any executions.\n * Defaults to true.\n */\n enabled?: boolean\n /**\n * Whether to execute on the leading edge of the timeout.\n * Defaults to false.\n */\n leading?: boolean\n /**\n * Whether to execute on the trailing edge of the timeout.\n * Defaults to true.\n */\n trailing?: boolean\n /**\n * Delay in milliseconds before executing the function\n * Defaults to 0ms\n */\n wait: number\n}\n\nconst defaultOptions: Required<DebouncerOptions> = {\n enabled: true,\n leading: false,\n trailing: true,\n wait: 0,\n}\n\n/**\n * A class that creates a debounced function.\n *\n * Debouncing ensures that a function is only executed after a certain amount of time has passed\n * since its last invocation. This is useful for handling frequent events like window resizing,\n * scroll events, or input changes where you want to limit the rate of execution.\n *\n * The debounced function can be configured to execute either at the start of the delay period\n * (leading edge) or at the end (trailing edge, default). Each new call during the wait period\n * will reset the timer.\n *\n * @example\n * ```ts\n * const debouncer = new Debouncer((value: string) => {\n * saveToDatabase(value);\n * }, { wait: 500 });\n *\n * // Will only save after 500ms of no new input\n * inputElement.addEventListener('input', () => {\n * debouncer.maybeExecute(inputElement.value);\n * });\n * ```\n */\nexport class Debouncer<\n TFn extends (...args: Array<any>) => any,\n TArgs extends Parameters<TFn>,\n> {\n private canLeadingExecute = true\n private executionCount = 0\n private options: Required<DebouncerOptions>\n private timeoutId: NodeJS.Timeout | undefined\n\n constructor(\n private fn: TFn,\n initialOptions: DebouncerOptions,\n ) {\n this.options = {\n ...defaultOptions,\n ...initialOptions,\n }\n }\n\n /**\n * Updates the debouncer options\n * Returns the new options state\n */\n setOptions(\n newOptions: Partial<DebouncerOptions>,\n ): Required<DebouncerOptions> {\n this.options = {\n ...this.options,\n ...newOptions,\n }\n return this.options\n }\n\n /**\n * Returns the number of times the function has been executed\n */\n getExecutionCount(): number {\n return this.executionCount\n }\n\n /**\n * Attempts to execute the debounced function\n * If a call is already in progress, it will be queued\n */\n maybeExecute(...args: TArgs): void {\n // Handle leading execution\n if (this.options.leading && this.canLeadingExecute) {\n this.executeFunction(...args)\n this.canLeadingExecute = false\n }\n\n // Clear any existing timeout\n if (this.timeoutId) clearTimeout(this.timeoutId)\n\n // Set new timeout that will reset canLeadingExecute\n this.timeoutId = setTimeout(() => {\n this.canLeadingExecute = true\n // Execute trailing only if enabled\n if (this.options.trailing) {\n this.executeFunction(...args)\n }\n }, this.options.wait)\n }\n\n private executeFunction(...args: TArgs): void {\n if (!this.options.enabled) return\n this.executionCount++\n this.fn(...args)\n }\n\n /**\n * Cancels any pending execution\n */\n cancel(): void {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId)\n this.canLeadingExecute = true\n }\n }\n}\n\n/**\n * Creates a debounced function that delays invoking the provided function until after a specified wait time.\n * Multiple calls during the wait period will cancel previous pending invocations and reset the timer.\n *\n * This the the simple function wrapper implementation pulled from the Debouncer class. If you need\n * more control over the debouncing behavior, use the Debouncer class directly.\n *\n * If leading option is true, the function will execute immediately on the first call, then wait the delay\n * before allowing another execution.\n *\n * @example\n * ```ts\n * const debounced = debounce(() => {\n * saveChanges();\n * }, { wait: 1000 });\n *\n * // Called repeatedly but executes at most once per second\n * inputElement.addEventListener('input', debounced);\n * ```\n */\nexport function debounce<TFn extends (...args: Array<any>) => any>(\n fn: TFn,\n initialOptions: Omit<DebouncerOptions, 'enabled'>,\n) {\n const debouncer = new Debouncer(fn, initialOptions)\n return debouncer.maybeExecute.bind(debouncer)\n}\n"],"names":[],"mappings":"AA0BA,MAAM,iBAA6C;AAAA,EACjD,SAAS;AAAA,EACT,SAAS;AAAA,EACT,UAAU;AAAA,EACV,MAAM;AACR;AAyBO,MAAM,UAGX;AAAA,EAMA,YACU,IACR,gBACA;AAFQ,SAAA,KAAA;AANV,SAAQ,oBAAoB;AAC5B,SAAQ,iBAAiB;AAQvB,SAAK,UAAU;AAAA,MACb,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOF,WACE,YAC4B;AAC5B,SAAK,UAAU;AAAA,MACb,GAAG,KAAK;AAAA,MACR,GAAG;AAAA,IACL;AACA,WAAO,KAAK;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,EAMd,oBAA4B;AAC1B,WAAO,KAAK;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOd,gBAAgB,MAAmB;AAEjC,QAAI,KAAK,QAAQ,WAAW,KAAK,mBAAmB;AAC7C,WAAA,gBAAgB,GAAG,IAAI;AAC5B,WAAK,oBAAoB;AAAA,IAAA;AAI3B,QAAI,KAAK,UAAwB,cAAA,KAAK,SAAS;AAG1C,SAAA,YAAY,WAAW,MAAM;AAChC,WAAK,oBAAoB;AAErB,UAAA,KAAK,QAAQ,UAAU;AACpB,aAAA,gBAAgB,GAAG,IAAI;AAAA,MAAA;AAAA,IAC9B,GACC,KAAK,QAAQ,IAAI;AAAA,EAAA;AAAA,EAGd,mBAAmB,MAAmB;AACxC,QAAA,CAAC,KAAK,QAAQ,QAAS;AACtB,SAAA;AACA,SAAA,GAAG,GAAG,IAAI;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,EAMjB,SAAe;AACb,QAAI,KAAK,WAAW;AAClB,mBAAa,KAAK,SAAS;AAC3B,WAAK,oBAAoB;AAAA,IAAA;AAAA,EAC3B;AAEJ;AAsBgB,SAAA,SACd,IACA,gBACA;AACA,QAAM,YAAY,IAAI,UAAU,IAAI,cAAc;AAC3C,SAAA,UAAU,aAAa,KAAK,SAAS;AAC9C;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './async-debouncer.js';
|
|
2
|
+
export * from './async-queuer.js';
|
|
3
|
+
export * from './async-rate-limiter.js';
|
|
4
|
+
export * from './async-throttler.js';
|
|
5
|
+
export * from './compare.js';
|
|
6
|
+
export * from './debouncer.js';
|
|
7
|
+
export * from './queuer.js';
|
|
8
|
+
export * from './rate-limiter.js';
|
|
9
|
+
export * from './throttler.js';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AsyncDebouncer, asyncDebounce } from "./async-debouncer.js";
|
|
2
|
+
import { AsyncQueuer, asyncQueue } from "./async-queuer.js";
|
|
3
|
+
import { AsyncRateLimiter, asyncRateLimit } from "./async-rate-limiter.js";
|
|
4
|
+
import { AsyncThrottler, asyncThrottle } from "./async-throttler.js";
|
|
5
|
+
import { isPlainArray, isPlainObject, replaceEqualDeep, shallowEqualObjects } from "./compare.js";
|
|
6
|
+
import { Debouncer, debounce } from "./debouncer.js";
|
|
7
|
+
import { Queuer, queue } from "./queuer.js";
|
|
8
|
+
import { RateLimiter, rateLimit } from "./rate-limiter.js";
|
|
9
|
+
import { Throttler, throttle } from "./throttler.js";
|
|
10
|
+
export {
|
|
11
|
+
AsyncDebouncer,
|
|
12
|
+
AsyncQueuer,
|
|
13
|
+
AsyncRateLimiter,
|
|
14
|
+
AsyncThrottler,
|
|
15
|
+
Debouncer,
|
|
16
|
+
Queuer,
|
|
17
|
+
RateLimiter,
|
|
18
|
+
Throttler,
|
|
19
|
+
asyncDebounce,
|
|
20
|
+
asyncQueue,
|
|
21
|
+
asyncRateLimit,
|
|
22
|
+
asyncThrottle,
|
|
23
|
+
debounce,
|
|
24
|
+
isPlainArray,
|
|
25
|
+
isPlainObject,
|
|
26
|
+
queue,
|
|
27
|
+
rateLimit,
|
|
28
|
+
replaceEqualDeep,
|
|
29
|
+
shallowEqualObjects,
|
|
30
|
+
throttle
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|