@tanstack/angular-pacer 0.20.0 → 0.22.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/README.md +7 -7
- 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/injectAsyncQueuedSignal.cjs.map +1 -1
- package/dist/async-queuer/injectAsyncQueuedSignal.d.cts +5 -10
- package/dist/async-queuer/injectAsyncQueuedSignal.d.ts +5 -10
- package/dist/async-queuer/injectAsyncQueuedSignal.js.map +1 -1
- 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/injectDebouncedSignal.cjs.map +1 -1
- package/dist/debouncer/injectDebouncedSignal.d.cts +5 -10
- package/dist/debouncer/injectDebouncedSignal.d.ts +5 -10
- package/dist/debouncer/injectDebouncedSignal.js.map +1 -1
- 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/injectQueuedSignal.cjs.map +1 -1
- package/dist/queuer/injectQueuedSignal.d.cts +5 -10
- package/dist/queuer/injectQueuedSignal.d.ts +5 -10
- package/dist/queuer/injectQueuedSignal.js.map +1 -1
- 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/injectRateLimitedSignal.cjs.map +1 -1
- package/dist/rate-limiter/injectRateLimitedSignal.d.cts +5 -10
- package/dist/rate-limiter/injectRateLimitedSignal.d.ts +5 -10
- package/dist/rate-limiter/injectRateLimitedSignal.js.map +1 -1
- 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/injectThrottledSignal.cjs.map +1 -1
- package/dist/throttler/injectThrottledSignal.d.cts +5 -10
- package/dist/throttler/injectThrottledSignal.d.ts +5 -10
- package/dist/throttler/injectThrottledSignal.js.map +1 -1
- 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/injectAsyncQueuedSignal.ts +4 -12
- 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/injectDebouncedSignal.ts +4 -11
- package/src/debouncer/injectDebouncer.ts +39 -4
- package/src/queuer/injectQueuedSignal.ts +4 -9
- package/src/queuer/injectQueuer.ts +39 -4
- package/src/rate-limiter/injectRateLimitedSignal.ts +4 -11
- package/src/rate-limiter/injectRateLimiter.ts +28 -4
- package/src/throttler/injectThrottledSignal.ts +4 -11
- package/src/throttler/injectThrottler.ts +39 -4
|
@@ -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_debouncer = require("@tanstack/pacer/debouncer");
|
|
4
5
|
|
|
@@ -34,6 +35,18 @@ let _tanstack_pacer_debouncer = require("@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 @@ let _tanstack_pacer_debouncer = require("@tanstack/pacer/debouncer");
|
|
|
60
73
|
* ```
|
|
61
74
|
*/
|
|
62
75
|
function injectDebouncer(fn, options, selector = () => ({})) {
|
|
63
|
-
const
|
|
76
|
+
const mergedOptions = {
|
|
64
77
|
...require_pacer_context.injectPacerOptions().debouncer,
|
|
65
78
|
...options
|
|
66
|
-
}
|
|
79
|
+
};
|
|
80
|
+
const debouncer = new _tanstack_pacer_debouncer.Debouncer(fn, mergedOptions);
|
|
67
81
|
const state = (0, _tanstack_angular_store.injectStore)(debouncer.store, selector);
|
|
68
|
-
|
|
82
|
+
const result = {
|
|
69
83
|
...debouncer,
|
|
70
84
|
state
|
|
71
85
|
};
|
|
86
|
+
(0, _angular_core.inject)(_angular_core.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.cjs","names":["Debouncer","
|
|
1
|
+
{"version":3,"file":"injectDebouncer.cjs","names":["injectPacerOptions","Debouncer","DestroyRef"],"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,GAAGA,0CAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,YAAY,IAAIC,oCAAe,IAAI,cAAc;CACvD,MAAM,iDAAoB,UAAU,OAAO,SAAS;CAEpD,MAAM,SAAS;EACb,GAAG;EACH;EACD;AAGD,2BAD0BC,0BAAY,EAAE,UAAU,MAAM,CAAC,EAC7C,gBAAgB;AAC1B,MAAI,cAAc,UAChB,eAAc,UAAU,OAAO;MAE/B,WAAU,QAAQ;GAEpB;AAEF,QAAO"}
|
|
@@ -1,9 +1,16 @@
|
|
|
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 { Debouncer, DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
|
|
5
5
|
|
|
6
6
|
//#region src/debouncer/injectDebouncer.d.ts
|
|
7
|
+
interface AngularDebouncerOptions<TFn extends AnyFunction, TSelected = {}> extends DebouncerOptions<TFn> {
|
|
8
|
+
/**
|
|
9
|
+
* Optional callback invoked when the component is destroyed. Receives the debouncer instance.
|
|
10
|
+
* When provided, replaces the default cleanup (cancel); use it to call flush(), cancel(), add logging, etc.
|
|
11
|
+
*/
|
|
12
|
+
onUnmount?: (debouncer: AngularDebouncer<TFn, TSelected>) => void;
|
|
13
|
+
}
|
|
7
14
|
interface AngularDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<Debouncer<TFn>, 'store'> {
|
|
8
15
|
/**
|
|
9
16
|
* Reactive state signal that will be updated when the debouncer state changes
|
|
@@ -48,6 +55,18 @@ interface AngularDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit
|
|
|
48
55
|
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
49
56
|
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
50
57
|
*
|
|
58
|
+
* ## Cleanup on Destroy
|
|
59
|
+
*
|
|
60
|
+
* By default, the function cancels any pending execution when the component is destroyed.
|
|
61
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
62
|
+
*
|
|
63
|
+
* ```ts
|
|
64
|
+
* const debouncer = injectDebouncer(fn, {
|
|
65
|
+
* wait: 500,
|
|
66
|
+
* onUnmount: (d) => d.flush()
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
51
70
|
* @example
|
|
52
71
|
* ```ts
|
|
53
72
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -73,7 +92,7 @@ interface AngularDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit
|
|
|
73
92
|
* const { isPending } = debouncer.state();
|
|
74
93
|
* ```
|
|
75
94
|
*/
|
|
76
|
-
declare function injectDebouncer<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options:
|
|
95
|
+
declare function injectDebouncer<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: AngularDebouncerOptions<TFn, TSelected>, selector?: (state: DebouncerState<TFn>) => TSelected): AngularDebouncer<TFn, TSelected>;
|
|
77
96
|
//#endregion
|
|
78
|
-
export { AngularDebouncer, injectDebouncer };
|
|
97
|
+
export { AngularDebouncer, AngularDebouncerOptions, injectDebouncer };
|
|
79
98
|
//# sourceMappingURL=injectDebouncer.d.cts.map
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { Signal } from "@angular/core";
|
|
2
|
+
import { Store } from "@tanstack/angular-store";
|
|
2
3
|
import { Debouncer, DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
|
|
3
4
|
import { AnyFunction } from "@tanstack/pacer/types";
|
|
4
|
-
import { Store } from "@tanstack/store";
|
|
5
5
|
|
|
6
6
|
//#region src/debouncer/injectDebouncer.d.ts
|
|
7
|
+
interface AngularDebouncerOptions<TFn extends AnyFunction, TSelected = {}> extends DebouncerOptions<TFn> {
|
|
8
|
+
/**
|
|
9
|
+
* Optional callback invoked when the component is destroyed. Receives the debouncer instance.
|
|
10
|
+
* When provided, replaces the default cleanup (cancel); use it to call flush(), cancel(), add logging, etc.
|
|
11
|
+
*/
|
|
12
|
+
onUnmount?: (debouncer: AngularDebouncer<TFn, TSelected>) => void;
|
|
13
|
+
}
|
|
7
14
|
interface AngularDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<Debouncer<TFn>, 'store'> {
|
|
8
15
|
/**
|
|
9
16
|
* Reactive state signal that will be updated when the debouncer state changes
|
|
@@ -48,6 +55,18 @@ interface AngularDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit
|
|
|
48
55
|
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
49
56
|
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
50
57
|
*
|
|
58
|
+
* ## Cleanup on Destroy
|
|
59
|
+
*
|
|
60
|
+
* By default, the function cancels any pending execution when the component is destroyed.
|
|
61
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
62
|
+
*
|
|
63
|
+
* ```ts
|
|
64
|
+
* const debouncer = injectDebouncer(fn, {
|
|
65
|
+
* wait: 500,
|
|
66
|
+
* onUnmount: (d) => d.flush()
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
51
70
|
* @example
|
|
52
71
|
* ```ts
|
|
53
72
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -73,7 +92,7 @@ interface AngularDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit
|
|
|
73
92
|
* const { isPending } = debouncer.state();
|
|
74
93
|
* ```
|
|
75
94
|
*/
|
|
76
|
-
declare function injectDebouncer<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options:
|
|
95
|
+
declare function injectDebouncer<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: AngularDebouncerOptions<TFn, TSelected>, selector?: (state: DebouncerState<TFn>) => TSelected): AngularDebouncer<TFn, TSelected>;
|
|
77
96
|
//#endregion
|
|
78
|
-
export { AngularDebouncer, injectDebouncer };
|
|
97
|
+
export { AngularDebouncer, AngularDebouncerOptions, injectDebouncer };
|
|
79
98
|
//# sourceMappingURL=injectDebouncer.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 { 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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectQueuedSignal.cjs","names":["injectQueuer"],"sources":["../../src/queuer/injectQueuedSignal.ts"],"sourcesContent":["import { computed } from '@angular/core'\nimport { injectQueuer } from './injectQueuer'\nimport type { AngularQueuer } from './injectQueuer'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport
|
|
1
|
+
{"version":3,"file":"injectQueuedSignal.cjs","names":["injectQueuer"],"sources":["../../src/queuer/injectQueuedSignal.ts"],"sourcesContent":["import { computed } from '@angular/core'\nimport { injectQueuer } from './injectQueuer'\nimport type { AngularQueuer } from './injectQueuer'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface QueuedSignal<TValue, TSelected = {}> {\n (): Array<TValue>\n addItem: AngularQueuer<TValue, TSelected>['addItem']\n queuer: AngularQueuer<TValue, TSelected>\n}\n\n/**\n * An Angular function that creates a queuer with managed state, combining Angular's signals with queuing functionality.\n * This function provides both the current queue state and queue control methods.\n *\n * The queue state is automatically updated whenever items are added, removed, or reordered in the queue.\n * All queue operations are reflected in the state array returned by the function.\n *\n * The function returns a callable object:\n * - `queued()`: Get the current queue items as an array\n * - `queued.addItem(...)`: Add an item to the queue\n * - `queued.queue`: The queuer instance with additional control methods\n *\n * @example\n * ```ts\n * // Default behavior - track items\n * const queued = injectQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 }\n * );\n *\n * // Add items\n * queued.addItem('task1');\n *\n * // Access items\n * console.log(queued()); // ['task1']\n *\n * // Control the queue\n * queued.queuer.start();\n * queued.queuer.stop();\n * ```\n */\nexport function injectQueuedSignal<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (item: TValue) => void,\n options: QueuerOptions<TValue> = {},\n selector: (state: QueuerState<TValue>) => TSelected = (state) =>\n ({ items: state.items }) as TSelected,\n): QueuedSignal<TValue, TSelected> {\n const queuer = injectQueuer(fn, options, selector)\n\n const items = computed(() => queuer.state().items as Array<TValue>)\n\n const queued = Object.assign(items, {\n addItem: queuer.addItem.bind(queuer),\n queuer,\n }) as QueuedSignal<TValue, TSelected>\n\n return queued\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,mBAOd,IACA,UAAiC,EAAE,EACnC,YAAuD,WACpD,EAAE,OAAO,MAAM,OAAO,GACQ;CACjC,MAAM,SAASA,kCAAa,IAAI,SAAS,SAAS;CAElD,MAAM,0CAAuB,OAAO,OAAO,CAAC,MAAuB;AAOnE,QALe,OAAO,OAAO,OAAO;EAClC,SAAS,OAAO,QAAQ,KAAK,OAAO;EACpC;EACD,CAAC"}
|
|
@@ -2,16 +2,11 @@ import { AngularQueuer } from "./injectQueuer.cjs";
|
|
|
2
2
|
import { QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
|
|
3
3
|
|
|
4
4
|
//#region src/queuer/injectQueuedSignal.d.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* The queuer instance with additional control methods and state signals.
|
|
12
|
-
*/
|
|
13
|
-
readonly queuer: AngularQueuer<TValue, TSelected>;
|
|
14
|
-
};
|
|
5
|
+
interface QueuedSignal<TValue, TSelected = {}> {
|
|
6
|
+
(): Array<TValue>;
|
|
7
|
+
addItem: AngularQueuer<TValue, TSelected>['addItem'];
|
|
8
|
+
queuer: AngularQueuer<TValue, TSelected>;
|
|
9
|
+
}
|
|
15
10
|
/**
|
|
16
11
|
* An Angular function that creates a queuer with managed state, combining Angular's signals with queuing functionality.
|
|
17
12
|
* This function provides both the current queue state and queue control methods.
|
|
@@ -2,16 +2,11 @@ import { AngularQueuer } from "./injectQueuer.js";
|
|
|
2
2
|
import { QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
|
|
3
3
|
|
|
4
4
|
//#region src/queuer/injectQueuedSignal.d.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* The queuer instance with additional control methods and state signals.
|
|
12
|
-
*/
|
|
13
|
-
readonly queuer: AngularQueuer<TValue, TSelected>;
|
|
14
|
-
};
|
|
5
|
+
interface QueuedSignal<TValue, TSelected = {}> {
|
|
6
|
+
(): Array<TValue>;
|
|
7
|
+
addItem: AngularQueuer<TValue, TSelected>['addItem'];
|
|
8
|
+
queuer: AngularQueuer<TValue, TSelected>;
|
|
9
|
+
}
|
|
15
10
|
/**
|
|
16
11
|
* An Angular function that creates a queuer with managed state, combining Angular's signals with queuing functionality.
|
|
17
12
|
* This function provides both the current queue state and queue control methods.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectQueuedSignal.js","names":[],"sources":["../../src/queuer/injectQueuedSignal.ts"],"sourcesContent":["import { computed } from '@angular/core'\nimport { injectQueuer } from './injectQueuer'\nimport type { AngularQueuer } from './injectQueuer'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport
|
|
1
|
+
{"version":3,"file":"injectQueuedSignal.js","names":[],"sources":["../../src/queuer/injectQueuedSignal.ts"],"sourcesContent":["import { computed } from '@angular/core'\nimport { injectQueuer } from './injectQueuer'\nimport type { AngularQueuer } from './injectQueuer'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface QueuedSignal<TValue, TSelected = {}> {\n (): Array<TValue>\n addItem: AngularQueuer<TValue, TSelected>['addItem']\n queuer: AngularQueuer<TValue, TSelected>\n}\n\n/**\n * An Angular function that creates a queuer with managed state, combining Angular's signals with queuing functionality.\n * This function provides both the current queue state and queue control methods.\n *\n * The queue state is automatically updated whenever items are added, removed, or reordered in the queue.\n * All queue operations are reflected in the state array returned by the function.\n *\n * The function returns a callable object:\n * - `queued()`: Get the current queue items as an array\n * - `queued.addItem(...)`: Add an item to the queue\n * - `queued.queue`: The queuer instance with additional control methods\n *\n * @example\n * ```ts\n * // Default behavior - track items\n * const queued = injectQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 }\n * );\n *\n * // Add items\n * queued.addItem('task1');\n *\n * // Access items\n * console.log(queued()); // ['task1']\n *\n * // Control the queue\n * queued.queuer.start();\n * queued.queuer.stop();\n * ```\n */\nexport function injectQueuedSignal<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (item: TValue) => void,\n options: QueuerOptions<TValue> = {},\n selector: (state: QueuerState<TValue>) => TSelected = (state) =>\n ({ items: state.items }) as TSelected,\n): QueuedSignal<TValue, TSelected> {\n const queuer = injectQueuer(fn, options, selector)\n\n const items = computed(() => queuer.state().items as Array<TValue>)\n\n const queued = Object.assign(items, {\n addItem: queuer.addItem.bind(queuer),\n queuer,\n }) as QueuedSignal<TValue, TSelected>\n\n return queued\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,mBAOd,IACA,UAAiC,EAAE,EACnC,YAAuD,WACpD,EAAE,OAAO,MAAM,OAAO,GACQ;CACjC,MAAM,SAAS,aAAa,IAAI,SAAS,SAAS;CAElD,MAAM,QAAQ,eAAe,OAAO,OAAO,CAAC,MAAuB;AAOnE,QALe,OAAO,OAAO,OAAO;EAClC,SAAS,OAAO,QAAQ,KAAK,OAAO;EACpC;EACD,CAAC"}
|
|
@@ -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
|