@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Tanner Linsley
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -106,21 +106,21 @@ A lightweight timing and scheduling library for debouncing, throttling, rate lim
|
|
|
106
106
|
|
|
107
107
|
<table align="center">
|
|
108
108
|
<tr>
|
|
109
|
-
|
|
109
|
+
<td>
|
|
110
110
|
<a href="https://www.coderabbit.ai/?via=tanstack&dub_id=aCcEEdAOqqutX6OS" >
|
|
111
111
|
<picture>
|
|
112
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/coderabbit-dark-
|
|
113
|
-
<source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/coderabbit-light-
|
|
114
|
-
<img src="https://tanstack.com/assets/coderabbit-light-
|
|
112
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/coderabbit-dark-D643Zkrv.svg" />
|
|
113
|
+
<source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/coderabbit-light-CIzGLYU_.svg" />
|
|
114
|
+
<img src="https://tanstack.com/assets/coderabbit-light-CIzGLYU_.svg" height="40" alt="CodeRabbit" />
|
|
115
115
|
</picture>
|
|
116
116
|
</a>
|
|
117
117
|
</td>
|
|
118
118
|
<td>
|
|
119
119
|
<a href="https://www.cloudflare.com?utm_source=tanstack">
|
|
120
120
|
<picture>
|
|
121
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/cloudflare-white-
|
|
122
|
-
<source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/cloudflare-black-
|
|
123
|
-
<img src="https://tanstack.com/assets/cloudflare-
|
|
121
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/cloudflare-white-Co-Tyjbl.svg" />
|
|
122
|
+
<source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/cloudflare-black-6Ojsn8yh.svg" />
|
|
123
|
+
<img src="https://tanstack.com/assets/cloudflare-white-Co-Tyjbl.svg" height="60" alt="Cloudflare" />
|
|
124
124
|
</picture>
|
|
125
125
|
</a>
|
|
126
126
|
</td>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { injectAsyncBatchedCallback } from "./injectAsyncBatchedCallback.cjs";
|
|
2
|
-
import { AngularAsyncBatcher, injectAsyncBatcher } from "./injectAsyncBatcher.cjs";
|
|
2
|
+
import { AngularAsyncBatcher, AngularAsyncBatcherOptions, injectAsyncBatcher } from "./injectAsyncBatcher.cjs";
|
|
3
3
|
export * from "@tanstack/pacer/async-batcher";
|
|
4
|
-
export { AngularAsyncBatcher, injectAsyncBatchedCallback, injectAsyncBatcher };
|
|
4
|
+
export { AngularAsyncBatcher, AngularAsyncBatcherOptions, injectAsyncBatchedCallback, injectAsyncBatcher };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { injectAsyncBatchedCallback } from "./injectAsyncBatchedCallback.js";
|
|
2
|
-
import { AngularAsyncBatcher, injectAsyncBatcher } from "./injectAsyncBatcher.js";
|
|
2
|
+
import { AngularAsyncBatcher, AngularAsyncBatcherOptions, injectAsyncBatcher } from "./injectAsyncBatcher.js";
|
|
3
3
|
export * from "@tanstack/pacer/async-batcher";
|
|
4
|
-
export { AngularAsyncBatcher, injectAsyncBatchedCallback, injectAsyncBatcher };
|
|
4
|
+
export { AngularAsyncBatcher, AngularAsyncBatcherOptions, injectAsyncBatchedCallback, injectAsyncBatcher };
|
|
@@ -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_async_batcher = require("@tanstack/pacer/async-batcher");
|
|
4
5
|
|
|
@@ -22,6 +23,20 @@ let _tanstack_pacer_async_batcher = require("@tanstack/pacer/async-batcher");
|
|
|
22
23
|
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
23
24
|
* full control over when your component tracks state changes.
|
|
24
25
|
*
|
|
26
|
+
* ## Cleanup on Destroy
|
|
27
|
+
*
|
|
28
|
+
* By default, the function cancels any pending batch and aborts in-flight work when the component is destroyed.
|
|
29
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const batcher = injectAsyncBatcher(fn, {
|
|
33
|
+
* maxSize: 10,
|
|
34
|
+
* onUnmount: (b) => b.flush()
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
|
|
39
|
+
*
|
|
25
40
|
* @example
|
|
26
41
|
* ```ts
|
|
27
42
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -45,15 +60,24 @@ let _tanstack_pacer_async_batcher = require("@tanstack/pacer/async-batcher");
|
|
|
45
60
|
* ```
|
|
46
61
|
*/
|
|
47
62
|
function injectAsyncBatcher(fn, options = {}, selector = () => ({})) {
|
|
48
|
-
const
|
|
63
|
+
const mergedOptions = {
|
|
49
64
|
...require_pacer_context.injectPacerOptions().asyncBatcher,
|
|
50
65
|
...options
|
|
51
|
-
}
|
|
66
|
+
};
|
|
67
|
+
const batcher = new _tanstack_pacer_async_batcher.AsyncBatcher(fn, mergedOptions);
|
|
52
68
|
const state = (0, _tanstack_angular_store.injectStore)(batcher.store, selector);
|
|
53
|
-
|
|
69
|
+
const result = {
|
|
54
70
|
...batcher,
|
|
55
71
|
state
|
|
56
72
|
};
|
|
73
|
+
(0, _angular_core.inject)(_angular_core.DestroyRef, { optional: true })?.onDestroy(() => {
|
|
74
|
+
if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
|
|
75
|
+
else {
|
|
76
|
+
batcher.cancel();
|
|
77
|
+
batcher.abort();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return result;
|
|
57
81
|
}
|
|
58
82
|
|
|
59
83
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectAsyncBatcher.cjs","names":["AsyncBatcher","
|
|
1
|
+
{"version":3,"file":"injectAsyncBatcher.cjs","names":["injectPacerOptions","AsyncBatcher","DestroyRef"],"sources":["../../src/async-batcher/injectAsyncBatcher.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { AsyncBatcher } from '@tanstack/pacer/async-batcher'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type {\n AsyncBatcherOptions,\n AsyncBatcherState,\n} from '@tanstack/pacer/async-batcher'\n\nexport interface AngularAsyncBatcherOptions<\n TValue,\n TSelected = {},\n> extends AsyncBatcherOptions<TValue> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the batcher instance.\n * When provided, replaces the default cleanup (cancel + abort); use it to call flush(), cancel(), add logging, etc.\n * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.\n */\n onUnmount?: (batcher: AngularAsyncBatcher<TValue, TSelected>) => void\n}\n\nexport interface AngularAsyncBatcher<TValue, TSelected = {}> extends Omit<\n AsyncBatcher<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the async batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.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<AsyncBatcherState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncBatcher instance.\n *\n * This is a lower-level function that provides direct access to the AsyncBatcher's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The AsyncBatcher collects items and processes them in batches asynchronously with support for\n * promise-based processing, error handling, retry capabilities, and abort support.\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 * ## Cleanup on Destroy\n *\n * By default, the function cancels any pending batch and aborts in-flight work 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 batcher = injectAsyncBatcher(fn, {\n * maxSize: 10,\n * onUnmount: (b) => b.flush()\n * });\n * ```\n *\n * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const batcher = injectAsyncBatcher(\n * async (items: Array<Data>) => {\n * const response = await fetch('/api/batch', {\n * method: 'POST',\n * body: JSON.stringify(items)\n * });\n * return response.json();\n * },\n * { maxSize: 10, wait: 2000 }\n * );\n *\n * // Add items\n * batcher.addItem(data1);\n * batcher.addItem(data2);\n *\n * // Access the selected state\n * const { items, isExecuting } = batcher.state();\n * ```\n */\nexport function injectAsyncBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => Promise<any>,\n options: AngularAsyncBatcherOptions<TValue, TSelected> = {},\n selector: (state: AsyncBatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncBatcher,\n ...options,\n } as AngularAsyncBatcherOptions<TValue, TSelected>\n\n const batcher = new AsyncBatcher<TValue>(fn, mergedOptions)\n const state = injectStore(batcher.store, selector)\n\n const result = {\n ...batcher,\n state,\n } as AngularAsyncBatcher<TValue, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n batcher.cancel()\n batcher.abort()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FA,SAAgB,mBACd,IACA,UAAyD,EAAE,EAC3D,kBACG,EAAE,GACmC;CACxC,MAAM,gBAAgB;EACpB,GAAGA,0CAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,UAAU,IAAIC,2CAAqB,IAAI,cAAc;CAC3D,MAAM,iDAAoB,QAAQ,OAAO,SAAS;CAElD,MAAM,SAAS;EACb,GAAG;EACH;EACD;AAGD,2BAD0BC,0BAAY,EAAE,UAAU,MAAM,CAAC,EAC7C,gBAAgB;AAC1B,MAAI,cAAc,UAChB,eAAc,UAAU,OAAO;OAC1B;AACL,WAAQ,QAAQ;AAChB,WAAQ,OAAO;;GAEjB;AAEF,QAAO"}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { AsyncBatcher, AsyncBatcherOptions, AsyncBatcherState } from "@tanstack/pacer/async-batcher";
|
|
2
2
|
import { Signal } from "@angular/core";
|
|
3
|
-
import { Store } from "@tanstack/store";
|
|
3
|
+
import { Store } from "@tanstack/angular-store";
|
|
4
4
|
|
|
5
5
|
//#region src/async-batcher/injectAsyncBatcher.d.ts
|
|
6
|
+
interface AngularAsyncBatcherOptions<TValue, TSelected = {}> extends AsyncBatcherOptions<TValue> {
|
|
7
|
+
/**
|
|
8
|
+
* Optional callback invoked when the component is destroyed. Receives the batcher instance.
|
|
9
|
+
* When provided, replaces the default cleanup (cancel + abort); use it to call flush(), cancel(), add logging, etc.
|
|
10
|
+
* When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
|
|
11
|
+
*/
|
|
12
|
+
onUnmount?: (batcher: AngularAsyncBatcher<TValue, TSelected>) => void;
|
|
13
|
+
}
|
|
6
14
|
interface AngularAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBatcher<TValue>, 'store'> {
|
|
7
15
|
/**
|
|
8
16
|
* Reactive state signal that will be updated when the async batcher state changes
|
|
@@ -35,6 +43,20 @@ interface AngularAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBatcher<
|
|
|
35
43
|
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
36
44
|
* full control over when your component tracks state changes.
|
|
37
45
|
*
|
|
46
|
+
* ## Cleanup on Destroy
|
|
47
|
+
*
|
|
48
|
+
* By default, the function cancels any pending batch and aborts in-flight work when the component is destroyed.
|
|
49
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* const batcher = injectAsyncBatcher(fn, {
|
|
53
|
+
* maxSize: 10,
|
|
54
|
+
* onUnmount: (b) => b.flush()
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
|
|
59
|
+
*
|
|
38
60
|
* @example
|
|
39
61
|
* ```ts
|
|
40
62
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -57,7 +79,7 @@ interface AngularAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBatcher<
|
|
|
57
79
|
* const { items, isExecuting } = batcher.state();
|
|
58
80
|
* ```
|
|
59
81
|
*/
|
|
60
|
-
declare function injectAsyncBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => Promise<any>, options?:
|
|
82
|
+
declare function injectAsyncBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => Promise<any>, options?: AngularAsyncBatcherOptions<TValue, TSelected>, selector?: (state: AsyncBatcherState<TValue>) => TSelected): AngularAsyncBatcher<TValue, TSelected>;
|
|
61
83
|
//#endregion
|
|
62
|
-
export { AngularAsyncBatcher, injectAsyncBatcher };
|
|
84
|
+
export { AngularAsyncBatcher, AngularAsyncBatcherOptions, injectAsyncBatcher };
|
|
63
85
|
//# sourceMappingURL=injectAsyncBatcher.d.cts.map
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { Signal } from "@angular/core";
|
|
2
|
+
import { Store } from "@tanstack/angular-store";
|
|
2
3
|
import { AsyncBatcher, AsyncBatcherOptions, AsyncBatcherState } from "@tanstack/pacer/async-batcher";
|
|
3
|
-
import { Store } from "@tanstack/store";
|
|
4
4
|
|
|
5
5
|
//#region src/async-batcher/injectAsyncBatcher.d.ts
|
|
6
|
+
interface AngularAsyncBatcherOptions<TValue, TSelected = {}> extends AsyncBatcherOptions<TValue> {
|
|
7
|
+
/**
|
|
8
|
+
* Optional callback invoked when the component is destroyed. Receives the batcher instance.
|
|
9
|
+
* When provided, replaces the default cleanup (cancel + abort); use it to call flush(), cancel(), add logging, etc.
|
|
10
|
+
* When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
|
|
11
|
+
*/
|
|
12
|
+
onUnmount?: (batcher: AngularAsyncBatcher<TValue, TSelected>) => void;
|
|
13
|
+
}
|
|
6
14
|
interface AngularAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBatcher<TValue>, 'store'> {
|
|
7
15
|
/**
|
|
8
16
|
* Reactive state signal that will be updated when the async batcher state changes
|
|
@@ -35,6 +43,20 @@ interface AngularAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBatcher<
|
|
|
35
43
|
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
36
44
|
* full control over when your component tracks state changes.
|
|
37
45
|
*
|
|
46
|
+
* ## Cleanup on Destroy
|
|
47
|
+
*
|
|
48
|
+
* By default, the function cancels any pending batch and aborts in-flight work when the component is destroyed.
|
|
49
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* const batcher = injectAsyncBatcher(fn, {
|
|
53
|
+
* maxSize: 10,
|
|
54
|
+
* onUnmount: (b) => b.flush()
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
|
|
59
|
+
*
|
|
38
60
|
* @example
|
|
39
61
|
* ```ts
|
|
40
62
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -57,7 +79,7 @@ interface AngularAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBatcher<
|
|
|
57
79
|
* const { items, isExecuting } = batcher.state();
|
|
58
80
|
* ```
|
|
59
81
|
*/
|
|
60
|
-
declare function injectAsyncBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => Promise<any>, options?:
|
|
82
|
+
declare function injectAsyncBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => Promise<any>, options?: AngularAsyncBatcherOptions<TValue, TSelected>, selector?: (state: AsyncBatcherState<TValue>) => TSelected): AngularAsyncBatcher<TValue, TSelected>;
|
|
61
83
|
//#endregion
|
|
62
|
-
export { AngularAsyncBatcher, injectAsyncBatcher };
|
|
84
|
+
export { AngularAsyncBatcher, AngularAsyncBatcherOptions, injectAsyncBatcher };
|
|
63
85
|
//# sourceMappingURL=injectAsyncBatcher.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 { AsyncBatcher } from "@tanstack/pacer/async-batcher";
|
|
4
5
|
|
|
@@ -22,6 +23,20 @@ import { AsyncBatcher } from "@tanstack/pacer/async-batcher";
|
|
|
22
23
|
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
23
24
|
* full control over when your component tracks state changes.
|
|
24
25
|
*
|
|
26
|
+
* ## Cleanup on Destroy
|
|
27
|
+
*
|
|
28
|
+
* By default, the function cancels any pending batch and aborts in-flight work when the component is destroyed.
|
|
29
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const batcher = injectAsyncBatcher(fn, {
|
|
33
|
+
* maxSize: 10,
|
|
34
|
+
* onUnmount: (b) => b.flush()
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
|
|
39
|
+
*
|
|
25
40
|
* @example
|
|
26
41
|
* ```ts
|
|
27
42
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -45,15 +60,24 @@ import { AsyncBatcher } from "@tanstack/pacer/async-batcher";
|
|
|
45
60
|
* ```
|
|
46
61
|
*/
|
|
47
62
|
function injectAsyncBatcher(fn, options = {}, selector = () => ({})) {
|
|
48
|
-
const
|
|
63
|
+
const mergedOptions = {
|
|
49
64
|
...injectPacerOptions().asyncBatcher,
|
|
50
65
|
...options
|
|
51
|
-
}
|
|
66
|
+
};
|
|
67
|
+
const batcher = new AsyncBatcher(fn, mergedOptions);
|
|
52
68
|
const state = injectStore(batcher.store, selector);
|
|
53
|
-
|
|
69
|
+
const result = {
|
|
54
70
|
...batcher,
|
|
55
71
|
state
|
|
56
72
|
};
|
|
73
|
+
inject(DestroyRef, { optional: true })?.onDestroy(() => {
|
|
74
|
+
if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
|
|
75
|
+
else {
|
|
76
|
+
batcher.cancel();
|
|
77
|
+
batcher.abort();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return result;
|
|
57
81
|
}
|
|
58
82
|
|
|
59
83
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectAsyncBatcher.js","names":[],"sources":["../../src/async-batcher/injectAsyncBatcher.ts"],"sourcesContent":["import { injectStore } from '@tanstack/angular-store'\nimport { AsyncBatcher } from '@tanstack/pacer/async-batcher'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/store'\nimport type {\n AsyncBatcherOptions,\n AsyncBatcherState,\n} from '@tanstack/pacer/async-batcher'\n\nexport interface AngularAsyncBatcher<TValue, TSelected = {}> extends Omit<\n AsyncBatcher<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the async batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.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<AsyncBatcherState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncBatcher instance.\n *\n * This is a lower-level function that provides direct access to the AsyncBatcher's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The AsyncBatcher collects items and processes them in batches asynchronously with support for\n * promise-based processing, error handling, retry capabilities, and abort support.\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 batcher = injectAsyncBatcher(\n * async (items: Array<Data>) => {\n * const response = await fetch('/api/batch', {\n * method: 'POST',\n * body: JSON.stringify(items)\n * });\n * return response.json();\n * },\n * { maxSize: 10, wait: 2000 }\n * );\n *\n * // Add items\n * batcher.addItem(data1);\n * batcher.addItem(data2);\n *\n * // Access the selected state\n * const { items, isExecuting } = batcher.state();\n * ```\n */\nexport function injectAsyncBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => Promise<any>,\n options:
|
|
1
|
+
{"version":3,"file":"injectAsyncBatcher.js","names":[],"sources":["../../src/async-batcher/injectAsyncBatcher.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { AsyncBatcher } from '@tanstack/pacer/async-batcher'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type {\n AsyncBatcherOptions,\n AsyncBatcherState,\n} from '@tanstack/pacer/async-batcher'\n\nexport interface AngularAsyncBatcherOptions<\n TValue,\n TSelected = {},\n> extends AsyncBatcherOptions<TValue> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the batcher instance.\n * When provided, replaces the default cleanup (cancel + abort); use it to call flush(), cancel(), add logging, etc.\n * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.\n */\n onUnmount?: (batcher: AngularAsyncBatcher<TValue, TSelected>) => void\n}\n\nexport interface AngularAsyncBatcher<TValue, TSelected = {}> extends Omit<\n AsyncBatcher<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the async batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.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<AsyncBatcherState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncBatcher instance.\n *\n * This is a lower-level function that provides direct access to the AsyncBatcher's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The AsyncBatcher collects items and processes them in batches asynchronously with support for\n * promise-based processing, error handling, retry capabilities, and abort support.\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 * ## Cleanup on Destroy\n *\n * By default, the function cancels any pending batch and aborts in-flight work 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 batcher = injectAsyncBatcher(fn, {\n * maxSize: 10,\n * onUnmount: (b) => b.flush()\n * });\n * ```\n *\n * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const batcher = injectAsyncBatcher(\n * async (items: Array<Data>) => {\n * const response = await fetch('/api/batch', {\n * method: 'POST',\n * body: JSON.stringify(items)\n * });\n * return response.json();\n * },\n * { maxSize: 10, wait: 2000 }\n * );\n *\n * // Add items\n * batcher.addItem(data1);\n * batcher.addItem(data2);\n *\n * // Access the selected state\n * const { items, isExecuting } = batcher.state();\n * ```\n */\nexport function injectAsyncBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => Promise<any>,\n options: AngularAsyncBatcherOptions<TValue, TSelected> = {},\n selector: (state: AsyncBatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncBatcher,\n ...options,\n } as AngularAsyncBatcherOptions<TValue, TSelected>\n\n const batcher = new AsyncBatcher<TValue>(fn, mergedOptions)\n const state = injectStore(batcher.store, selector)\n\n const result = {\n ...batcher,\n state,\n } as AngularAsyncBatcher<TValue, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n batcher.cancel()\n batcher.abort()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FA,SAAgB,mBACd,IACA,UAAyD,EAAE,EAC3D,kBACG,EAAE,GACmC;CACxC,MAAM,gBAAgB;EACpB,GAAG,oBAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,UAAU,IAAI,aAAqB,IAAI,cAAc;CAC3D,MAAM,QAAQ,YAAY,QAAQ,OAAO,SAAS;CAElD,MAAM,SAAS;EACb,GAAG;EACH;EACD;AAGD,CADmB,OAAO,YAAY,EAAE,UAAU,MAAM,CAAC,EAC7C,gBAAgB;AAC1B,MAAI,cAAc,UAChB,eAAc,UAAU,OAAO;OAC1B;AACL,WAAQ,QAAQ;AAChB,WAAQ,OAAO;;GAEjB;AAEF,QAAO"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { injectAsyncDebouncedCallback } from "./injectAsyncDebouncedCallback.cjs";
|
|
2
|
-
import { AngularAsyncDebouncer, injectAsyncDebouncer } from "./injectAsyncDebouncer.cjs";
|
|
2
|
+
import { AngularAsyncDebouncer, AngularAsyncDebouncerOptions, injectAsyncDebouncer } from "./injectAsyncDebouncer.cjs";
|
|
3
3
|
export * from "@tanstack/pacer/async-debouncer";
|
|
4
|
-
export { AngularAsyncDebouncer, injectAsyncDebouncedCallback, injectAsyncDebouncer };
|
|
4
|
+
export { AngularAsyncDebouncer, AngularAsyncDebouncerOptions, injectAsyncDebouncedCallback, injectAsyncDebouncer };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { injectAsyncDebouncedCallback } from "./injectAsyncDebouncedCallback.js";
|
|
2
|
-
import { AngularAsyncDebouncer, injectAsyncDebouncer } from "./injectAsyncDebouncer.js";
|
|
2
|
+
import { AngularAsyncDebouncer, AngularAsyncDebouncerOptions, injectAsyncDebouncer } from "./injectAsyncDebouncer.js";
|
|
3
3
|
export * from "@tanstack/pacer/async-debouncer";
|
|
4
|
-
export { AngularAsyncDebouncer, injectAsyncDebouncedCallback, injectAsyncDebouncer };
|
|
4
|
+
export { AngularAsyncDebouncer, AngularAsyncDebouncerOptions, injectAsyncDebouncedCallback, injectAsyncDebouncer };
|
|
@@ -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_async_debouncer = require("@tanstack/pacer/async-debouncer");
|
|
4
5
|
|
|
@@ -37,6 +38,20 @@ let _tanstack_pacer_async_debouncer = require("@tanstack/pacer/async-debouncer")
|
|
|
37
38
|
* - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing' | 'settled')
|
|
38
39
|
* - `successCount`: Number of function executions that have completed successfully
|
|
39
40
|
*
|
|
41
|
+
* ## Cleanup on Destroy
|
|
42
|
+
*
|
|
43
|
+
* By default, the function cancels any pending execution and aborts in-flight work when the component is destroyed.
|
|
44
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* const debouncer = injectAsyncDebouncer(fn, {
|
|
48
|
+
* wait: 500,
|
|
49
|
+
* onUnmount: (d) => d.flush()
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
|
|
54
|
+
*
|
|
40
55
|
* @example
|
|
41
56
|
* ```ts
|
|
42
57
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -67,15 +82,24 @@ let _tanstack_pacer_async_debouncer = require("@tanstack/pacer/async-debouncer")
|
|
|
67
82
|
* ```
|
|
68
83
|
*/
|
|
69
84
|
function injectAsyncDebouncer(fn, options, selector = () => ({})) {
|
|
70
|
-
const
|
|
85
|
+
const mergedOptions = {
|
|
71
86
|
...require_pacer_context.injectPacerOptions().asyncDebouncer,
|
|
72
87
|
...options
|
|
73
|
-
}
|
|
88
|
+
};
|
|
89
|
+
const debouncer = new _tanstack_pacer_async_debouncer.AsyncDebouncer(fn, mergedOptions);
|
|
74
90
|
const state = (0, _tanstack_angular_store.injectStore)(debouncer.store, selector);
|
|
75
|
-
|
|
91
|
+
const result = {
|
|
76
92
|
...debouncer,
|
|
77
93
|
state
|
|
78
94
|
};
|
|
95
|
+
(0, _angular_core.inject)(_angular_core.DestroyRef, { optional: true })?.onDestroy(() => {
|
|
96
|
+
if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
|
|
97
|
+
else {
|
|
98
|
+
debouncer.cancel();
|
|
99
|
+
debouncer.abort();
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return result;
|
|
79
103
|
}
|
|
80
104
|
|
|
81
105
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectAsyncDebouncer.cjs","names":["AsyncDebouncer","
|
|
1
|
+
{"version":3,"file":"injectAsyncDebouncer.cjs","names":["injectPacerOptions","AsyncDebouncer","DestroyRef"],"sources":["../../src/async-debouncer/injectAsyncDebouncer.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { AsyncDebouncer } from '@tanstack/pacer/async-debouncer'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncDebouncerOptions,\n AsyncDebouncerState,\n} from '@tanstack/pacer/async-debouncer'\n\nexport interface AngularAsyncDebouncerOptions<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends AsyncDebouncerOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the debouncer instance.\n * When provided, replaces the default cleanup (cancel + abort); use it to call flush(), cancel(), add logging, etc.\n * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.\n */\n onUnmount?: (debouncer: AngularAsyncDebouncer<TFn, TSelected>) => void\n}\n\nexport interface AngularAsyncDebouncer<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncDebouncer<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the async 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<AsyncDebouncerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncDebouncer instance.\n *\n * This is a lower-level function that provides direct access to the AsyncDebouncer's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides async debouncing functionality with promise support, error handling,\n * retry capabilities, and abort support.\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 * - `errorCount`: Number of function executions that have resulted in errors\n * - `isExecuting`: Whether the debounced function is currently executing asynchronously\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 * - `lastResult`: The result from the most recent successful function execution\n * - `settleCount`: Number of function executions that have completed (either successfully or with errors)\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing' | 'settled')\n * - `successCount`: Number of function executions that have completed successfully\n *\n * ## Cleanup on Destroy\n *\n * By default, the function cancels any pending execution and aborts in-flight work 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 = injectAsyncDebouncer(fn, {\n * wait: 500,\n * onUnmount: (d) => d.flush()\n * });\n * ```\n *\n * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const debouncer = injectAsyncDebouncer(\n * async (query: string) => {\n * const response = await fetch(`/api/search?q=${query}`);\n * return response.json();\n * },\n * { wait: 500 }\n * );\n *\n * // Opt-in to track isExecuting changes (optimized for loading states)\n * const debouncer = injectAsyncDebouncer(\n * async (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ isExecuting: state.isExecuting, isPending: state.isPending })\n * );\n *\n * // In an event handler\n * const handleChange = async (e: Event) => {\n * const target = e.target as HTMLInputElement;\n * const result = await debouncer.maybeExecute(target.value);\n * console.log('Search results:', result);\n * };\n *\n * // Access the selected state\n * const { isExecuting, errorCount } = debouncer.state();\n * ```\n */\nexport function injectAsyncDebouncer<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AngularAsyncDebouncerOptions<TFn, TSelected>,\n selector: (state: AsyncDebouncerState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncDebouncer<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncDebouncer,\n ...options,\n } as AngularAsyncDebouncerOptions<TFn, TSelected>\n\n const debouncer = new AsyncDebouncer<TFn>(fn, mergedOptions)\n const state = injectStore(debouncer.store, selector)\n\n const result = {\n ...debouncer,\n state,\n } as AngularAsyncDebouncer<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 debouncer.abort()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsHA,SAAgB,qBAId,IACA,SACA,kBACG,EAAE,GACkC;CACvC,MAAM,gBAAgB;EACpB,GAAGA,0CAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,YAAY,IAAIC,+CAAoB,IAAI,cAAc;CAC5D,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;OAC1B;AACL,aAAU,QAAQ;AAClB,aAAU,OAAO;;GAEnB;AAEF,QAAO"}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { Signal } from "@angular/core";
|
|
2
|
-
import { Store } from "@tanstack/store";
|
|
2
|
+
import { Store } from "@tanstack/angular-store";
|
|
3
3
|
import { AsyncDebouncer, AsyncDebouncerOptions, AsyncDebouncerState } from "@tanstack/pacer/async-debouncer";
|
|
4
4
|
import { AnyAsyncFunction } from "@tanstack/pacer/types";
|
|
5
5
|
|
|
6
6
|
//#region src/async-debouncer/injectAsyncDebouncer.d.ts
|
|
7
|
+
interface AngularAsyncDebouncerOptions<TFn extends AnyAsyncFunction, TSelected = {}> extends AsyncDebouncerOptions<TFn> {
|
|
8
|
+
/**
|
|
9
|
+
* Optional callback invoked when the component is destroyed. Receives the debouncer instance.
|
|
10
|
+
* When provided, replaces the default cleanup (cancel + abort); use it to call flush(), cancel(), add logging, etc.
|
|
11
|
+
* When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
|
|
12
|
+
*/
|
|
13
|
+
onUnmount?: (debouncer: AngularAsyncDebouncer<TFn, TSelected>) => void;
|
|
14
|
+
}
|
|
7
15
|
interface AngularAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncDebouncer<TFn>, 'store'> {
|
|
8
16
|
/**
|
|
9
17
|
* Reactive state signal that will be updated when the async debouncer state changes
|
|
@@ -51,6 +59,20 @@ interface AngularAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}> ex
|
|
|
51
59
|
* - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing' | 'settled')
|
|
52
60
|
* - `successCount`: Number of function executions that have completed successfully
|
|
53
61
|
*
|
|
62
|
+
* ## Cleanup on Destroy
|
|
63
|
+
*
|
|
64
|
+
* By default, the function cancels any pending execution and aborts in-flight work when the component is destroyed.
|
|
65
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
66
|
+
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* const debouncer = injectAsyncDebouncer(fn, {
|
|
69
|
+
* wait: 500,
|
|
70
|
+
* onUnmount: (d) => d.flush()
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
|
|
75
|
+
*
|
|
54
76
|
* @example
|
|
55
77
|
* ```ts
|
|
56
78
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -80,7 +102,7 @@ interface AngularAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}> ex
|
|
|
80
102
|
* const { isExecuting, errorCount } = debouncer.state();
|
|
81
103
|
* ```
|
|
82
104
|
*/
|
|
83
|
-
declare function injectAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options:
|
|
105
|
+
declare function injectAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: AngularAsyncDebouncerOptions<TFn, TSelected>, selector?: (state: AsyncDebouncerState<TFn>) => TSelected): AngularAsyncDebouncer<TFn, TSelected>;
|
|
84
106
|
//#endregion
|
|
85
|
-
export { AngularAsyncDebouncer, injectAsyncDebouncer };
|
|
107
|
+
export { AngularAsyncDebouncer, AngularAsyncDebouncerOptions, injectAsyncDebouncer };
|
|
86
108
|
//# sourceMappingURL=injectAsyncDebouncer.d.cts.map
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { Signal } from "@angular/core";
|
|
2
|
+
import { Store } from "@tanstack/angular-store";
|
|
2
3
|
import { AsyncDebouncer, AsyncDebouncerOptions, AsyncDebouncerState } from "@tanstack/pacer/async-debouncer";
|
|
3
4
|
import { AnyAsyncFunction } from "@tanstack/pacer/types";
|
|
4
|
-
import { Store } from "@tanstack/store";
|
|
5
5
|
|
|
6
6
|
//#region src/async-debouncer/injectAsyncDebouncer.d.ts
|
|
7
|
+
interface AngularAsyncDebouncerOptions<TFn extends AnyAsyncFunction, TSelected = {}> extends AsyncDebouncerOptions<TFn> {
|
|
8
|
+
/**
|
|
9
|
+
* Optional callback invoked when the component is destroyed. Receives the debouncer instance.
|
|
10
|
+
* When provided, replaces the default cleanup (cancel + abort); use it to call flush(), cancel(), add logging, etc.
|
|
11
|
+
* When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
|
|
12
|
+
*/
|
|
13
|
+
onUnmount?: (debouncer: AngularAsyncDebouncer<TFn, TSelected>) => void;
|
|
14
|
+
}
|
|
7
15
|
interface AngularAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncDebouncer<TFn>, 'store'> {
|
|
8
16
|
/**
|
|
9
17
|
* Reactive state signal that will be updated when the async debouncer state changes
|
|
@@ -51,6 +59,20 @@ interface AngularAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}> ex
|
|
|
51
59
|
* - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing' | 'settled')
|
|
52
60
|
* - `successCount`: Number of function executions that have completed successfully
|
|
53
61
|
*
|
|
62
|
+
* ## Cleanup on Destroy
|
|
63
|
+
*
|
|
64
|
+
* By default, the function cancels any pending execution and aborts in-flight work when the component is destroyed.
|
|
65
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
66
|
+
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* const debouncer = injectAsyncDebouncer(fn, {
|
|
69
|
+
* wait: 500,
|
|
70
|
+
* onUnmount: (d) => d.flush()
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
|
|
75
|
+
*
|
|
54
76
|
* @example
|
|
55
77
|
* ```ts
|
|
56
78
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -80,7 +102,7 @@ interface AngularAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}> ex
|
|
|
80
102
|
* const { isExecuting, errorCount } = debouncer.state();
|
|
81
103
|
* ```
|
|
82
104
|
*/
|
|
83
|
-
declare function injectAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options:
|
|
105
|
+
declare function injectAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: AngularAsyncDebouncerOptions<TFn, TSelected>, selector?: (state: AsyncDebouncerState<TFn>) => TSelected): AngularAsyncDebouncer<TFn, TSelected>;
|
|
84
106
|
//#endregion
|
|
85
|
-
export { AngularAsyncDebouncer, injectAsyncDebouncer };
|
|
107
|
+
export { AngularAsyncDebouncer, AngularAsyncDebouncerOptions, injectAsyncDebouncer };
|
|
86
108
|
//# sourceMappingURL=injectAsyncDebouncer.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 { AsyncDebouncer } from "@tanstack/pacer/async-debouncer";
|
|
4
5
|
|
|
@@ -37,6 +38,20 @@ import { AsyncDebouncer } from "@tanstack/pacer/async-debouncer";
|
|
|
37
38
|
* - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing' | 'settled')
|
|
38
39
|
* - `successCount`: Number of function executions that have completed successfully
|
|
39
40
|
*
|
|
41
|
+
* ## Cleanup on Destroy
|
|
42
|
+
*
|
|
43
|
+
* By default, the function cancels any pending execution and aborts in-flight work when the component is destroyed.
|
|
44
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* const debouncer = injectAsyncDebouncer(fn, {
|
|
48
|
+
* wait: 500,
|
|
49
|
+
* onUnmount: (d) => d.flush()
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
|
|
54
|
+
*
|
|
40
55
|
* @example
|
|
41
56
|
* ```ts
|
|
42
57
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -67,15 +82,24 @@ import { AsyncDebouncer } from "@tanstack/pacer/async-debouncer";
|
|
|
67
82
|
* ```
|
|
68
83
|
*/
|
|
69
84
|
function injectAsyncDebouncer(fn, options, selector = () => ({})) {
|
|
70
|
-
const
|
|
85
|
+
const mergedOptions = {
|
|
71
86
|
...injectPacerOptions().asyncDebouncer,
|
|
72
87
|
...options
|
|
73
|
-
}
|
|
88
|
+
};
|
|
89
|
+
const debouncer = new AsyncDebouncer(fn, mergedOptions);
|
|
74
90
|
const state = injectStore(debouncer.store, selector);
|
|
75
|
-
|
|
91
|
+
const result = {
|
|
76
92
|
...debouncer,
|
|
77
93
|
state
|
|
78
94
|
};
|
|
95
|
+
inject(DestroyRef, { optional: true })?.onDestroy(() => {
|
|
96
|
+
if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
|
|
97
|
+
else {
|
|
98
|
+
debouncer.cancel();
|
|
99
|
+
debouncer.abort();
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return result;
|
|
79
103
|
}
|
|
80
104
|
|
|
81
105
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectAsyncDebouncer.js","names":[],"sources":["../../src/async-debouncer/injectAsyncDebouncer.ts"],"sourcesContent":["import { injectStore } from '@tanstack/angular-store'\nimport { AsyncDebouncer } from '@tanstack/pacer/async-debouncer'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/store'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncDebouncerOptions,\n AsyncDebouncerState,\n} from '@tanstack/pacer/async-debouncer'\n\nexport interface AngularAsyncDebouncer<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncDebouncer<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the async 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<AsyncDebouncerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncDebouncer instance.\n *\n * This is a lower-level function that provides direct access to the AsyncDebouncer's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides async debouncing functionality with promise support, error handling,\n * retry capabilities, and abort support.\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 * - `errorCount`: Number of function executions that have resulted in errors\n * - `isExecuting`: Whether the debounced function is currently executing asynchronously\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 * - `lastResult`: The result from the most recent successful function execution\n * - `settleCount`: Number of function executions that have completed (either successfully or with errors)\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing' | 'settled')\n * - `successCount`: Number of function executions that have completed successfully\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const debouncer = injectAsyncDebouncer(\n * async (query: string) => {\n * const response = await fetch(`/api/search?q=${query}`);\n * return response.json();\n * },\n * { wait: 500 }\n * );\n *\n * // Opt-in to track isExecuting changes (optimized for loading states)\n * const debouncer = injectAsyncDebouncer(\n * async (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ isExecuting: state.isExecuting, isPending: state.isPending })\n * );\n *\n * // In an event handler\n * const handleChange = async (e: Event) => {\n * const target = e.target as HTMLInputElement;\n * const result = await debouncer.maybeExecute(target.value);\n * console.log('Search results:', result);\n * };\n *\n * // Access the selected state\n * const { isExecuting, errorCount } = debouncer.state();\n * ```\n */\nexport function injectAsyncDebouncer<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options:
|
|
1
|
+
{"version":3,"file":"injectAsyncDebouncer.js","names":[],"sources":["../../src/async-debouncer/injectAsyncDebouncer.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { AsyncDebouncer } from '@tanstack/pacer/async-debouncer'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncDebouncerOptions,\n AsyncDebouncerState,\n} from '@tanstack/pacer/async-debouncer'\n\nexport interface AngularAsyncDebouncerOptions<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends AsyncDebouncerOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the debouncer instance.\n * When provided, replaces the default cleanup (cancel + abort); use it to call flush(), cancel(), add logging, etc.\n * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.\n */\n onUnmount?: (debouncer: AngularAsyncDebouncer<TFn, TSelected>) => void\n}\n\nexport interface AngularAsyncDebouncer<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncDebouncer<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the async 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<AsyncDebouncerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncDebouncer instance.\n *\n * This is a lower-level function that provides direct access to the AsyncDebouncer's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides async debouncing functionality with promise support, error handling,\n * retry capabilities, and abort support.\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 * - `errorCount`: Number of function executions that have resulted in errors\n * - `isExecuting`: Whether the debounced function is currently executing asynchronously\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 * - `lastResult`: The result from the most recent successful function execution\n * - `settleCount`: Number of function executions that have completed (either successfully or with errors)\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing' | 'settled')\n * - `successCount`: Number of function executions that have completed successfully\n *\n * ## Cleanup on Destroy\n *\n * By default, the function cancels any pending execution and aborts in-flight work 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 = injectAsyncDebouncer(fn, {\n * wait: 500,\n * onUnmount: (d) => d.flush()\n * });\n * ```\n *\n * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const debouncer = injectAsyncDebouncer(\n * async (query: string) => {\n * const response = await fetch(`/api/search?q=${query}`);\n * return response.json();\n * },\n * { wait: 500 }\n * );\n *\n * // Opt-in to track isExecuting changes (optimized for loading states)\n * const debouncer = injectAsyncDebouncer(\n * async (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ isExecuting: state.isExecuting, isPending: state.isPending })\n * );\n *\n * // In an event handler\n * const handleChange = async (e: Event) => {\n * const target = e.target as HTMLInputElement;\n * const result = await debouncer.maybeExecute(target.value);\n * console.log('Search results:', result);\n * };\n *\n * // Access the selected state\n * const { isExecuting, errorCount } = debouncer.state();\n * ```\n */\nexport function injectAsyncDebouncer<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AngularAsyncDebouncerOptions<TFn, TSelected>,\n selector: (state: AsyncDebouncerState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncDebouncer<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncDebouncer,\n ...options,\n } as AngularAsyncDebouncerOptions<TFn, TSelected>\n\n const debouncer = new AsyncDebouncer<TFn>(fn, mergedOptions)\n const state = injectStore(debouncer.store, selector)\n\n const result = {\n ...debouncer,\n state,\n } as AngularAsyncDebouncer<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 debouncer.abort()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsHA,SAAgB,qBAId,IACA,SACA,kBACG,EAAE,GACkC;CACvC,MAAM,gBAAgB;EACpB,GAAG,oBAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,YAAY,IAAI,eAAoB,IAAI,cAAc;CAC5D,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;OAC1B;AACL,aAAU,QAAQ;AAClB,aAAU,OAAO;;GAEnB;AAEF,QAAO"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AngularAsyncQueuer, injectAsyncQueuer } from "./injectAsyncQueuer.cjs";
|
|
1
|
+
import { AngularAsyncQueuer, AngularAsyncQueuerOptions, injectAsyncQueuer } from "./injectAsyncQueuer.cjs";
|
|
2
2
|
import { AsyncQueuedSignal, injectAsyncQueuedSignal } from "./injectAsyncQueuedSignal.cjs";
|
|
3
3
|
export * from "@tanstack/pacer/async-queuer";
|
|
4
|
-
export { AngularAsyncQueuer, AsyncQueuedSignal, injectAsyncQueuedSignal, injectAsyncQueuer };
|
|
4
|
+
export { AngularAsyncQueuer, AngularAsyncQueuerOptions, AsyncQueuedSignal, injectAsyncQueuedSignal, injectAsyncQueuer };
|