@tanstack/angular-pacer 0.23.1 → 0.25.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/README.md +21 -6
- package/dist/async-batcher/injectAsyncBatchedCallback.d.ts +2 -5
- package/dist/async-batcher/injectAsyncBatchedCallback.js +1 -2
- package/dist/async-batcher/injectAsyncBatcher.d.ts +4 -7
- package/dist/async-batcher/injectAsyncBatcher.js +1 -2
- package/dist/async-debouncer/injectAsyncDebouncedCallback.d.ts +2 -5
- package/dist/async-debouncer/injectAsyncDebouncedCallback.js +1 -2
- package/dist/async-debouncer/injectAsyncDebouncer.d.ts +4 -7
- package/dist/async-debouncer/injectAsyncDebouncer.js +1 -2
- package/dist/async-queuer/injectAsyncQueuedSignal.d.ts +3 -6
- package/dist/async-queuer/injectAsyncQueuedSignal.js +1 -2
- package/dist/async-queuer/injectAsyncQueuer.d.ts +4 -7
- package/dist/async-queuer/injectAsyncQueuer.js +1 -2
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.d.ts +2 -5
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.js +1 -2
- package/dist/async-rate-limiter/injectAsyncRateLimiter.d.ts +4 -7
- package/dist/async-rate-limiter/injectAsyncRateLimiter.js +1 -2
- package/dist/async-throttler/injectAsyncThrottledCallback.d.ts +2 -5
- package/dist/async-throttler/injectAsyncThrottledCallback.js +1 -2
- package/dist/async-throttler/injectAsyncThrottler.d.ts +4 -7
- package/dist/async-throttler/injectAsyncThrottler.js +1 -2
- package/dist/batcher/injectBatchedCallback.d.ts +2 -5
- package/dist/batcher/injectBatchedCallback.js +1 -2
- package/dist/batcher/injectBatcher.d.ts +4 -7
- package/dist/batcher/injectBatcher.js +1 -2
- package/dist/debouncer/injectDebouncedCallback.d.ts +2 -5
- package/dist/debouncer/injectDebouncedCallback.js +1 -2
- package/dist/debouncer/injectDebouncedSignal.d.ts +3 -6
- package/dist/debouncer/injectDebouncedSignal.js +1 -2
- package/dist/debouncer/injectDebouncedValue.d.ts +3 -6
- package/dist/debouncer/injectDebouncedValue.js +1 -2
- package/dist/debouncer/injectDebouncer.d.ts +4 -7
- package/dist/debouncer/injectDebouncer.js +1 -2
- package/dist/provider/pacer-context.d.ts +4 -7
- package/dist/provider/pacer-context.js +1 -2
- package/dist/provider/pacer-provider.d.ts +2 -5
- package/dist/provider/pacer-provider.js +1 -2
- package/dist/queuer/injectQueuedSignal.d.ts +3 -6
- package/dist/queuer/injectQueuedSignal.js +1 -2
- package/dist/queuer/injectQueuedValue.d.ts +3 -6
- package/dist/queuer/injectQueuedValue.js +1 -2
- package/dist/queuer/injectQueuer.d.ts +4 -7
- package/dist/queuer/injectQueuer.js +1 -2
- package/dist/rate-limiter/injectRateLimitedCallback.d.ts +2 -5
- package/dist/rate-limiter/injectRateLimitedCallback.js +1 -2
- package/dist/rate-limiter/injectRateLimitedSignal.d.ts +3 -6
- package/dist/rate-limiter/injectRateLimitedSignal.js +1 -2
- package/dist/rate-limiter/injectRateLimitedValue.d.ts +3 -6
- package/dist/rate-limiter/injectRateLimitedValue.js +1 -2
- package/dist/rate-limiter/injectRateLimiter.d.ts +4 -7
- package/dist/rate-limiter/injectRateLimiter.js +1 -2
- package/dist/throttler/injectThrottledCallback.d.ts +2 -5
- package/dist/throttler/injectThrottledCallback.js +1 -2
- package/dist/throttler/injectThrottledSignal.d.ts +3 -8
- package/dist/throttler/injectThrottledSignal.js +1 -4
- package/dist/throttler/injectThrottledValue.d.ts +3 -8
- package/dist/throttler/injectThrottledValue.js +1 -2
- package/dist/throttler/injectThrottler.d.ts +4 -9
- package/dist/throttler/injectThrottler.js +1 -4
- package/package.json +25 -72
- package/dist/async-batcher/index.cjs +0 -13
- package/dist/async-batcher/index.d.cts +0 -4
- package/dist/async-batcher/injectAsyncBatchedCallback.cjs +0 -49
- package/dist/async-batcher/injectAsyncBatchedCallback.cjs.map +0 -1
- package/dist/async-batcher/injectAsyncBatchedCallback.d.cts +0 -45
- package/dist/async-batcher/injectAsyncBatchedCallback.js.map +0 -1
- package/dist/async-batcher/injectAsyncBatcher.cjs +0 -85
- package/dist/async-batcher/injectAsyncBatcher.cjs.map +0 -1
- package/dist/async-batcher/injectAsyncBatcher.d.cts +0 -85
- package/dist/async-batcher/injectAsyncBatcher.js.map +0 -1
- package/dist/async-debouncer/index.cjs +0 -13
- package/dist/async-debouncer/index.d.cts +0 -4
- package/dist/async-debouncer/injectAsyncDebouncedCallback.cjs +0 -49
- package/dist/async-debouncer/injectAsyncDebouncedCallback.cjs.map +0 -1
- package/dist/async-debouncer/injectAsyncDebouncedCallback.d.cts +0 -43
- package/dist/async-debouncer/injectAsyncDebouncedCallback.js.map +0 -1
- package/dist/async-debouncer/injectAsyncDebouncer.cjs +0 -107
- package/dist/async-debouncer/injectAsyncDebouncer.cjs.map +0 -1
- package/dist/async-debouncer/injectAsyncDebouncer.d.cts +0 -108
- package/dist/async-debouncer/injectAsyncDebouncer.js.map +0 -1
- package/dist/async-queuer/index.cjs +0 -13
- package/dist/async-queuer/index.d.cts +0 -4
- package/dist/async-queuer/injectAsyncQueuedSignal.cjs +0 -53
- package/dist/async-queuer/injectAsyncQueuedSignal.cjs.map +0 -1
- package/dist/async-queuer/injectAsyncQueuedSignal.d.cts +0 -50
- package/dist/async-queuer/injectAsyncQueuedSignal.js.map +0 -1
- package/dist/async-queuer/injectAsyncQueuer.cjs +0 -85
- package/dist/async-queuer/injectAsyncQueuer.cjs.map +0 -1
- package/dist/async-queuer/injectAsyncQueuer.d.cts +0 -85
- package/dist/async-queuer/injectAsyncQueuer.js.map +0 -1
- package/dist/async-rate-limiter/index.cjs +0 -13
- package/dist/async-rate-limiter/index.d.cts +0 -4
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.cjs +0 -52
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.cjs.map +0 -1
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.d.cts +0 -46
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.js.map +0 -1
- package/dist/async-rate-limiter/injectAsyncRateLimiter.cjs +0 -69
- package/dist/async-rate-limiter/injectAsyncRateLimiter.cjs.map +0 -1
- package/dist/async-rate-limiter/injectAsyncRateLimiter.d.cts +0 -72
- package/dist/async-rate-limiter/injectAsyncRateLimiter.js.map +0 -1
- package/dist/async-retryer/index.cjs +0 -9
- package/dist/async-retryer/index.d.cts +0 -1
- package/dist/async-throttler/index.cjs +0 -13
- package/dist/async-throttler/index.d.cts +0 -4
- package/dist/async-throttler/injectAsyncThrottledCallback.cjs +0 -50
- package/dist/async-throttler/injectAsyncThrottledCallback.cjs.map +0 -1
- package/dist/async-throttler/injectAsyncThrottledCallback.d.cts +0 -44
- package/dist/async-throttler/injectAsyncThrottledCallback.js.map +0 -1
- package/dist/async-throttler/injectAsyncThrottler.cjs +0 -86
- package/dist/async-throttler/injectAsyncThrottler.cjs.map +0 -1
- package/dist/async-throttler/injectAsyncThrottler.d.cts +0 -87
- package/dist/async-throttler/injectAsyncThrottler.js.map +0 -1
- package/dist/batcher/index.cjs +0 -13
- package/dist/batcher/index.d.cts +0 -4
- package/dist/batcher/injectBatchedCallback.cjs +0 -47
- package/dist/batcher/injectBatchedCallback.cjs.map +0 -1
- package/dist/batcher/injectBatchedCallback.d.cts +0 -43
- package/dist/batcher/injectBatchedCallback.js.map +0 -1
- package/dist/batcher/injectBatcher.cjs +0 -75
- package/dist/batcher/injectBatcher.cjs.map +0 -1
- package/dist/batcher/injectBatcher.d.cts +0 -77
- package/dist/batcher/injectBatcher.js.map +0 -1
- package/dist/debouncer/index.cjs +0 -17
- package/dist/debouncer/index.d.cts +0 -6
- package/dist/debouncer/injectDebouncedCallback.cjs +0 -46
- package/dist/debouncer/injectDebouncedCallback.cjs.map +0 -1
- package/dist/debouncer/injectDebouncedCallback.d.cts +0 -43
- package/dist/debouncer/injectDebouncedCallback.js.map +0 -1
- package/dist/debouncer/injectDebouncedSignal.cjs +0 -68
- package/dist/debouncer/injectDebouncedSignal.cjs.map +0 -1
- package/dist/debouncer/injectDebouncedSignal.d.cts +0 -60
- package/dist/debouncer/injectDebouncedSignal.js.map +0 -1
- package/dist/debouncer/injectDebouncedValue.cjs +0 -17
- package/dist/debouncer/injectDebouncedValue.cjs.map +0 -1
- package/dist/debouncer/injectDebouncedValue.d.cts +0 -76
- package/dist/debouncer/injectDebouncedValue.js.map +0 -1
- package/dist/debouncer/injectDebouncer.cjs +0 -95
- package/dist/debouncer/injectDebouncer.cjs.map +0 -1
- package/dist/debouncer/injectDebouncer.d.cts +0 -98
- package/dist/debouncer/injectDebouncer.js.map +0 -1
- package/dist/index.cjs +0 -65
- package/dist/index.d.cts +0 -30
- package/dist/provider/index.cjs +0 -7
- package/dist/provider/index.d.cts +0 -3
- package/dist/provider/pacer-context.cjs +0 -20
- package/dist/provider/pacer-context.cjs.map +0 -1
- package/dist/provider/pacer-context.d.cts +0 -21
- package/dist/provider/pacer-context.js.map +0 -1
- package/dist/provider/pacer-provider.cjs +0 -41
- package/dist/provider/pacer-provider.cjs.map +0 -1
- package/dist/provider/pacer-provider.d.cts +0 -36
- package/dist/provider/pacer-provider.js.map +0 -1
- package/dist/queuer/index.cjs +0 -15
- package/dist/queuer/index.d.cts +0 -5
- package/dist/queuer/injectQueuedSignal.cjs +0 -47
- package/dist/queuer/injectQueuedSignal.cjs.map +0 -1
- package/dist/queuer/injectQueuedSignal.d.cts +0 -44
- package/dist/queuer/injectQueuedSignal.js.map +0 -1
- package/dist/queuer/injectQueuedValue.cjs +0 -23
- package/dist/queuer/injectQueuedValue.cjs.map +0 -1
- package/dist/queuer/injectQueuedValue.d.cts +0 -34
- package/dist/queuer/injectQueuedValue.js.map +0 -1
- package/dist/queuer/injectQueuer.cjs +0 -80
- package/dist/queuer/injectQueuer.cjs.map +0 -1
- package/dist/queuer/injectQueuer.d.cts +0 -82
- package/dist/queuer/injectQueuer.js.map +0 -1
- package/dist/rate-limiter/index.cjs +0 -17
- package/dist/rate-limiter/index.d.cts +0 -6
- package/dist/rate-limiter/injectRateLimitedCallback.cjs +0 -45
- package/dist/rate-limiter/injectRateLimitedCallback.cjs.map +0 -1
- package/dist/rate-limiter/injectRateLimitedCallback.d.cts +0 -42
- package/dist/rate-limiter/injectRateLimitedCallback.js.map +0 -1
- package/dist/rate-limiter/injectRateLimitedSignal.cjs +0 -62
- package/dist/rate-limiter/injectRateLimitedSignal.cjs.map +0 -1
- package/dist/rate-limiter/injectRateLimitedSignal.d.cts +0 -54
- package/dist/rate-limiter/injectRateLimitedSignal.js.map +0 -1
- package/dist/rate-limiter/injectRateLimitedValue.cjs +0 -17
- package/dist/rate-limiter/injectRateLimitedValue.cjs.map +0 -1
- package/dist/rate-limiter/injectRateLimitedValue.d.cts +0 -49
- package/dist/rate-limiter/injectRateLimitedValue.js.map +0 -1
- package/dist/rate-limiter/injectRateLimiter.cjs +0 -100
- package/dist/rate-limiter/injectRateLimiter.cjs.map +0 -1
- package/dist/rate-limiter/injectRateLimiter.d.cts +0 -103
- package/dist/rate-limiter/injectRateLimiter.js.map +0 -1
- package/dist/throttler/index.cjs +0 -17
- package/dist/throttler/index.d.cts +0 -6
- package/dist/throttler/injectThrottledCallback.cjs +0 -45
- package/dist/throttler/injectThrottledCallback.cjs.map +0 -1
- package/dist/throttler/injectThrottledCallback.d.cts +0 -42
- package/dist/throttler/injectThrottledCallback.js.map +0 -1
- package/dist/throttler/injectThrottledSignal.cjs +0 -69
- package/dist/throttler/injectThrottledSignal.cjs.map +0 -1
- package/dist/throttler/injectThrottledSignal.d.cts +0 -61
- package/dist/throttler/injectThrottledSignal.js.map +0 -1
- package/dist/throttler/injectThrottledValue.cjs +0 -17
- package/dist/throttler/injectThrottledValue.cjs.map +0 -1
- package/dist/throttler/injectThrottledValue.d.cts +0 -74
- package/dist/throttler/injectThrottledValue.js.map +0 -1
- package/dist/throttler/injectThrottler.cjs +0 -95
- package/dist/throttler/injectThrottler.cjs.map +0 -1
- package/dist/throttler/injectThrottler.d.cts +0 -98
- package/dist/throttler/injectThrottler.js.map +0 -1
- package/dist/types/index.cjs +0 -9
- package/dist/types/index.d.cts +0 -1
- package/dist/utils/index.cjs +0 -9
- package/dist/utils/index.d.cts +0 -1
- package/src/async-batcher/index.ts +0 -4
- package/src/async-batcher/injectAsyncBatchedCallback.ts +0 -48
- package/src/async-batcher/injectAsyncBatcher.ts +0 -126
- package/src/async-debouncer/index.ts +0 -4
- package/src/async-debouncer/injectAsyncDebouncedCallback.ts +0 -50
- package/src/async-debouncer/injectAsyncDebouncer.ts +0 -152
- package/src/async-queuer/index.ts +0 -4
- package/src/async-queuer/injectAsyncQueuedSignal.ts +0 -74
- package/src/async-queuer/injectAsyncQueuer.ts +0 -126
- package/src/async-rate-limiter/index.ts +0 -4
- package/src/async-rate-limiter/injectAsyncRateLimitedCallback.ts +0 -52
- package/src/async-rate-limiter/injectAsyncRateLimiter.ts +0 -115
- package/src/async-retryer/index.ts +0 -1
- package/src/async-throttler/index.ts +0 -4
- package/src/async-throttler/injectAsyncThrottledCallback.ts +0 -50
- package/src/async-throttler/injectAsyncThrottler.ts +0 -131
- package/src/batcher/index.ts +0 -4
- package/src/batcher/injectBatchedCallback.ts +0 -46
- package/src/batcher/injectBatcher.ts +0 -114
- package/src/debouncer/index.ts +0 -6
- package/src/debouncer/injectDebouncedCallback.ts +0 -46
- package/src/debouncer/injectDebouncedSignal.ts +0 -94
- package/src/debouncer/injectDebouncedValue.ts +0 -126
- package/src/debouncer/injectDebouncer.ts +0 -137
- package/src/index.ts +0 -40
- package/src/provider/index.ts +0 -2
- package/src/provider/pacer-context.ts +0 -46
- package/src/provider/pacer-provider.ts +0 -38
- package/src/queuer/index.ts +0 -5
- package/src/queuer/injectQueuedSignal.ts +0 -65
- package/src/queuer/injectQueuedValue.ts +0 -101
- package/src/queuer/injectQueuer.ts +0 -118
- package/src/rate-limiter/index.ts +0 -6
- package/src/rate-limiter/injectRateLimitedCallback.ts +0 -45
- package/src/rate-limiter/injectRateLimitedSignal.ts +0 -88
- package/src/rate-limiter/injectRateLimitedValue.ts +0 -99
- package/src/rate-limiter/injectRateLimiter.ts +0 -140
- package/src/throttler/index.ts +0 -6
- package/src/throttler/injectThrottledCallback.ts +0 -45
- package/src/throttler/injectThrottledSignal.ts +0 -95
- package/src/throttler/injectThrottledValue.ts +0 -124
- package/src/throttler/injectThrottler.ts +0 -137
- package/src/types/index.ts +0 -1
- package/src/utils/index.ts +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectAsyncBatchedCallback.js","names":[],"sources":["../../src/async-batcher/injectAsyncBatchedCallback.ts"],"sourcesContent":["import { injectAsyncBatcher } from './injectAsyncBatcher'\nimport type { AsyncBatcherOptions } from '@tanstack/pacer/async-batcher'\n\n/**\n * An Angular function that creates an async batched version of a callback function.\n * This function is essentially a wrapper around `injectAsyncBatcher` that provides\n * a simplified API for basic async batching needs.\n *\n * The batched function will collect items and process them in batches asynchronously based on\n * the configured conditions (maxSize, wait time, etc.).\n *\n * This function provides a simpler API compared to `injectAsyncBatcher`, making it ideal for basic\n * async batching needs. However, it does not expose the underlying AsyncBatcher instance.\n *\n * For advanced usage requiring features like:\n * - Manual flushing\n * - Access to batch state\n * - Error handling callbacks\n * - Retry support\n *\n * Consider using the `injectAsyncBatcher` function instead.\n *\n * @example\n * ```ts\n * // Batch async API calls\n * const batchApiCall = injectAsyncBatchedCallback(\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: 1000 }\n * );\n *\n * // Items will be batched and sent together\n * await batchApiCall(data1);\n * await batchApiCall(data2);\n * ```\n */\nexport function injectAsyncBatchedCallback<TValue>(\n fn: (items: Array<TValue>) => Promise<any>,\n options: AsyncBatcherOptions<TValue>,\n): (item: TValue) => Promise<void> {\n const batcher = injectAsyncBatcher(fn, options)\n return (item: TValue) => batcher.addItem(item)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,2BACd,IACA,SACiC;CACjC,MAAM,UAAU,mBAAmB,IAAI,QAAQ;CAC/C,QAAQ,SAAiB,QAAQ,QAAQ,KAAK"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
const require_pacer_context = require('../provider/pacer-context.cjs');
|
|
2
|
-
let _angular_core = require("@angular/core");
|
|
3
|
-
let _tanstack_angular_store = require("@tanstack/angular-store");
|
|
4
|
-
let _tanstack_pacer_async_batcher = require("@tanstack/pacer/async-batcher");
|
|
5
|
-
|
|
6
|
-
//#region src/async-batcher/injectAsyncBatcher.ts
|
|
7
|
-
/**
|
|
8
|
-
* An Angular function that creates and manages an AsyncBatcher instance.
|
|
9
|
-
*
|
|
10
|
-
* This is a lower-level function that provides direct access to the AsyncBatcher's functionality.
|
|
11
|
-
* This allows you to integrate it with any state management solution you prefer.
|
|
12
|
-
*
|
|
13
|
-
* The AsyncBatcher collects items and processes them in batches asynchronously with support for
|
|
14
|
-
* promise-based processing, error handling, retry capabilities, and abort support.
|
|
15
|
-
*
|
|
16
|
-
* ## State Management and Selector
|
|
17
|
-
*
|
|
18
|
-
* The function uses TanStack Store for state management and wraps it with Angular signals.
|
|
19
|
-
* The `selector` parameter allows you to specify which state changes will trigger signal updates,
|
|
20
|
-
* optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
|
|
21
|
-
*
|
|
22
|
-
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
23
|
-
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
24
|
-
* full control over when your component tracks state changes.
|
|
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
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```ts
|
|
42
|
-
* // Default behavior - no reactive state subscriptions
|
|
43
|
-
* const batcher = injectAsyncBatcher(
|
|
44
|
-
* async (items: Array<Data>) => {
|
|
45
|
-
* const response = await fetch('/api/batch', {
|
|
46
|
-
* method: 'POST',
|
|
47
|
-
* body: JSON.stringify(items)
|
|
48
|
-
* });
|
|
49
|
-
* return response.json();
|
|
50
|
-
* },
|
|
51
|
-
* { maxSize: 10, wait: 2000 }
|
|
52
|
-
* );
|
|
53
|
-
*
|
|
54
|
-
* // Add items
|
|
55
|
-
* batcher.addItem(data1);
|
|
56
|
-
* batcher.addItem(data2);
|
|
57
|
-
*
|
|
58
|
-
* // Access the selected state
|
|
59
|
-
* const { items, isExecuting } = batcher.state();
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
function injectAsyncBatcher(fn, options = {}, selector = () => ({})) {
|
|
63
|
-
const mergedOptions = {
|
|
64
|
-
...require_pacer_context.injectPacerOptions().asyncBatcher,
|
|
65
|
-
...options
|
|
66
|
-
};
|
|
67
|
-
const batcher = new _tanstack_pacer_async_batcher.AsyncBatcher(fn, mergedOptions);
|
|
68
|
-
const state = (0, _tanstack_angular_store.injectSelector)(batcher.store, selector);
|
|
69
|
-
const result = {
|
|
70
|
-
...batcher,
|
|
71
|
-
state
|
|
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;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
//#endregion
|
|
84
|
-
exports.injectAsyncBatcher = injectAsyncBatcher;
|
|
85
|
-
//# sourceMappingURL=injectAsyncBatcher.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectAsyncBatcher.cjs","names":["injectPacerOptions","AsyncBatcher","DestroyRef"],"sources":["../../src/async-batcher/injectAsyncBatcher.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } 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 = injectSelector(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,oDAAuB,QAAQ,OAAO,SAAS;CAErD,MAAM,SAAS;EACb,GAAG;EACH;EACD;CAGD,0BAD0BC,0BAAY,EAAE,UAAU,MAAM,CAC9C,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,OAAO;OAC1B;GACL,QAAQ,QAAQ;GAChB,QAAQ,OAAO;;GAEjB;CAEF,OAAO"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { AsyncBatcher, AsyncBatcherOptions, AsyncBatcherState } from "@tanstack/pacer/async-batcher";
|
|
2
|
-
import { Signal } from "@angular/core";
|
|
3
|
-
import { Store } from "@tanstack/angular-store";
|
|
4
|
-
|
|
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
|
-
}
|
|
14
|
-
interface AngularAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBatcher<TValue>, 'store'> {
|
|
15
|
-
/**
|
|
16
|
-
* Reactive state signal that will be updated when the async batcher state changes
|
|
17
|
-
*
|
|
18
|
-
* Use this instead of `batcher.store.state`
|
|
19
|
-
*/
|
|
20
|
-
readonly state: Signal<Readonly<TSelected>>;
|
|
21
|
-
/**
|
|
22
|
-
* @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.
|
|
23
|
-
* The state on the store object is not reactive in Angular signals.
|
|
24
|
-
*/
|
|
25
|
-
readonly store: Store<Readonly<AsyncBatcherState<TValue>>>;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* An Angular function that creates and manages an AsyncBatcher instance.
|
|
29
|
-
*
|
|
30
|
-
* This is a lower-level function that provides direct access to the AsyncBatcher's functionality.
|
|
31
|
-
* This allows you to integrate it with any state management solution you prefer.
|
|
32
|
-
*
|
|
33
|
-
* The AsyncBatcher collects items and processes them in batches asynchronously with support for
|
|
34
|
-
* promise-based processing, error handling, retry capabilities, and abort support.
|
|
35
|
-
*
|
|
36
|
-
* ## State Management and Selector
|
|
37
|
-
*
|
|
38
|
-
* The function uses TanStack Store for state management and wraps it with Angular signals.
|
|
39
|
-
* The `selector` parameter allows you to specify which state changes will trigger signal updates,
|
|
40
|
-
* optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
|
|
41
|
-
*
|
|
42
|
-
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
43
|
-
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
44
|
-
* full control over when your component tracks state changes.
|
|
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
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* ```ts
|
|
62
|
-
* // Default behavior - no reactive state subscriptions
|
|
63
|
-
* const batcher = injectAsyncBatcher(
|
|
64
|
-
* async (items: Array<Data>) => {
|
|
65
|
-
* const response = await fetch('/api/batch', {
|
|
66
|
-
* method: 'POST',
|
|
67
|
-
* body: JSON.stringify(items)
|
|
68
|
-
* });
|
|
69
|
-
* return response.json();
|
|
70
|
-
* },
|
|
71
|
-
* { maxSize: 10, wait: 2000 }
|
|
72
|
-
* );
|
|
73
|
-
*
|
|
74
|
-
* // Add items
|
|
75
|
-
* batcher.addItem(data1);
|
|
76
|
-
* batcher.addItem(data2);
|
|
77
|
-
*
|
|
78
|
-
* // Access the selected state
|
|
79
|
-
* const { items, isExecuting } = batcher.state();
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
declare function injectAsyncBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => Promise<any>, options?: AngularAsyncBatcherOptions<TValue, TSelected>, selector?: (state: AsyncBatcherState<TValue>) => TSelected): AngularAsyncBatcher<TValue, TSelected>;
|
|
83
|
-
//#endregion
|
|
84
|
-
export { AngularAsyncBatcher, AngularAsyncBatcherOptions, injectAsyncBatcher };
|
|
85
|
-
//# sourceMappingURL=injectAsyncBatcher.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectAsyncBatcher.js","names":[],"sources":["../../src/async-batcher/injectAsyncBatcher.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } 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 = injectSelector(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,eAAe,QAAQ,OAAO,SAAS;CAErD,MAAM,SAAS;EACb,GAAG;EACH;EACD;CAGD,AADmB,OAAO,YAAY,EAAE,UAAU,MAAM,CAC9C,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,OAAO;OAC1B;GACL,QAAQ,QAAQ;GAChB,QAAQ,OAAO;;GAEjB;CAEF,OAAO"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_injectAsyncDebouncer = require('./injectAsyncDebouncer.cjs');
|
|
3
|
-
const require_injectAsyncDebouncedCallback = require('./injectAsyncDebouncedCallback.cjs');
|
|
4
|
-
|
|
5
|
-
exports.injectAsyncDebouncedCallback = require_injectAsyncDebouncedCallback.injectAsyncDebouncedCallback;
|
|
6
|
-
exports.injectAsyncDebouncer = require_injectAsyncDebouncer.injectAsyncDebouncer;
|
|
7
|
-
var _tanstack_pacer_async_debouncer = require("@tanstack/pacer/async-debouncer");
|
|
8
|
-
Object.keys(_tanstack_pacer_async_debouncer).forEach(function (k) {
|
|
9
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function () { return _tanstack_pacer_async_debouncer[k]; }
|
|
12
|
-
});
|
|
13
|
-
});
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { injectAsyncDebouncedCallback } from "./injectAsyncDebouncedCallback.cjs";
|
|
2
|
-
import { AngularAsyncDebouncer, AngularAsyncDebouncerOptions, injectAsyncDebouncer } from "./injectAsyncDebouncer.cjs";
|
|
3
|
-
export * from "@tanstack/pacer/async-debouncer";
|
|
4
|
-
export { AngularAsyncDebouncer, AngularAsyncDebouncerOptions, injectAsyncDebouncedCallback, injectAsyncDebouncer };
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
const require_injectAsyncDebouncer = require('./injectAsyncDebouncer.cjs');
|
|
2
|
-
|
|
3
|
-
//#region src/async-debouncer/injectAsyncDebouncedCallback.ts
|
|
4
|
-
/**
|
|
5
|
-
* An Angular function that creates an async debounced version of a callback function.
|
|
6
|
-
* This function is essentially a wrapper around `injectAsyncDebouncer` that provides
|
|
7
|
-
* a simplified API for basic async debouncing needs.
|
|
8
|
-
*
|
|
9
|
-
* The debounced function will only execute after the specified wait time has elapsed
|
|
10
|
-
* since its last invocation. If called again before the wait time expires, the timer
|
|
11
|
-
* resets and starts waiting again.
|
|
12
|
-
*
|
|
13
|
-
* This function provides a simpler API compared to `injectAsyncDebouncer`, making it ideal for basic
|
|
14
|
-
* async debouncing needs. However, it does not expose the underlying AsyncDebouncer instance.
|
|
15
|
-
*
|
|
16
|
-
* For advanced usage requiring features like:
|
|
17
|
-
* - Manual cancellation
|
|
18
|
-
* - Access to execution counts
|
|
19
|
-
* - Error handling callbacks
|
|
20
|
-
* - Retry support
|
|
21
|
-
*
|
|
22
|
-
* Consider using the `injectAsyncDebouncer` function instead.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* // Debounce an async search handler
|
|
27
|
-
* const handleSearch = injectAsyncDebouncedCallback(
|
|
28
|
-
* async (query: string) => {
|
|
29
|
-
* const response = await fetch(`/api/search?q=${query}`);
|
|
30
|
-
* return response.json();
|
|
31
|
-
* },
|
|
32
|
-
* { wait: 500 }
|
|
33
|
-
* );
|
|
34
|
-
*
|
|
35
|
-
* // Use in an input
|
|
36
|
-
* const results = await handleSearch(searchQuery);
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
function injectAsyncDebouncedCallback(fn, options) {
|
|
40
|
-
const debouncer = require_injectAsyncDebouncer.injectAsyncDebouncer(fn, options);
|
|
41
|
-
return async (...args) => {
|
|
42
|
-
const result = await debouncer.maybeExecute(...args);
|
|
43
|
-
return result !== void 0 ? await result : void 0;
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
//#endregion
|
|
48
|
-
exports.injectAsyncDebouncedCallback = injectAsyncDebouncedCallback;
|
|
49
|
-
//# sourceMappingURL=injectAsyncDebouncedCallback.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectAsyncDebouncedCallback.cjs","names":["injectAsyncDebouncer"],"sources":["../../src/async-debouncer/injectAsyncDebouncedCallback.ts"],"sourcesContent":["import { injectAsyncDebouncer } from './injectAsyncDebouncer'\nimport type { AsyncDebouncerOptions } from '@tanstack/pacer/async-debouncer'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\n\n/**\n * An Angular function that creates an async debounced version of a callback function.\n * This function is essentially a wrapper around `injectAsyncDebouncer` that provides\n * a simplified API for basic async debouncing needs.\n *\n * The debounced function will only execute after the specified wait time has elapsed\n * since its last invocation. If called again before the wait time expires, the timer\n * resets and starts waiting again.\n *\n * This function provides a simpler API compared to `injectAsyncDebouncer`, making it ideal for basic\n * async debouncing needs. However, it does not expose the underlying AsyncDebouncer instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - Error handling callbacks\n * - Retry support\n *\n * Consider using the `injectAsyncDebouncer` function instead.\n *\n * @example\n * ```ts\n * // Debounce an async search handler\n * const handleSearch = injectAsyncDebouncedCallback(\n * async (query: string) => {\n * const response = await fetch(`/api/search?q=${query}`);\n * return response.json();\n * },\n * { wait: 500 }\n * );\n *\n * // Use in an input\n * const results = await handleSearch(searchQuery);\n * ```\n */\nexport function injectAsyncDebouncedCallback<TFn extends AnyAsyncFunction>(\n fn: TFn,\n options: AsyncDebouncerOptions<TFn>,\n): (...args: Parameters<TFn>) => Promise<Awaited<ReturnType<TFn>> | undefined> {\n const debouncer = injectAsyncDebouncer(fn, options)\n return async (...args: Parameters<TFn>) => {\n const result = await debouncer.maybeExecute(...args)\n // Not sure if this is the best way to handle this,\n return result !== undefined ? await result : undefined\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,6BACd,IACA,SAC6E;CAC7E,MAAM,YAAYA,kDAAqB,IAAI,QAAQ;CACnD,OAAO,OAAO,GAAG,SAA0B;EACzC,MAAM,SAAS,MAAM,UAAU,aAAa,GAAG,KAAK;EAEpD,OAAO,WAAW,SAAY,MAAM,SAAS"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { AsyncDebouncerOptions } from "@tanstack/pacer/async-debouncer";
|
|
2
|
-
import { AnyAsyncFunction } from "@tanstack/pacer/types";
|
|
3
|
-
|
|
4
|
-
//#region src/async-debouncer/injectAsyncDebouncedCallback.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* An Angular function that creates an async debounced version of a callback function.
|
|
7
|
-
* This function is essentially a wrapper around `injectAsyncDebouncer` that provides
|
|
8
|
-
* a simplified API for basic async debouncing needs.
|
|
9
|
-
*
|
|
10
|
-
* The debounced function will only execute after the specified wait time has elapsed
|
|
11
|
-
* since its last invocation. If called again before the wait time expires, the timer
|
|
12
|
-
* resets and starts waiting again.
|
|
13
|
-
*
|
|
14
|
-
* This function provides a simpler API compared to `injectAsyncDebouncer`, making it ideal for basic
|
|
15
|
-
* async debouncing needs. However, it does not expose the underlying AsyncDebouncer instance.
|
|
16
|
-
*
|
|
17
|
-
* For advanced usage requiring features like:
|
|
18
|
-
* - Manual cancellation
|
|
19
|
-
* - Access to execution counts
|
|
20
|
-
* - Error handling callbacks
|
|
21
|
-
* - Retry support
|
|
22
|
-
*
|
|
23
|
-
* Consider using the `injectAsyncDebouncer` function instead.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* // Debounce an async search handler
|
|
28
|
-
* const handleSearch = injectAsyncDebouncedCallback(
|
|
29
|
-
* async (query: string) => {
|
|
30
|
-
* const response = await fetch(`/api/search?q=${query}`);
|
|
31
|
-
* return response.json();
|
|
32
|
-
* },
|
|
33
|
-
* { wait: 500 }
|
|
34
|
-
* );
|
|
35
|
-
*
|
|
36
|
-
* // Use in an input
|
|
37
|
-
* const results = await handleSearch(searchQuery);
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
declare function injectAsyncDebouncedCallback<TFn extends AnyAsyncFunction>(fn: TFn, options: AsyncDebouncerOptions<TFn>): (...args: Parameters<TFn>) => Promise<Awaited<ReturnType<TFn>> | undefined>;
|
|
41
|
-
//#endregion
|
|
42
|
-
export { injectAsyncDebouncedCallback };
|
|
43
|
-
//# sourceMappingURL=injectAsyncDebouncedCallback.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectAsyncDebouncedCallback.js","names":[],"sources":["../../src/async-debouncer/injectAsyncDebouncedCallback.ts"],"sourcesContent":["import { injectAsyncDebouncer } from './injectAsyncDebouncer'\nimport type { AsyncDebouncerOptions } from '@tanstack/pacer/async-debouncer'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\n\n/**\n * An Angular function that creates an async debounced version of a callback function.\n * This function is essentially a wrapper around `injectAsyncDebouncer` that provides\n * a simplified API for basic async debouncing needs.\n *\n * The debounced function will only execute after the specified wait time has elapsed\n * since its last invocation. If called again before the wait time expires, the timer\n * resets and starts waiting again.\n *\n * This function provides a simpler API compared to `injectAsyncDebouncer`, making it ideal for basic\n * async debouncing needs. However, it does not expose the underlying AsyncDebouncer instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - Error handling callbacks\n * - Retry support\n *\n * Consider using the `injectAsyncDebouncer` function instead.\n *\n * @example\n * ```ts\n * // Debounce an async search handler\n * const handleSearch = injectAsyncDebouncedCallback(\n * async (query: string) => {\n * const response = await fetch(`/api/search?q=${query}`);\n * return response.json();\n * },\n * { wait: 500 }\n * );\n *\n * // Use in an input\n * const results = await handleSearch(searchQuery);\n * ```\n */\nexport function injectAsyncDebouncedCallback<TFn extends AnyAsyncFunction>(\n fn: TFn,\n options: AsyncDebouncerOptions<TFn>,\n): (...args: Parameters<TFn>) => Promise<Awaited<ReturnType<TFn>> | undefined> {\n const debouncer = injectAsyncDebouncer(fn, options)\n return async (...args: Parameters<TFn>) => {\n const result = await debouncer.maybeExecute(...args)\n // Not sure if this is the best way to handle this,\n return result !== undefined ? await result : undefined\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,6BACd,IACA,SAC6E;CAC7E,MAAM,YAAY,qBAAqB,IAAI,QAAQ;CACnD,OAAO,OAAO,GAAG,SAA0B;EACzC,MAAM,SAAS,MAAM,UAAU,aAAa,GAAG,KAAK;EAEpD,OAAO,WAAW,SAAY,MAAM,SAAS"}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
const require_pacer_context = require('../provider/pacer-context.cjs');
|
|
2
|
-
let _angular_core = require("@angular/core");
|
|
3
|
-
let _tanstack_angular_store = require("@tanstack/angular-store");
|
|
4
|
-
let _tanstack_pacer_async_debouncer = require("@tanstack/pacer/async-debouncer");
|
|
5
|
-
|
|
6
|
-
//#region src/async-debouncer/injectAsyncDebouncer.ts
|
|
7
|
-
/**
|
|
8
|
-
* An Angular function that creates and manages an AsyncDebouncer instance.
|
|
9
|
-
*
|
|
10
|
-
* This is a lower-level function that provides direct access to the AsyncDebouncer's functionality.
|
|
11
|
-
* This allows you to integrate it with any state management solution you prefer.
|
|
12
|
-
*
|
|
13
|
-
* This function provides async debouncing functionality with promise support, error handling,
|
|
14
|
-
* retry capabilities, and abort support.
|
|
15
|
-
*
|
|
16
|
-
* The debouncer will only execute the function after the specified wait time has elapsed
|
|
17
|
-
* since the last call. If the function is called again before the wait time expires, the
|
|
18
|
-
* timer resets and starts waiting again.
|
|
19
|
-
*
|
|
20
|
-
* ## State Management and Selector
|
|
21
|
-
*
|
|
22
|
-
* The function uses TanStack Store for state management and wraps it with Angular signals.
|
|
23
|
-
* The `selector` parameter allows you to specify which state changes will trigger signal updates,
|
|
24
|
-
* optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
|
|
25
|
-
*
|
|
26
|
-
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
27
|
-
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
28
|
-
* full control over when your component tracks state changes.
|
|
29
|
-
*
|
|
30
|
-
* Available state properties:
|
|
31
|
-
* - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
|
|
32
|
-
* - `errorCount`: Number of function executions that have resulted in errors
|
|
33
|
-
* - `isExecuting`: Whether the debounced function is currently executing asynchronously
|
|
34
|
-
* - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
|
|
35
|
-
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
36
|
-
* - `lastResult`: The result from the most recent successful function execution
|
|
37
|
-
* - `settleCount`: Number of function executions that have completed (either successfully or with errors)
|
|
38
|
-
* - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing' | 'settled')
|
|
39
|
-
* - `successCount`: Number of function executions that have completed successfully
|
|
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
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```ts
|
|
57
|
-
* // Default behavior - no reactive state subscriptions
|
|
58
|
-
* const debouncer = injectAsyncDebouncer(
|
|
59
|
-
* async (query: string) => {
|
|
60
|
-
* const response = await fetch(`/api/search?q=${query}`);
|
|
61
|
-
* return response.json();
|
|
62
|
-
* },
|
|
63
|
-
* { wait: 500 }
|
|
64
|
-
* );
|
|
65
|
-
*
|
|
66
|
-
* // Opt-in to track isExecuting changes (optimized for loading states)
|
|
67
|
-
* const debouncer = injectAsyncDebouncer(
|
|
68
|
-
* async (query: string) => fetchSearchResults(query),
|
|
69
|
-
* { wait: 500 },
|
|
70
|
-
* (state) => ({ isExecuting: state.isExecuting, isPending: state.isPending })
|
|
71
|
-
* );
|
|
72
|
-
*
|
|
73
|
-
* // In an event handler
|
|
74
|
-
* const handleChange = async (e: Event) => {
|
|
75
|
-
* const target = e.target as HTMLInputElement;
|
|
76
|
-
* const result = await debouncer.maybeExecute(target.value);
|
|
77
|
-
* console.log('Search results:', result);
|
|
78
|
-
* };
|
|
79
|
-
*
|
|
80
|
-
* // Access the selected state
|
|
81
|
-
* const { isExecuting, errorCount } = debouncer.state();
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
84
|
-
function injectAsyncDebouncer(fn, options, selector = () => ({})) {
|
|
85
|
-
const mergedOptions = {
|
|
86
|
-
...require_pacer_context.injectPacerOptions().asyncDebouncer,
|
|
87
|
-
...options
|
|
88
|
-
};
|
|
89
|
-
const debouncer = new _tanstack_pacer_async_debouncer.AsyncDebouncer(fn, mergedOptions);
|
|
90
|
-
const state = (0, _tanstack_angular_store.injectSelector)(debouncer.store, selector);
|
|
91
|
-
const result = {
|
|
92
|
-
...debouncer,
|
|
93
|
-
state
|
|
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;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
//#endregion
|
|
106
|
-
exports.injectAsyncDebouncer = injectAsyncDebouncer;
|
|
107
|
-
//# sourceMappingURL=injectAsyncDebouncer.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectAsyncDebouncer.cjs","names":["injectPacerOptions","AsyncDebouncer","DestroyRef"],"sources":["../../src/async-debouncer/injectAsyncDebouncer.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } 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 = injectSelector(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,oDAAuB,UAAU,OAAO,SAAS;CAEvD,MAAM,SAAS;EACb,GAAG;EACH;EACD;CAGD,0BAD0BC,0BAAY,EAAE,UAAU,MAAM,CAC9C,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,OAAO;OAC1B;GACL,UAAU,QAAQ;GAClB,UAAU,OAAO;;GAEnB;CAEF,OAAO"}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { Signal } from "@angular/core";
|
|
2
|
-
import { Store } from "@tanstack/angular-store";
|
|
3
|
-
import { AsyncDebouncer, AsyncDebouncerOptions, AsyncDebouncerState } from "@tanstack/pacer/async-debouncer";
|
|
4
|
-
import { AnyAsyncFunction } from "@tanstack/pacer/types";
|
|
5
|
-
|
|
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
|
-
}
|
|
15
|
-
interface AngularAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncDebouncer<TFn>, 'store'> {
|
|
16
|
-
/**
|
|
17
|
-
* Reactive state signal that will be updated when the async debouncer state changes
|
|
18
|
-
*
|
|
19
|
-
* Use this instead of `debouncer.store.state`
|
|
20
|
-
*/
|
|
21
|
-
readonly state: Signal<Readonly<TSelected>>;
|
|
22
|
-
/**
|
|
23
|
-
* @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.
|
|
24
|
-
* The state on the store object is not reactive in Angular signals.
|
|
25
|
-
*/
|
|
26
|
-
readonly store: Store<Readonly<AsyncDebouncerState<TFn>>>;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* An Angular function that creates and manages an AsyncDebouncer instance.
|
|
30
|
-
*
|
|
31
|
-
* This is a lower-level function that provides direct access to the AsyncDebouncer's functionality.
|
|
32
|
-
* This allows you to integrate it with any state management solution you prefer.
|
|
33
|
-
*
|
|
34
|
-
* This function provides async debouncing functionality with promise support, error handling,
|
|
35
|
-
* retry capabilities, and abort support.
|
|
36
|
-
*
|
|
37
|
-
* The debouncer will only execute the function after the specified wait time has elapsed
|
|
38
|
-
* since the last call. If the function is called again before the wait time expires, the
|
|
39
|
-
* timer resets and starts waiting again.
|
|
40
|
-
*
|
|
41
|
-
* ## State Management and Selector
|
|
42
|
-
*
|
|
43
|
-
* The function uses TanStack Store for state management and wraps it with Angular signals.
|
|
44
|
-
* The `selector` parameter allows you to specify which state changes will trigger signal updates,
|
|
45
|
-
* optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
|
|
46
|
-
*
|
|
47
|
-
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
48
|
-
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
49
|
-
* full control over when your component tracks state changes.
|
|
50
|
-
*
|
|
51
|
-
* Available state properties:
|
|
52
|
-
* - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
|
|
53
|
-
* - `errorCount`: Number of function executions that have resulted in errors
|
|
54
|
-
* - `isExecuting`: Whether the debounced function is currently executing asynchronously
|
|
55
|
-
* - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
|
|
56
|
-
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
57
|
-
* - `lastResult`: The result from the most recent successful function execution
|
|
58
|
-
* - `settleCount`: Number of function executions that have completed (either successfully or with errors)
|
|
59
|
-
* - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing' | 'settled')
|
|
60
|
-
* - `successCount`: Number of function executions that have completed successfully
|
|
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
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* ```ts
|
|
78
|
-
* // Default behavior - no reactive state subscriptions
|
|
79
|
-
* const debouncer = injectAsyncDebouncer(
|
|
80
|
-
* async (query: string) => {
|
|
81
|
-
* const response = await fetch(`/api/search?q=${query}`);
|
|
82
|
-
* return response.json();
|
|
83
|
-
* },
|
|
84
|
-
* { wait: 500 }
|
|
85
|
-
* );
|
|
86
|
-
*
|
|
87
|
-
* // Opt-in to track isExecuting changes (optimized for loading states)
|
|
88
|
-
* const debouncer = injectAsyncDebouncer(
|
|
89
|
-
* async (query: string) => fetchSearchResults(query),
|
|
90
|
-
* { wait: 500 },
|
|
91
|
-
* (state) => ({ isExecuting: state.isExecuting, isPending: state.isPending })
|
|
92
|
-
* );
|
|
93
|
-
*
|
|
94
|
-
* // In an event handler
|
|
95
|
-
* const handleChange = async (e: Event) => {
|
|
96
|
-
* const target = e.target as HTMLInputElement;
|
|
97
|
-
* const result = await debouncer.maybeExecute(target.value);
|
|
98
|
-
* console.log('Search results:', result);
|
|
99
|
-
* };
|
|
100
|
-
*
|
|
101
|
-
* // Access the selected state
|
|
102
|
-
* const { isExecuting, errorCount } = debouncer.state();
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
|
-
declare function injectAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: AngularAsyncDebouncerOptions<TFn, TSelected>, selector?: (state: AsyncDebouncerState<TFn>) => TSelected): AngularAsyncDebouncer<TFn, TSelected>;
|
|
106
|
-
//#endregion
|
|
107
|
-
export { AngularAsyncDebouncer, AngularAsyncDebouncerOptions, injectAsyncDebouncer };
|
|
108
|
-
//# sourceMappingURL=injectAsyncDebouncer.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectAsyncDebouncer.js","names":[],"sources":["../../src/async-debouncer/injectAsyncDebouncer.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } 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 = injectSelector(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,eAAe,UAAU,OAAO,SAAS;CAEvD,MAAM,SAAS;EACb,GAAG;EACH;EACD;CAGD,AADmB,OAAO,YAAY,EAAE,UAAU,MAAM,CAC9C,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,OAAO;OAC1B;GACL,UAAU,QAAQ;GAClB,UAAU,OAAO;;GAEnB;CAEF,OAAO"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_injectAsyncQueuer = require('./injectAsyncQueuer.cjs');
|
|
3
|
-
const require_injectAsyncQueuedSignal = require('./injectAsyncQueuedSignal.cjs');
|
|
4
|
-
|
|
5
|
-
exports.injectAsyncQueuedSignal = require_injectAsyncQueuedSignal.injectAsyncQueuedSignal;
|
|
6
|
-
exports.injectAsyncQueuer = require_injectAsyncQueuer.injectAsyncQueuer;
|
|
7
|
-
var _tanstack_pacer_async_queuer = require("@tanstack/pacer/async-queuer");
|
|
8
|
-
Object.keys(_tanstack_pacer_async_queuer).forEach(function (k) {
|
|
9
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function () { return _tanstack_pacer_async_queuer[k]; }
|
|
12
|
-
});
|
|
13
|
-
});
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { AngularAsyncQueuer, AngularAsyncQueuerOptions, injectAsyncQueuer } from "./injectAsyncQueuer.cjs";
|
|
2
|
-
import { AsyncQueuedSignal, injectAsyncQueuedSignal } from "./injectAsyncQueuedSignal.cjs";
|
|
3
|
-
export * from "@tanstack/pacer/async-queuer";
|
|
4
|
-
export { AngularAsyncQueuer, AngularAsyncQueuerOptions, AsyncQueuedSignal, injectAsyncQueuedSignal, injectAsyncQueuer };
|