@tanstack/angular-pacer 0.20.0 → 0.21.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/async-batcher/index.d.cts +2 -2
- package/dist/async-batcher/index.d.ts +2 -2
- package/dist/async-batcher/injectAsyncBatcher.cjs +27 -3
- package/dist/async-batcher/injectAsyncBatcher.cjs.map +1 -1
- package/dist/async-batcher/injectAsyncBatcher.d.cts +25 -3
- package/dist/async-batcher/injectAsyncBatcher.d.ts +25 -3
- package/dist/async-batcher/injectAsyncBatcher.js +27 -3
- package/dist/async-batcher/injectAsyncBatcher.js.map +1 -1
- package/dist/async-debouncer/index.d.cts +2 -2
- package/dist/async-debouncer/index.d.ts +2 -2
- package/dist/async-debouncer/injectAsyncDebouncer.cjs +27 -3
- package/dist/async-debouncer/injectAsyncDebouncer.cjs.map +1 -1
- package/dist/async-debouncer/injectAsyncDebouncer.d.cts +25 -3
- package/dist/async-debouncer/injectAsyncDebouncer.d.ts +25 -3
- package/dist/async-debouncer/injectAsyncDebouncer.js +27 -3
- package/dist/async-debouncer/injectAsyncDebouncer.js.map +1 -1
- package/dist/async-queuer/index.d.cts +2 -2
- package/dist/async-queuer/index.d.ts +2 -2
- package/dist/async-queuer/injectAsyncQueuer.cjs +27 -3
- package/dist/async-queuer/injectAsyncQueuer.cjs.map +1 -1
- package/dist/async-queuer/injectAsyncQueuer.d.cts +25 -3
- package/dist/async-queuer/injectAsyncQueuer.d.ts +25 -3
- package/dist/async-queuer/injectAsyncQueuer.js +27 -3
- package/dist/async-queuer/injectAsyncQueuer.js.map +1 -1
- package/dist/async-rate-limiter/index.d.cts +2 -2
- package/dist/async-rate-limiter/index.d.ts +2 -2
- package/dist/async-rate-limiter/injectAsyncRateLimiter.cjs +15 -3
- package/dist/async-rate-limiter/injectAsyncRateLimiter.cjs.map +1 -1
- package/dist/async-rate-limiter/injectAsyncRateLimiter.d.cts +15 -3
- package/dist/async-rate-limiter/injectAsyncRateLimiter.d.ts +15 -3
- package/dist/async-rate-limiter/injectAsyncRateLimiter.js +15 -3
- package/dist/async-rate-limiter/injectAsyncRateLimiter.js.map +1 -1
- package/dist/async-throttler/index.d.cts +2 -2
- package/dist/async-throttler/index.d.ts +2 -2
- package/dist/async-throttler/injectAsyncThrottler.cjs +27 -3
- package/dist/async-throttler/injectAsyncThrottler.cjs.map +1 -1
- package/dist/async-throttler/injectAsyncThrottler.d.cts +25 -3
- package/dist/async-throttler/injectAsyncThrottler.d.ts +25 -3
- package/dist/async-throttler/injectAsyncThrottler.js +27 -3
- package/dist/async-throttler/injectAsyncThrottler.js.map +1 -1
- package/dist/batcher/index.d.cts +2 -2
- package/dist/batcher/index.d.ts +2 -2
- package/dist/batcher/injectBatcher.cjs +22 -3
- package/dist/batcher/injectBatcher.cjs.map +1 -1
- package/dist/batcher/injectBatcher.d.cts +22 -3
- package/dist/batcher/injectBatcher.d.ts +22 -3
- package/dist/batcher/injectBatcher.js +22 -3
- package/dist/batcher/injectBatcher.js.map +1 -1
- package/dist/debouncer/index.d.cts +2 -2
- package/dist/debouncer/index.d.ts +2 -2
- package/dist/debouncer/injectDebouncer.cjs +22 -3
- package/dist/debouncer/injectDebouncer.cjs.map +1 -1
- package/dist/debouncer/injectDebouncer.d.cts +22 -3
- package/dist/debouncer/injectDebouncer.d.ts +22 -3
- package/dist/debouncer/injectDebouncer.js +22 -3
- package/dist/debouncer/injectDebouncer.js.map +1 -1
- package/dist/index.d.cts +11 -11
- package/dist/index.d.ts +11 -11
- package/dist/queuer/index.d.cts +2 -2
- package/dist/queuer/index.d.ts +2 -2
- package/dist/queuer/injectQueuer.cjs +22 -3
- package/dist/queuer/injectQueuer.cjs.map +1 -1
- package/dist/queuer/injectQueuer.d.cts +22 -3
- package/dist/queuer/injectQueuer.d.ts +22 -3
- package/dist/queuer/injectQueuer.js +22 -3
- package/dist/queuer/injectQueuer.js.map +1 -1
- package/dist/rate-limiter/index.d.cts +2 -2
- package/dist/rate-limiter/index.d.ts +2 -2
- package/dist/rate-limiter/injectRateLimiter.cjs +13 -3
- package/dist/rate-limiter/injectRateLimiter.cjs.map +1 -1
- package/dist/rate-limiter/injectRateLimiter.d.cts +13 -3
- package/dist/rate-limiter/injectRateLimiter.d.ts +13 -3
- package/dist/rate-limiter/injectRateLimiter.js +13 -3
- package/dist/rate-limiter/injectRateLimiter.js.map +1 -1
- package/dist/throttler/index.d.cts +2 -2
- package/dist/throttler/index.d.ts +2 -2
- package/dist/throttler/injectThrottler.cjs +22 -3
- package/dist/throttler/injectThrottler.cjs.map +1 -1
- package/dist/throttler/injectThrottler.d.cts +22 -3
- package/dist/throttler/injectThrottler.d.ts +22 -3
- package/dist/throttler/injectThrottler.js +22 -3
- package/dist/throttler/injectThrottler.js.map +1 -1
- package/package.json +15 -15
- package/src/async-batcher/injectAsyncBatcher.ts +43 -4
- package/src/async-debouncer/injectAsyncDebouncer.ts +43 -4
- package/src/async-queuer/injectAsyncQueuer.ts +43 -4
- package/src/async-rate-limiter/injectAsyncRateLimiter.ts +32 -4
- package/src/async-throttler/injectAsyncThrottler.ts +43 -4
- package/src/batcher/injectBatcher.ts +39 -4
- package/src/debouncer/injectDebouncer.ts +39 -4
- package/src/queuer/injectQueuer.ts +39 -4
- package/src/rate-limiter/injectRateLimiter.ts +28 -4
- package/src/throttler/injectThrottler.ts +39 -4
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { injectPacerOptions } from "../provider/pacer-context.js";
|
|
2
|
+
import { DestroyRef, inject } from "@angular/core";
|
|
2
3
|
import { injectStore } from "@tanstack/angular-store";
|
|
3
4
|
import { Debouncer } from "@tanstack/pacer/debouncer";
|
|
4
5
|
|
|
@@ -34,6 +35,18 @@ import { Debouncer } from "@tanstack/pacer/debouncer";
|
|
|
34
35
|
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
35
36
|
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
36
37
|
*
|
|
38
|
+
* ## Cleanup on Destroy
|
|
39
|
+
*
|
|
40
|
+
* By default, the function cancels any pending execution when the component is destroyed.
|
|
41
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* const debouncer = injectDebouncer(fn, {
|
|
45
|
+
* wait: 500,
|
|
46
|
+
* onUnmount: (d) => d.flush()
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
37
50
|
* @example
|
|
38
51
|
* ```ts
|
|
39
52
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -60,15 +73,21 @@ import { Debouncer } from "@tanstack/pacer/debouncer";
|
|
|
60
73
|
* ```
|
|
61
74
|
*/
|
|
62
75
|
function injectDebouncer(fn, options, selector = () => ({})) {
|
|
63
|
-
const
|
|
76
|
+
const mergedOptions = {
|
|
64
77
|
...injectPacerOptions().debouncer,
|
|
65
78
|
...options
|
|
66
|
-
}
|
|
79
|
+
};
|
|
80
|
+
const debouncer = new Debouncer(fn, mergedOptions);
|
|
67
81
|
const state = injectStore(debouncer.store, selector);
|
|
68
|
-
|
|
82
|
+
const result = {
|
|
69
83
|
...debouncer,
|
|
70
84
|
state
|
|
71
85
|
};
|
|
86
|
+
inject(DestroyRef, { optional: true })?.onDestroy(() => {
|
|
87
|
+
if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
|
|
88
|
+
else debouncer.cancel();
|
|
89
|
+
});
|
|
90
|
+
return result;
|
|
72
91
|
}
|
|
73
92
|
|
|
74
93
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectDebouncer.js","names":[],"sources":["../../src/debouncer/injectDebouncer.ts"],"sourcesContent":["import { injectStore } from '@tanstack/angular-store'\nimport { Debouncer } from '@tanstack/pacer/debouncer'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/store'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\nexport interface AngularDebouncer<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Debouncer<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the debouncer state changes\n *\n * Use this instead of `debouncer.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<DebouncerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages a Debouncer instance.\n *\n * This is a lower-level function that provides direct access to the Debouncer's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides debouncing functionality to limit how often a function can be called,\n * waiting for a specified delay before executing the latest call. This is useful for handling\n * frequent events like window resizing, scroll events, or real-time search inputs.\n *\n * The debouncer will only execute the function after the specified wait time has elapsed\n * since the last call. If the function is called again before the wait time expires, the\n * timer resets and starts waiting again.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const debouncer = injectDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 }\n * );\n *\n * // Opt-in to track isPending changes (optimized for loading states)\n * const debouncer = injectDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // In an event handler\n * const handleChange = (e: Event) => {\n * const target = e.target as HTMLInputElement\n * debouncer.maybeExecute(target.value);\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = debouncer.state();\n * ```\n */\nexport function injectDebouncer<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options:
|
|
1
|
+
{"version":3,"file":"injectDebouncer.js","names":[],"sources":["../../src/debouncer/injectDebouncer.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { Debouncer } from '@tanstack/pacer/debouncer'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\nexport interface AngularDebouncerOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends DebouncerOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the debouncer instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), cancel(), add logging, etc.\n */\n onUnmount?: (debouncer: AngularDebouncer<TFn, TSelected>) => void\n}\n\nexport interface AngularDebouncer<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Debouncer<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the debouncer state changes\n *\n * Use this instead of `debouncer.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<DebouncerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages a Debouncer instance.\n *\n * This is a lower-level function that provides direct access to the Debouncer's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides debouncing functionality to limit how often a function can be called,\n * waiting for a specified delay before executing the latest call. This is useful for handling\n * frequent events like window resizing, scroll events, or real-time search inputs.\n *\n * The debouncer will only execute the function after the specified wait time has elapsed\n * since the last call. If the function is called again before the wait time expires, the\n * timer resets and starts waiting again.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * ## Cleanup on Destroy\n *\n * By default, the function cancels any pending execution when the component is destroyed.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```ts\n * const debouncer = injectDebouncer(fn, {\n * wait: 500,\n * onUnmount: (d) => d.flush()\n * });\n * ```\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const debouncer = injectDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 }\n * );\n *\n * // Opt-in to track isPending changes (optimized for loading states)\n * const debouncer = injectDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // In an event handler\n * const handleChange = (e: Event) => {\n * const target = e.target as HTMLInputElement\n * debouncer.maybeExecute(target.value);\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = debouncer.state();\n * ```\n */\nexport function injectDebouncer<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: AngularDebouncerOptions<TFn, TSelected>,\n selector: (state: DebouncerState<TFn>) => TSelected = () => ({}) as TSelected,\n): AngularDebouncer<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().debouncer,\n ...options,\n } as AngularDebouncerOptions<TFn, TSelected>\n\n const debouncer = new Debouncer<TFn>(fn, mergedOptions)\n const state = injectStore(debouncer.store, selector)\n\n const result = {\n ...debouncer,\n state,\n } as AngularDebouncer<TFn, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n debouncer.cancel()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4GA,SAAgB,gBACd,IACA,SACA,kBAA6D,EAAE,GAC7B;CAClC,MAAM,gBAAgB;EACpB,GAAG,oBAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,YAAY,IAAI,UAAe,IAAI,cAAc;CACvD,MAAM,QAAQ,YAAY,UAAU,OAAO,SAAS;CAEpD,MAAM,SAAS;EACb,GAAG;EACH;EACD;AAGD,CADmB,OAAO,YAAY,EAAE,UAAU,MAAM,CAAC,EAC7C,gBAAgB;AAC1B,MAAI,cAAc,UAChB,eAAc,UAAU,OAAO;MAE/B,WAAU,QAAQ;GAEpB;AAEF,QAAO"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import { injectAsyncBatchedCallback } from "./async-batcher/injectAsyncBatchedCallback.cjs";
|
|
2
|
-
import { AngularAsyncBatcher, injectAsyncBatcher } from "./async-batcher/injectAsyncBatcher.cjs";
|
|
2
|
+
import { AngularAsyncBatcher, AngularAsyncBatcherOptions, injectAsyncBatcher } from "./async-batcher/injectAsyncBatcher.cjs";
|
|
3
3
|
import { injectAsyncDebouncedCallback } from "./async-debouncer/injectAsyncDebouncedCallback.cjs";
|
|
4
|
-
import { AngularAsyncDebouncer, injectAsyncDebouncer } from "./async-debouncer/injectAsyncDebouncer.cjs";
|
|
5
|
-
import { AngularAsyncQueuer, injectAsyncQueuer } from "./async-queuer/injectAsyncQueuer.cjs";
|
|
4
|
+
import { AngularAsyncDebouncer, AngularAsyncDebouncerOptions, injectAsyncDebouncer } from "./async-debouncer/injectAsyncDebouncer.cjs";
|
|
5
|
+
import { AngularAsyncQueuer, AngularAsyncQueuerOptions, injectAsyncQueuer } from "./async-queuer/injectAsyncQueuer.cjs";
|
|
6
6
|
import { AsyncQueuedSignal, injectAsyncQueuedSignal } from "./async-queuer/injectAsyncQueuedSignal.cjs";
|
|
7
7
|
import { injectAsyncRateLimitedCallback } from "./async-rate-limiter/injectAsyncRateLimitedCallback.cjs";
|
|
8
|
-
import { AngularAsyncRateLimiter, injectAsyncRateLimiter } from "./async-rate-limiter/injectAsyncRateLimiter.cjs";
|
|
8
|
+
import { AngularAsyncRateLimiter, AngularAsyncRateLimiterOptions, injectAsyncRateLimiter } from "./async-rate-limiter/injectAsyncRateLimiter.cjs";
|
|
9
9
|
import { injectAsyncThrottledCallback } from "./async-throttler/injectAsyncThrottledCallback.cjs";
|
|
10
|
-
import { AngularAsyncThrottler, injectAsyncThrottler } from "./async-throttler/injectAsyncThrottler.cjs";
|
|
10
|
+
import { AngularAsyncThrottler, AngularAsyncThrottlerOptions, injectAsyncThrottler } from "./async-throttler/injectAsyncThrottler.cjs";
|
|
11
11
|
import { injectBatchedCallback } from "./batcher/injectBatchedCallback.cjs";
|
|
12
|
-
import { AngularBatcher, injectBatcher } from "./batcher/injectBatcher.cjs";
|
|
12
|
+
import { AngularBatcher, AngularBatcherOptions, injectBatcher } from "./batcher/injectBatcher.cjs";
|
|
13
13
|
import { injectDebouncedCallback } from "./debouncer/injectDebouncedCallback.cjs";
|
|
14
|
-
import { AngularDebouncer, injectDebouncer } from "./debouncer/injectDebouncer.cjs";
|
|
14
|
+
import { AngularDebouncer, AngularDebouncerOptions, injectDebouncer } from "./debouncer/injectDebouncer.cjs";
|
|
15
15
|
import { DebouncedSignal, injectDebouncedSignal } from "./debouncer/injectDebouncedSignal.cjs";
|
|
16
16
|
import { injectDebouncedValue } from "./debouncer/injectDebouncedValue.cjs";
|
|
17
17
|
import { providePacerOptions } from "./provider/pacer-provider.cjs";
|
|
18
|
-
import { AngularQueuer, injectQueuer } from "./queuer/injectQueuer.cjs";
|
|
18
|
+
import { AngularQueuer, AngularQueuerOptions, injectQueuer } from "./queuer/injectQueuer.cjs";
|
|
19
19
|
import { QueuedSignal, injectQueuedSignal } from "./queuer/injectQueuedSignal.cjs";
|
|
20
20
|
import { injectQueuedValue } from "./queuer/injectQueuedValue.cjs";
|
|
21
21
|
import { injectRateLimitedCallback } from "./rate-limiter/injectRateLimitedCallback.cjs";
|
|
22
|
-
import { AngularRateLimiter, injectRateLimiter } from "./rate-limiter/injectRateLimiter.cjs";
|
|
22
|
+
import { AngularRateLimiter, AngularRateLimiterOptions, injectRateLimiter } from "./rate-limiter/injectRateLimiter.cjs";
|
|
23
23
|
import { RateLimitedSignal, injectRateLimitedSignal } from "./rate-limiter/injectRateLimitedSignal.cjs";
|
|
24
24
|
import { injectRateLimitedValue } from "./rate-limiter/injectRateLimitedValue.cjs";
|
|
25
25
|
import { injectThrottledCallback } from "./throttler/injectThrottledCallback.cjs";
|
|
26
|
-
import { AngularThrottler, injectThrottler } from "./throttler/injectThrottler.cjs";
|
|
26
|
+
import { AngularThrottler, AngularThrottlerOptions, injectThrottler } from "./throttler/injectThrottler.cjs";
|
|
27
27
|
import { ThrottledSignal, injectThrottledSignal } from "./throttler/injectThrottledSignal.cjs";
|
|
28
28
|
import { injectThrottledValue } from "./throttler/injectThrottledValue.cjs";
|
|
29
29
|
export * from "@tanstack/pacer";
|
|
30
|
-
export { AngularAsyncBatcher, AngularAsyncDebouncer, AngularAsyncQueuer, AngularAsyncRateLimiter, AngularAsyncThrottler, AngularBatcher, AngularDebouncer, AngularQueuer, AngularRateLimiter, AngularThrottler, AsyncQueuedSignal, DebouncedSignal, QueuedSignal, RateLimitedSignal, ThrottledSignal, injectAsyncBatchedCallback, injectAsyncBatcher, injectAsyncDebouncedCallback, injectAsyncDebouncer, injectAsyncQueuedSignal, injectAsyncQueuer, injectAsyncRateLimitedCallback, injectAsyncRateLimiter, injectAsyncThrottledCallback, injectAsyncThrottler, injectBatchedCallback, injectBatcher, injectDebouncedCallback, injectDebouncedSignal, injectDebouncedValue, injectDebouncer, injectQueuedSignal, injectQueuedValue, injectQueuer, injectRateLimitedCallback, injectRateLimitedSignal, injectRateLimitedValue, injectRateLimiter, injectThrottledCallback, injectThrottledSignal, injectThrottledValue, injectThrottler, providePacerOptions };
|
|
30
|
+
export { AngularAsyncBatcher, AngularAsyncBatcherOptions, AngularAsyncDebouncer, AngularAsyncDebouncerOptions, AngularAsyncQueuer, AngularAsyncQueuerOptions, AngularAsyncRateLimiter, AngularAsyncRateLimiterOptions, AngularAsyncThrottler, AngularAsyncThrottlerOptions, AngularBatcher, AngularBatcherOptions, AngularDebouncer, AngularDebouncerOptions, AngularQueuer, AngularQueuerOptions, AngularRateLimiter, AngularRateLimiterOptions, AngularThrottler, AngularThrottlerOptions, AsyncQueuedSignal, DebouncedSignal, QueuedSignal, RateLimitedSignal, ThrottledSignal, injectAsyncBatchedCallback, injectAsyncBatcher, injectAsyncDebouncedCallback, injectAsyncDebouncer, injectAsyncQueuedSignal, injectAsyncQueuer, injectAsyncRateLimitedCallback, injectAsyncRateLimiter, injectAsyncThrottledCallback, injectAsyncThrottler, injectBatchedCallback, injectBatcher, injectDebouncedCallback, injectDebouncedSignal, injectDebouncedValue, injectDebouncer, injectQueuedSignal, injectQueuedValue, injectQueuer, injectRateLimitedCallback, injectRateLimitedSignal, injectRateLimitedValue, injectRateLimiter, injectThrottledCallback, injectThrottledSignal, injectThrottledValue, injectThrottler, providePacerOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import { injectAsyncBatchedCallback } from "./async-batcher/injectAsyncBatchedCallback.js";
|
|
2
|
-
import { AngularAsyncBatcher, injectAsyncBatcher } from "./async-batcher/injectAsyncBatcher.js";
|
|
2
|
+
import { AngularAsyncBatcher, AngularAsyncBatcherOptions, injectAsyncBatcher } from "./async-batcher/injectAsyncBatcher.js";
|
|
3
3
|
import { injectAsyncDebouncedCallback } from "./async-debouncer/injectAsyncDebouncedCallback.js";
|
|
4
|
-
import { AngularAsyncDebouncer, injectAsyncDebouncer } from "./async-debouncer/injectAsyncDebouncer.js";
|
|
5
|
-
import { AngularAsyncQueuer, injectAsyncQueuer } from "./async-queuer/injectAsyncQueuer.js";
|
|
4
|
+
import { AngularAsyncDebouncer, AngularAsyncDebouncerOptions, injectAsyncDebouncer } from "./async-debouncer/injectAsyncDebouncer.js";
|
|
5
|
+
import { AngularAsyncQueuer, AngularAsyncQueuerOptions, injectAsyncQueuer } from "./async-queuer/injectAsyncQueuer.js";
|
|
6
6
|
import { AsyncQueuedSignal, injectAsyncQueuedSignal } from "./async-queuer/injectAsyncQueuedSignal.js";
|
|
7
7
|
import { injectAsyncRateLimitedCallback } from "./async-rate-limiter/injectAsyncRateLimitedCallback.js";
|
|
8
|
-
import { AngularAsyncRateLimiter, injectAsyncRateLimiter } from "./async-rate-limiter/injectAsyncRateLimiter.js";
|
|
8
|
+
import { AngularAsyncRateLimiter, AngularAsyncRateLimiterOptions, injectAsyncRateLimiter } from "./async-rate-limiter/injectAsyncRateLimiter.js";
|
|
9
9
|
import { injectAsyncThrottledCallback } from "./async-throttler/injectAsyncThrottledCallback.js";
|
|
10
|
-
import { AngularAsyncThrottler, injectAsyncThrottler } from "./async-throttler/injectAsyncThrottler.js";
|
|
10
|
+
import { AngularAsyncThrottler, AngularAsyncThrottlerOptions, injectAsyncThrottler } from "./async-throttler/injectAsyncThrottler.js";
|
|
11
11
|
import { injectBatchedCallback } from "./batcher/injectBatchedCallback.js";
|
|
12
|
-
import { AngularBatcher, injectBatcher } from "./batcher/injectBatcher.js";
|
|
12
|
+
import { AngularBatcher, AngularBatcherOptions, injectBatcher } from "./batcher/injectBatcher.js";
|
|
13
13
|
import { injectDebouncedCallback } from "./debouncer/injectDebouncedCallback.js";
|
|
14
|
-
import { AngularDebouncer, injectDebouncer } from "./debouncer/injectDebouncer.js";
|
|
14
|
+
import { AngularDebouncer, AngularDebouncerOptions, injectDebouncer } from "./debouncer/injectDebouncer.js";
|
|
15
15
|
import { DebouncedSignal, injectDebouncedSignal } from "./debouncer/injectDebouncedSignal.js";
|
|
16
16
|
import { injectDebouncedValue } from "./debouncer/injectDebouncedValue.js";
|
|
17
17
|
import { providePacerOptions } from "./provider/pacer-provider.js";
|
|
18
|
-
import { AngularQueuer, injectQueuer } from "./queuer/injectQueuer.js";
|
|
18
|
+
import { AngularQueuer, AngularQueuerOptions, injectQueuer } from "./queuer/injectQueuer.js";
|
|
19
19
|
import { QueuedSignal, injectQueuedSignal } from "./queuer/injectQueuedSignal.js";
|
|
20
20
|
import { injectQueuedValue } from "./queuer/injectQueuedValue.js";
|
|
21
21
|
import { injectRateLimitedCallback } from "./rate-limiter/injectRateLimitedCallback.js";
|
|
22
|
-
import { AngularRateLimiter, injectRateLimiter } from "./rate-limiter/injectRateLimiter.js";
|
|
22
|
+
import { AngularRateLimiter, AngularRateLimiterOptions, injectRateLimiter } from "./rate-limiter/injectRateLimiter.js";
|
|
23
23
|
import { RateLimitedSignal, injectRateLimitedSignal } from "./rate-limiter/injectRateLimitedSignal.js";
|
|
24
24
|
import { injectRateLimitedValue } from "./rate-limiter/injectRateLimitedValue.js";
|
|
25
25
|
import { injectThrottledCallback } from "./throttler/injectThrottledCallback.js";
|
|
26
|
-
import { AngularThrottler, injectThrottler } from "./throttler/injectThrottler.js";
|
|
26
|
+
import { AngularThrottler, AngularThrottlerOptions, injectThrottler } from "./throttler/injectThrottler.js";
|
|
27
27
|
import { ThrottledSignal, injectThrottledSignal } from "./throttler/injectThrottledSignal.js";
|
|
28
28
|
import { injectThrottledValue } from "./throttler/injectThrottledValue.js";
|
|
29
29
|
export * from "@tanstack/pacer";
|
|
30
|
-
export { AngularAsyncBatcher, AngularAsyncDebouncer, AngularAsyncQueuer, AngularAsyncRateLimiter, AngularAsyncThrottler, AngularBatcher, AngularDebouncer, AngularQueuer, AngularRateLimiter, AngularThrottler, AsyncQueuedSignal, DebouncedSignal, QueuedSignal, RateLimitedSignal, ThrottledSignal, injectAsyncBatchedCallback, injectAsyncBatcher, injectAsyncDebouncedCallback, injectAsyncDebouncer, injectAsyncQueuedSignal, injectAsyncQueuer, injectAsyncRateLimitedCallback, injectAsyncRateLimiter, injectAsyncThrottledCallback, injectAsyncThrottler, injectBatchedCallback, injectBatcher, injectDebouncedCallback, injectDebouncedSignal, injectDebouncedValue, injectDebouncer, injectQueuedSignal, injectQueuedValue, injectQueuer, injectRateLimitedCallback, injectRateLimitedSignal, injectRateLimitedValue, injectRateLimiter, injectThrottledCallback, injectThrottledSignal, injectThrottledValue, injectThrottler, providePacerOptions };
|
|
30
|
+
export { AngularAsyncBatcher, AngularAsyncBatcherOptions, AngularAsyncDebouncer, AngularAsyncDebouncerOptions, AngularAsyncQueuer, AngularAsyncQueuerOptions, AngularAsyncRateLimiter, AngularAsyncRateLimiterOptions, AngularAsyncThrottler, AngularAsyncThrottlerOptions, AngularBatcher, AngularBatcherOptions, AngularDebouncer, AngularDebouncerOptions, AngularQueuer, AngularQueuerOptions, AngularRateLimiter, AngularRateLimiterOptions, AngularThrottler, AngularThrottlerOptions, AsyncQueuedSignal, DebouncedSignal, QueuedSignal, RateLimitedSignal, ThrottledSignal, injectAsyncBatchedCallback, injectAsyncBatcher, injectAsyncDebouncedCallback, injectAsyncDebouncer, injectAsyncQueuedSignal, injectAsyncQueuer, injectAsyncRateLimitedCallback, injectAsyncRateLimiter, injectAsyncThrottledCallback, injectAsyncThrottler, injectBatchedCallback, injectBatcher, injectDebouncedCallback, injectDebouncedSignal, injectDebouncedValue, injectDebouncer, injectQueuedSignal, injectQueuedValue, injectQueuer, injectRateLimitedCallback, injectRateLimitedSignal, injectRateLimitedValue, injectRateLimiter, injectThrottledCallback, injectThrottledSignal, injectThrottledValue, injectThrottler, providePacerOptions };
|
package/dist/queuer/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AngularQueuer, injectQueuer } from "./injectQueuer.cjs";
|
|
1
|
+
import { AngularQueuer, AngularQueuerOptions, injectQueuer } from "./injectQueuer.cjs";
|
|
2
2
|
import { QueuedSignal, injectQueuedSignal } from "./injectQueuedSignal.cjs";
|
|
3
3
|
import { injectQueuedValue } from "./injectQueuedValue.cjs";
|
|
4
4
|
export * from "@tanstack/pacer/queuer";
|
|
5
|
-
export { AngularQueuer, QueuedSignal, injectQueuedSignal, injectQueuedValue, injectQueuer };
|
|
5
|
+
export { AngularQueuer, AngularQueuerOptions, QueuedSignal, injectQueuedSignal, injectQueuedValue, injectQueuer };
|
package/dist/queuer/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AngularQueuer, injectQueuer } from "./injectQueuer.js";
|
|
1
|
+
import { AngularQueuer, AngularQueuerOptions, injectQueuer } from "./injectQueuer.js";
|
|
2
2
|
import { QueuedSignal, injectQueuedSignal } from "./injectQueuedSignal.js";
|
|
3
3
|
import { injectQueuedValue } from "./injectQueuedValue.js";
|
|
4
4
|
export * from "@tanstack/pacer/queuer";
|
|
5
|
-
export { AngularQueuer, QueuedSignal, injectQueuedSignal, injectQueuedValue, injectQueuer };
|
|
5
|
+
export { AngularQueuer, AngularQueuerOptions, QueuedSignal, injectQueuedSignal, injectQueuedValue, injectQueuer };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_pacer_context = require('../provider/pacer-context.cjs');
|
|
2
|
+
let _angular_core = require("@angular/core");
|
|
2
3
|
let _tanstack_angular_store = require("@tanstack/angular-store");
|
|
3
4
|
let _tanstack_pacer_queuer = require("@tanstack/pacer/queuer");
|
|
4
5
|
|
|
@@ -43,17 +44,35 @@ let _tanstack_pacer_queuer = require("@tanstack/pacer/queuer");
|
|
|
43
44
|
* // Access the selected state
|
|
44
45
|
* const { items, isRunning } = queue.state();
|
|
45
46
|
* ```
|
|
47
|
+
*
|
|
48
|
+
* ## Cleanup on Destroy
|
|
49
|
+
*
|
|
50
|
+
* By default, the function stops the queuer when the component is destroyed.
|
|
51
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending items instead:
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* const queue = injectQueuer(fn, {
|
|
55
|
+
* started: true,
|
|
56
|
+
* onUnmount: (q) => q.flush()
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
46
59
|
*/
|
|
47
60
|
function injectQueuer(fn, options = {}, selector = () => ({})) {
|
|
48
|
-
const
|
|
61
|
+
const mergedOptions = {
|
|
49
62
|
...require_pacer_context.injectPacerOptions().queuer,
|
|
50
63
|
...options
|
|
51
|
-
}
|
|
64
|
+
};
|
|
65
|
+
const queuer = new _tanstack_pacer_queuer.Queuer(fn, mergedOptions);
|
|
52
66
|
const state = (0, _tanstack_angular_store.injectStore)(queuer.store, selector);
|
|
53
|
-
|
|
67
|
+
const result = {
|
|
54
68
|
...queuer,
|
|
55
69
|
state
|
|
56
70
|
};
|
|
71
|
+
(0, _angular_core.inject)(_angular_core.DestroyRef, { optional: true })?.onDestroy(() => {
|
|
72
|
+
if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
|
|
73
|
+
else queuer.stop();
|
|
74
|
+
});
|
|
75
|
+
return result;
|
|
57
76
|
}
|
|
58
77
|
|
|
59
78
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectQueuer.cjs","names":["Queuer","
|
|
1
|
+
{"version":3,"file":"injectQueuer.cjs","names":["injectPacerOptions","Queuer","DestroyRef"],"sources":["../../src/queuer/injectQueuer.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { Queuer } from '@tanstack/pacer/queuer'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface AngularQueuerOptions<\n TValue,\n TSelected = {},\n> extends QueuerOptions<TValue> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop); use it to call flush(), stop(), add logging, etc.\n */\n onUnmount?: (queuer: AngularQueuer<TValue, TSelected>) => void\n}\n\nexport interface AngularQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<QueuerState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages a Queuer instance.\n *\n * This is a lower-level function that provides direct access to the Queuer's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The Queuer processes items synchronously in order, with optional delays between processing each item.\n * The queuer includes an internal tick mechanism that can be started and stopped, making it useful as a scheduler.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const queue = injectQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 }\n * );\n *\n * // Opt-in to track queue contents changes\n * const queue = injectQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({ items: state.items, size: state.size })\n * );\n *\n * // Add items\n * queue.addItem('task1');\n *\n * // Access the selected state\n * const { items, isRunning } = queue.state();\n * ```\n *\n * ## Cleanup on Destroy\n *\n * By default, the function stops the queuer when the component is destroyed.\n * Use the `onUnmount` option to customize this. For example, to flush pending items instead:\n *\n * ```ts\n * const queue = injectQueuer(fn, {\n * started: true,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n */\nexport function injectQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: AngularQueuerOptions<TValue, TSelected> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): AngularQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().queuer,\n ...options,\n } as AngularQueuerOptions<TValue, TSelected>\n\n const queuer = new Queuer<TValue>(fn, mergedOptions)\n const state = injectStore(queuer.store, selector)\n\n const result = {\n ...queuer,\n state,\n } as AngularQueuer<TValue, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n queuer.stop()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,aACd,IACA,UAAmD,EAAE,EACrD,kBAA6D,EAAE,GAC7B;CAClC,MAAM,gBAAgB;EACpB,GAAGA,0CAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,SAAS,IAAIC,8BAAe,IAAI,cAAc;CACpD,MAAM,iDAAoB,OAAO,OAAO,SAAS;CAEjD,MAAM,SAAS;EACb,GAAG;EACH;EACD;AAGD,2BAD0BC,0BAAY,EAAE,UAAU,MAAM,CAAC,EAC7C,gBAAgB;AAC1B,MAAI,cAAc,UAChB,eAAc,UAAU,OAAO;MAE/B,QAAO,MAAM;GAEf;AAEF,QAAO"}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { Signal } from "@angular/core";
|
|
2
|
-
import { Store } from "@tanstack/store";
|
|
2
|
+
import { Store } from "@tanstack/angular-store";
|
|
3
3
|
import { Queuer, QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
|
|
4
4
|
|
|
5
5
|
//#region src/queuer/injectQueuer.d.ts
|
|
6
|
+
interface AngularQueuerOptions<TValue, TSelected = {}> extends QueuerOptions<TValue> {
|
|
7
|
+
/**
|
|
8
|
+
* Optional callback invoked when the component is destroyed. Receives the queuer instance.
|
|
9
|
+
* When provided, replaces the default cleanup (stop); use it to call flush(), stop(), add logging, etc.
|
|
10
|
+
*/
|
|
11
|
+
onUnmount?: (queuer: AngularQueuer<TValue, TSelected>) => void;
|
|
12
|
+
}
|
|
6
13
|
interface AngularQueuer<TValue, TSelected = {}> extends Omit<Queuer<TValue>, 'store'> {
|
|
7
14
|
/**
|
|
8
15
|
* Reactive state signal that will be updated when the queuer state changes
|
|
@@ -56,8 +63,20 @@ interface AngularQueuer<TValue, TSelected = {}> extends Omit<Queuer<TValue>, 'st
|
|
|
56
63
|
* // Access the selected state
|
|
57
64
|
* const { items, isRunning } = queue.state();
|
|
58
65
|
* ```
|
|
66
|
+
*
|
|
67
|
+
* ## Cleanup on Destroy
|
|
68
|
+
*
|
|
69
|
+
* By default, the function stops the queuer when the component is destroyed.
|
|
70
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending items instead:
|
|
71
|
+
*
|
|
72
|
+
* ```ts
|
|
73
|
+
* const queue = injectQueuer(fn, {
|
|
74
|
+
* started: true,
|
|
75
|
+
* onUnmount: (q) => q.flush()
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
59
78
|
*/
|
|
60
|
-
declare function injectQueuer<TValue, TSelected = {}>(fn: (item: TValue) => void, options?:
|
|
79
|
+
declare function injectQueuer<TValue, TSelected = {}>(fn: (item: TValue) => void, options?: AngularQueuerOptions<TValue, TSelected>, selector?: (state: QueuerState<TValue>) => TSelected): AngularQueuer<TValue, TSelected>;
|
|
61
80
|
//#endregion
|
|
62
|
-
export { AngularQueuer, injectQueuer };
|
|
81
|
+
export { AngularQueuer, AngularQueuerOptions, injectQueuer };
|
|
63
82
|
//# sourceMappingURL=injectQueuer.d.cts.map
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { Signal } from "@angular/core";
|
|
2
|
+
import { Store } from "@tanstack/angular-store";
|
|
2
3
|
import { Queuer, QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
|
|
3
|
-
import { Store } from "@tanstack/store";
|
|
4
4
|
|
|
5
5
|
//#region src/queuer/injectQueuer.d.ts
|
|
6
|
+
interface AngularQueuerOptions<TValue, TSelected = {}> extends QueuerOptions<TValue> {
|
|
7
|
+
/**
|
|
8
|
+
* Optional callback invoked when the component is destroyed. Receives the queuer instance.
|
|
9
|
+
* When provided, replaces the default cleanup (stop); use it to call flush(), stop(), add logging, etc.
|
|
10
|
+
*/
|
|
11
|
+
onUnmount?: (queuer: AngularQueuer<TValue, TSelected>) => void;
|
|
12
|
+
}
|
|
6
13
|
interface AngularQueuer<TValue, TSelected = {}> extends Omit<Queuer<TValue>, 'store'> {
|
|
7
14
|
/**
|
|
8
15
|
* Reactive state signal that will be updated when the queuer state changes
|
|
@@ -56,8 +63,20 @@ interface AngularQueuer<TValue, TSelected = {}> extends Omit<Queuer<TValue>, 'st
|
|
|
56
63
|
* // Access the selected state
|
|
57
64
|
* const { items, isRunning } = queue.state();
|
|
58
65
|
* ```
|
|
66
|
+
*
|
|
67
|
+
* ## Cleanup on Destroy
|
|
68
|
+
*
|
|
69
|
+
* By default, the function stops the queuer when the component is destroyed.
|
|
70
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending items instead:
|
|
71
|
+
*
|
|
72
|
+
* ```ts
|
|
73
|
+
* const queue = injectQueuer(fn, {
|
|
74
|
+
* started: true,
|
|
75
|
+
* onUnmount: (q) => q.flush()
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
59
78
|
*/
|
|
60
|
-
declare function injectQueuer<TValue, TSelected = {}>(fn: (item: TValue) => void, options?:
|
|
79
|
+
declare function injectQueuer<TValue, TSelected = {}>(fn: (item: TValue) => void, options?: AngularQueuerOptions<TValue, TSelected>, selector?: (state: QueuerState<TValue>) => TSelected): AngularQueuer<TValue, TSelected>;
|
|
61
80
|
//#endregion
|
|
62
|
-
export { AngularQueuer, injectQueuer };
|
|
81
|
+
export { AngularQueuer, AngularQueuerOptions, injectQueuer };
|
|
63
82
|
//# sourceMappingURL=injectQueuer.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { injectPacerOptions } from "../provider/pacer-context.js";
|
|
2
|
+
import { DestroyRef, inject } from "@angular/core";
|
|
2
3
|
import { injectStore } from "@tanstack/angular-store";
|
|
3
4
|
import { Queuer } from "@tanstack/pacer/queuer";
|
|
4
5
|
|
|
@@ -43,17 +44,35 @@ import { Queuer } from "@tanstack/pacer/queuer";
|
|
|
43
44
|
* // Access the selected state
|
|
44
45
|
* const { items, isRunning } = queue.state();
|
|
45
46
|
* ```
|
|
47
|
+
*
|
|
48
|
+
* ## Cleanup on Destroy
|
|
49
|
+
*
|
|
50
|
+
* By default, the function stops the queuer when the component is destroyed.
|
|
51
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending items instead:
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* const queue = injectQueuer(fn, {
|
|
55
|
+
* started: true,
|
|
56
|
+
* onUnmount: (q) => q.flush()
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
46
59
|
*/
|
|
47
60
|
function injectQueuer(fn, options = {}, selector = () => ({})) {
|
|
48
|
-
const
|
|
61
|
+
const mergedOptions = {
|
|
49
62
|
...injectPacerOptions().queuer,
|
|
50
63
|
...options
|
|
51
|
-
}
|
|
64
|
+
};
|
|
65
|
+
const queuer = new Queuer(fn, mergedOptions);
|
|
52
66
|
const state = injectStore(queuer.store, selector);
|
|
53
|
-
|
|
67
|
+
const result = {
|
|
54
68
|
...queuer,
|
|
55
69
|
state
|
|
56
70
|
};
|
|
71
|
+
inject(DestroyRef, { optional: true })?.onDestroy(() => {
|
|
72
|
+
if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
|
|
73
|
+
else queuer.stop();
|
|
74
|
+
});
|
|
75
|
+
return result;
|
|
57
76
|
}
|
|
58
77
|
|
|
59
78
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectQueuer.js","names":[],"sources":["../../src/queuer/injectQueuer.ts"],"sourcesContent":["import { injectStore } from '@tanstack/angular-store'\nimport { Queuer } from '@tanstack/pacer/queuer'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/store'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface AngularQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<QueuerState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages a Queuer instance.\n *\n * This is a lower-level function that provides direct access to the Queuer's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The Queuer processes items synchronously in order, with optional delays between processing each item.\n * The queuer includes an internal tick mechanism that can be started and stopped, making it useful as a scheduler.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const queue = injectQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 }\n * );\n *\n * // Opt-in to track queue contents changes\n * const queue = injectQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({ items: state.items, size: state.size })\n * );\n *\n * // Add items\n * queue.addItem('task1');\n *\n * // Access the selected state\n * const { items, isRunning } = queue.state();\n * ```\n */\nexport function injectQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options:
|
|
1
|
+
{"version":3,"file":"injectQueuer.js","names":[],"sources":["../../src/queuer/injectQueuer.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { Queuer } from '@tanstack/pacer/queuer'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface AngularQueuerOptions<\n TValue,\n TSelected = {},\n> extends QueuerOptions<TValue> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop); use it to call flush(), stop(), add logging, etc.\n */\n onUnmount?: (queuer: AngularQueuer<TValue, TSelected>) => void\n}\n\nexport interface AngularQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<QueuerState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages a Queuer instance.\n *\n * This is a lower-level function that provides direct access to the Queuer's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The Queuer processes items synchronously in order, with optional delays between processing each item.\n * The queuer includes an internal tick mechanism that can be started and stopped, making it useful as a scheduler.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const queue = injectQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 }\n * );\n *\n * // Opt-in to track queue contents changes\n * const queue = injectQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({ items: state.items, size: state.size })\n * );\n *\n * // Add items\n * queue.addItem('task1');\n *\n * // Access the selected state\n * const { items, isRunning } = queue.state();\n * ```\n *\n * ## Cleanup on Destroy\n *\n * By default, the function stops the queuer when the component is destroyed.\n * Use the `onUnmount` option to customize this. For example, to flush pending items instead:\n *\n * ```ts\n * const queue = injectQueuer(fn, {\n * started: true,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n */\nexport function injectQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: AngularQueuerOptions<TValue, TSelected> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): AngularQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().queuer,\n ...options,\n } as AngularQueuerOptions<TValue, TSelected>\n\n const queuer = new Queuer<TValue>(fn, mergedOptions)\n const state = injectStore(queuer.store, selector)\n\n const result = {\n ...queuer,\n state,\n } as AngularQueuer<TValue, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n queuer.stop()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,aACd,IACA,UAAmD,EAAE,EACrD,kBAA6D,EAAE,GAC7B;CAClC,MAAM,gBAAgB;EACpB,GAAG,oBAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,SAAS,IAAI,OAAe,IAAI,cAAc;CACpD,MAAM,QAAQ,YAAY,OAAO,OAAO,SAAS;CAEjD,MAAM,SAAS;EACb,GAAG;EACH;EACD;AAGD,CADmB,OAAO,YAAY,EAAE,UAAU,MAAM,CAAC,EAC7C,gBAAgB;AAC1B,MAAI,cAAc,UAChB,eAAc,UAAU,OAAO;MAE/B,QAAO,MAAM;GAEf;AAEF,QAAO"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { injectRateLimitedCallback } from "./injectRateLimitedCallback.cjs";
|
|
2
|
-
import { AngularRateLimiter, injectRateLimiter } from "./injectRateLimiter.cjs";
|
|
2
|
+
import { AngularRateLimiter, AngularRateLimiterOptions, injectRateLimiter } from "./injectRateLimiter.cjs";
|
|
3
3
|
import { RateLimitedSignal, injectRateLimitedSignal } from "./injectRateLimitedSignal.cjs";
|
|
4
4
|
import { injectRateLimitedValue } from "./injectRateLimitedValue.cjs";
|
|
5
5
|
export * from "@tanstack/pacer/rate-limiter";
|
|
6
|
-
export { AngularRateLimiter, RateLimitedSignal, injectRateLimitedCallback, injectRateLimitedSignal, injectRateLimitedValue, injectRateLimiter };
|
|
6
|
+
export { AngularRateLimiter, AngularRateLimiterOptions, RateLimitedSignal, injectRateLimitedCallback, injectRateLimitedSignal, injectRateLimitedValue, injectRateLimiter };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { injectRateLimitedCallback } from "./injectRateLimitedCallback.js";
|
|
2
|
-
import { AngularRateLimiter, injectRateLimiter } from "./injectRateLimiter.js";
|
|
2
|
+
import { AngularRateLimiter, AngularRateLimiterOptions, injectRateLimiter } from "./injectRateLimiter.js";
|
|
3
3
|
import { RateLimitedSignal, injectRateLimitedSignal } from "./injectRateLimitedSignal.js";
|
|
4
4
|
import { injectRateLimitedValue } from "./injectRateLimitedValue.js";
|
|
5
5
|
export * from "@tanstack/pacer/rate-limiter";
|
|
6
|
-
export { AngularRateLimiter, RateLimitedSignal, injectRateLimitedCallback, injectRateLimitedSignal, injectRateLimitedValue, injectRateLimiter };
|
|
6
|
+
export { AngularRateLimiter, AngularRateLimiterOptions, RateLimitedSignal, injectRateLimitedCallback, injectRateLimitedSignal, injectRateLimitedValue, injectRateLimiter };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_pacer_context = require('../provider/pacer-context.cjs');
|
|
2
|
+
let _angular_core = require("@angular/core");
|
|
2
3
|
let _tanstack_angular_store = require("@tanstack/angular-store");
|
|
3
4
|
let _tanstack_pacer_rate_limiter = require("@tanstack/pacer/rate-limiter");
|
|
4
5
|
|
|
@@ -39,6 +40,10 @@ let _tanstack_pacer_rate_limiter = require("@tanstack/pacer/rate-limiter");
|
|
|
39
40
|
* - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations
|
|
40
41
|
* - `rejectionCount`: Number of function executions that have been rejected due to rate limiting
|
|
41
42
|
*
|
|
43
|
+
* ## Cleanup on Destroy
|
|
44
|
+
*
|
|
45
|
+
* Use the `onUnmount` option to run a callback when the component is destroyed.
|
|
46
|
+
*
|
|
42
47
|
* @example
|
|
43
48
|
* ```ts
|
|
44
49
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -74,15 +79,20 @@ let _tanstack_pacer_rate_limiter = require("@tanstack/pacer/rate-limiter");
|
|
|
74
79
|
* ```
|
|
75
80
|
*/
|
|
76
81
|
function injectRateLimiter(fn, options, selector = () => ({})) {
|
|
77
|
-
const
|
|
82
|
+
const mergedOptions = {
|
|
78
83
|
...require_pacer_context.injectPacerOptions().rateLimiter,
|
|
79
84
|
...options
|
|
80
|
-
}
|
|
85
|
+
};
|
|
86
|
+
const rateLimiter = new _tanstack_pacer_rate_limiter.RateLimiter(fn, mergedOptions);
|
|
81
87
|
const state = (0, _tanstack_angular_store.injectStore)(rateLimiter.store, selector);
|
|
82
|
-
|
|
88
|
+
const result = {
|
|
83
89
|
...rateLimiter,
|
|
84
90
|
state
|
|
85
91
|
};
|
|
92
|
+
(0, _angular_core.inject)(_angular_core.DestroyRef, { optional: true })?.onDestroy(() => {
|
|
93
|
+
if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
|
|
94
|
+
});
|
|
95
|
+
return result;
|
|
86
96
|
}
|
|
87
97
|
|
|
88
98
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectRateLimiter.cjs","names":["RateLimiter","
|
|
1
|
+
{"version":3,"file":"injectRateLimiter.cjs","names":["injectPacerOptions","RateLimiter","DestroyRef"],"sources":["../../src/rate-limiter/injectRateLimiter.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\nexport interface AngularRateLimiterOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends RateLimiterOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the rate limiter instance.\n */\n onUnmount?: (rateLimiter: AngularRateLimiter<TFn, TSelected>) => void\n}\n\nexport interface AngularRateLimiter<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<RateLimiter<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<RateLimiterState>>\n}\n\n/**\n * An Angular function that creates and manages a RateLimiter instance.\n *\n * This is a lower-level function that provides direct access to the RateLimiter's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * Rate limiting is a simple \"hard limit\" approach that allows executions until a maximum count is reached within\n * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,\n * it does not attempt to space out or collapse executions intelligently.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n * consistent rate of execution over time.\n *\n * For smoother execution patterns:\n * - Use throttling when you want consistent spacing between executions (e.g. UI updates)\n * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)\n * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations\n * - `rejectionCount`: Number of function executions that have been rejected due to rate limiting\n *\n * ## Cleanup on Destroy\n *\n * Use the `onUnmount` option to run a callback when the component is destroyed.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = injectRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * });\n *\n * // Opt-in to track execution count changes\n * const rateLimiter = injectRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Monitor rate limit status\n * const handleClick = () => {\n * const remaining = rateLimiter.getRemainingInWindow();\n * if (remaining > 0) {\n * rateLimiter.maybeExecute(data);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { executionCount, rejectionCount } = rateLimiter.state();\n * ```\n */\nexport function injectRateLimiter<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: AngularRateLimiterOptions<TFn, TSelected>,\n selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,\n): AngularRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().rateLimiter,\n ...options,\n } as AngularRateLimiterOptions<TFn, TSelected>\n\n const rateLimiter = new RateLimiter<TFn>(fn, mergedOptions)\n const state = injectStore(rateLimiter.store, selector)\n\n const result = {\n ...rateLimiter,\n state,\n } as AngularRateLimiter<TFn, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiHA,SAAgB,kBACd,IACA,SACA,kBAA0D,EAAE,GACxB;CACpC,MAAM,gBAAgB;EACpB,GAAGA,0CAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,cAAc,IAAIC,yCAAiB,IAAI,cAAc;CAC3D,MAAM,iDAAoB,YAAY,OAAO,SAAS;CAEtD,MAAM,SAAS;EACb,GAAG;EACH;EACD;AAGD,2BAD0BC,0BAAY,EAAE,UAAU,MAAM,CAAC,EAC7C,gBAAgB;AAC1B,MAAI,cAAc,UAChB,eAAc,UAAU,OAAO;GAEjC;AAEF,QAAO"}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { Signal } from "@angular/core";
|
|
2
|
-
import { Store } from "@tanstack/store";
|
|
2
|
+
import { Store } from "@tanstack/angular-store";
|
|
3
3
|
import { AnyFunction } from "@tanstack/pacer/types";
|
|
4
4
|
import { RateLimiter, RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
5
5
|
|
|
6
6
|
//#region src/rate-limiter/injectRateLimiter.d.ts
|
|
7
|
+
interface AngularRateLimiterOptions<TFn extends AnyFunction, TSelected = {}> extends RateLimiterOptions<TFn> {
|
|
8
|
+
/**
|
|
9
|
+
* Optional callback invoked when the component is destroyed. Receives the rate limiter instance.
|
|
10
|
+
*/
|
|
11
|
+
onUnmount?: (rateLimiter: AngularRateLimiter<TFn, TSelected>) => void;
|
|
12
|
+
}
|
|
7
13
|
interface AngularRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Omit<RateLimiter<TFn>, 'store'> {
|
|
8
14
|
/**
|
|
9
15
|
* Reactive state signal that will be updated when the rate limiter state changes
|
|
@@ -53,6 +59,10 @@ interface AngularRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Om
|
|
|
53
59
|
* - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations
|
|
54
60
|
* - `rejectionCount`: Number of function executions that have been rejected due to rate limiting
|
|
55
61
|
*
|
|
62
|
+
* ## Cleanup on Destroy
|
|
63
|
+
*
|
|
64
|
+
* Use the `onUnmount` option to run a callback when the component is destroyed.
|
|
65
|
+
*
|
|
56
66
|
* @example
|
|
57
67
|
* ```ts
|
|
58
68
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -87,7 +97,7 @@ interface AngularRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Om
|
|
|
87
97
|
* const { executionCount, rejectionCount } = rateLimiter.state();
|
|
88
98
|
* ```
|
|
89
99
|
*/
|
|
90
|
-
declare function injectRateLimiter<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options:
|
|
100
|
+
declare function injectRateLimiter<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: AngularRateLimiterOptions<TFn, TSelected>, selector?: (state: RateLimiterState) => TSelected): AngularRateLimiter<TFn, TSelected>;
|
|
91
101
|
//#endregion
|
|
92
|
-
export { AngularRateLimiter, injectRateLimiter };
|
|
102
|
+
export { AngularRateLimiter, AngularRateLimiterOptions, injectRateLimiter };
|
|
93
103
|
//# sourceMappingURL=injectRateLimiter.d.cts.map
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { Signal } from "@angular/core";
|
|
2
|
+
import { Store } from "@tanstack/angular-store";
|
|
2
3
|
import { RateLimiter, RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
3
4
|
import { AnyFunction } from "@tanstack/pacer/types";
|
|
4
|
-
import { Store } from "@tanstack/store";
|
|
5
5
|
|
|
6
6
|
//#region src/rate-limiter/injectRateLimiter.d.ts
|
|
7
|
+
interface AngularRateLimiterOptions<TFn extends AnyFunction, TSelected = {}> extends RateLimiterOptions<TFn> {
|
|
8
|
+
/**
|
|
9
|
+
* Optional callback invoked when the component is destroyed. Receives the rate limiter instance.
|
|
10
|
+
*/
|
|
11
|
+
onUnmount?: (rateLimiter: AngularRateLimiter<TFn, TSelected>) => void;
|
|
12
|
+
}
|
|
7
13
|
interface AngularRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Omit<RateLimiter<TFn>, 'store'> {
|
|
8
14
|
/**
|
|
9
15
|
* Reactive state signal that will be updated when the rate limiter state changes
|
|
@@ -53,6 +59,10 @@ interface AngularRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Om
|
|
|
53
59
|
* - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations
|
|
54
60
|
* - `rejectionCount`: Number of function executions that have been rejected due to rate limiting
|
|
55
61
|
*
|
|
62
|
+
* ## Cleanup on Destroy
|
|
63
|
+
*
|
|
64
|
+
* Use the `onUnmount` option to run a callback when the component is destroyed.
|
|
65
|
+
*
|
|
56
66
|
* @example
|
|
57
67
|
* ```ts
|
|
58
68
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -87,7 +97,7 @@ interface AngularRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Om
|
|
|
87
97
|
* const { executionCount, rejectionCount } = rateLimiter.state();
|
|
88
98
|
* ```
|
|
89
99
|
*/
|
|
90
|
-
declare function injectRateLimiter<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options:
|
|
100
|
+
declare function injectRateLimiter<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: AngularRateLimiterOptions<TFn, TSelected>, selector?: (state: RateLimiterState) => TSelected): AngularRateLimiter<TFn, TSelected>;
|
|
91
101
|
//#endregion
|
|
92
|
-
export { AngularRateLimiter, injectRateLimiter };
|
|
102
|
+
export { AngularRateLimiter, AngularRateLimiterOptions, injectRateLimiter };
|
|
93
103
|
//# sourceMappingURL=injectRateLimiter.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { injectPacerOptions } from "../provider/pacer-context.js";
|
|
2
|
+
import { DestroyRef, inject } from "@angular/core";
|
|
2
3
|
import { injectStore } from "@tanstack/angular-store";
|
|
3
4
|
import { RateLimiter } from "@tanstack/pacer/rate-limiter";
|
|
4
5
|
|
|
@@ -39,6 +40,10 @@ import { RateLimiter } from "@tanstack/pacer/rate-limiter";
|
|
|
39
40
|
* - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations
|
|
40
41
|
* - `rejectionCount`: Number of function executions that have been rejected due to rate limiting
|
|
41
42
|
*
|
|
43
|
+
* ## Cleanup on Destroy
|
|
44
|
+
*
|
|
45
|
+
* Use the `onUnmount` option to run a callback when the component is destroyed.
|
|
46
|
+
*
|
|
42
47
|
* @example
|
|
43
48
|
* ```ts
|
|
44
49
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -74,15 +79,20 @@ import { RateLimiter } from "@tanstack/pacer/rate-limiter";
|
|
|
74
79
|
* ```
|
|
75
80
|
*/
|
|
76
81
|
function injectRateLimiter(fn, options, selector = () => ({})) {
|
|
77
|
-
const
|
|
82
|
+
const mergedOptions = {
|
|
78
83
|
...injectPacerOptions().rateLimiter,
|
|
79
84
|
...options
|
|
80
|
-
}
|
|
85
|
+
};
|
|
86
|
+
const rateLimiter = new RateLimiter(fn, mergedOptions);
|
|
81
87
|
const state = injectStore(rateLimiter.store, selector);
|
|
82
|
-
|
|
88
|
+
const result = {
|
|
83
89
|
...rateLimiter,
|
|
84
90
|
state
|
|
85
91
|
};
|
|
92
|
+
inject(DestroyRef, { optional: true })?.onDestroy(() => {
|
|
93
|
+
if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
|
|
94
|
+
});
|
|
95
|
+
return result;
|
|
86
96
|
}
|
|
87
97
|
|
|
88
98
|
//#endregion
|