@tanstack/angular-pacer 0.24.0 → 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 +4 -4
- package/dist/async-batcher/injectAsyncBatchedCallback.d.ts +2 -4
- package/dist/async-batcher/injectAsyncBatchedCallback.js +1 -2
- package/dist/async-batcher/injectAsyncBatcher.d.ts +4 -6
- package/dist/async-batcher/injectAsyncBatcher.js +1 -2
- package/dist/async-debouncer/injectAsyncDebouncedCallback.d.ts +2 -4
- package/dist/async-debouncer/injectAsyncDebouncedCallback.js +1 -2
- package/dist/async-debouncer/injectAsyncDebouncer.d.ts +4 -6
- package/dist/async-debouncer/injectAsyncDebouncer.js +1 -2
- package/dist/async-queuer/injectAsyncQueuedSignal.d.ts +3 -5
- package/dist/async-queuer/injectAsyncQueuedSignal.js +1 -2
- package/dist/async-queuer/injectAsyncQueuer.d.ts +4 -6
- package/dist/async-queuer/injectAsyncQueuer.js +1 -2
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.d.ts +2 -4
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.js +1 -2
- package/dist/async-rate-limiter/injectAsyncRateLimiter.d.ts +4 -6
- package/dist/async-rate-limiter/injectAsyncRateLimiter.js +1 -2
- package/dist/async-throttler/injectAsyncThrottledCallback.d.ts +2 -4
- package/dist/async-throttler/injectAsyncThrottledCallback.js +1 -2
- package/dist/async-throttler/injectAsyncThrottler.d.ts +4 -6
- package/dist/async-throttler/injectAsyncThrottler.js +1 -2
- package/dist/batcher/injectBatchedCallback.d.ts +2 -4
- package/dist/batcher/injectBatchedCallback.js +1 -2
- package/dist/batcher/injectBatcher.d.ts +4 -6
- package/dist/batcher/injectBatcher.js +1 -2
- package/dist/debouncer/injectDebouncedCallback.d.ts +2 -4
- package/dist/debouncer/injectDebouncedCallback.js +1 -2
- package/dist/debouncer/injectDebouncedSignal.d.ts +3 -5
- package/dist/debouncer/injectDebouncedSignal.js +1 -2
- package/dist/debouncer/injectDebouncedValue.d.ts +3 -5
- package/dist/debouncer/injectDebouncedValue.js +1 -2
- package/dist/debouncer/injectDebouncer.d.ts +4 -6
- package/dist/debouncer/injectDebouncer.js +1 -2
- package/dist/provider/pacer-context.d.ts +4 -6
- package/dist/provider/pacer-context.js +1 -2
- package/dist/provider/pacer-provider.d.ts +2 -4
- package/dist/provider/pacer-provider.js +1 -2
- package/dist/queuer/injectQueuedSignal.d.ts +3 -5
- package/dist/queuer/injectQueuedSignal.js +1 -2
- package/dist/queuer/injectQueuedValue.d.ts +3 -5
- package/dist/queuer/injectQueuedValue.js +1 -2
- package/dist/queuer/injectQueuer.d.ts +4 -6
- package/dist/queuer/injectQueuer.js +1 -2
- package/dist/rate-limiter/injectRateLimitedCallback.d.ts +2 -4
- package/dist/rate-limiter/injectRateLimitedCallback.js +1 -2
- package/dist/rate-limiter/injectRateLimitedSignal.d.ts +3 -5
- package/dist/rate-limiter/injectRateLimitedSignal.js +1 -2
- package/dist/rate-limiter/injectRateLimitedValue.d.ts +3 -5
- package/dist/rate-limiter/injectRateLimitedValue.js +1 -2
- package/dist/rate-limiter/injectRateLimiter.d.ts +4 -6
- package/dist/rate-limiter/injectRateLimiter.js +1 -2
- package/dist/throttler/injectThrottledCallback.d.ts +2 -4
- package/dist/throttler/injectThrottledCallback.js +1 -2
- package/dist/throttler/injectThrottledSignal.d.ts +3 -7
- package/dist/throttler/injectThrottledSignal.js +1 -4
- package/dist/throttler/injectThrottledValue.d.ts +3 -7
- package/dist/throttler/injectThrottledValue.js +1 -2
- package/dist/throttler/injectThrottler.d.ts +4 -8
- package/dist/throttler/injectThrottler.js +1 -4
- package/package.json +24 -71
- 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 -44
- 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 -84
- 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 -42
- 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 -107
- 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 -49
- 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 -84
- 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 -45
- 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 -71
- package/dist/async-rate-limiter/injectAsyncRateLimiter.js.map +0 -1
- package/dist/async-retryer/index.cjs +0 -8
- 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 -43
- 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 -86
- 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 -42
- 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 -76
- 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 -42
- 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 -59
- 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 -75
- 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 -97
- 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 -20
- 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 -35
- 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 -43
- 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 -33
- 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 -81
- 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 -41
- 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 -53
- 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 -48
- 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 -102
- 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 -41
- 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 -60
- 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 -73
- 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 -97
- package/dist/throttler/injectThrottler.js.map +0 -1
- package/dist/types/index.cjs +0 -8
- package/dist/types/index.d.cts +0 -1
- package/dist/utils/index.cjs +0 -8
- 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 -125
- 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 -99
- 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 -98
- 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 -123
- package/src/throttler/injectThrottler.ts +0 -137
- package/src/types/index.ts +0 -1
- package/src/utils/index.ts +0 -1
|
@@ -1,86 +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_throttler = require("@tanstack/pacer/async-throttler");
|
|
5
|
-
|
|
6
|
-
//#region src/async-throttler/injectAsyncThrottler.ts
|
|
7
|
-
/**
|
|
8
|
-
* An Angular function that creates and manages an AsyncThrottler instance.
|
|
9
|
-
*
|
|
10
|
-
* This is a lower-level function that provides direct access to the AsyncThrottler's functionality.
|
|
11
|
-
* This allows you to integrate it with any state management solution you prefer.
|
|
12
|
-
*
|
|
13
|
-
* This function provides async throttling functionality with promise support, error handling,
|
|
14
|
-
* retry capabilities, and abort support.
|
|
15
|
-
*
|
|
16
|
-
* The throttler will execute the function at most once within the specified wait time.
|
|
17
|
-
*
|
|
18
|
-
* ## State Management and Selector
|
|
19
|
-
*
|
|
20
|
-
* The function uses TanStack Store for state management and wraps it with Angular signals.
|
|
21
|
-
* The `selector` parameter allows you to specify which state changes will trigger signal updates,
|
|
22
|
-
* optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
|
|
23
|
-
*
|
|
24
|
-
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
25
|
-
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
26
|
-
* full control over when your component tracks state changes.
|
|
27
|
-
*
|
|
28
|
-
* ## Cleanup on Destroy
|
|
29
|
-
*
|
|
30
|
-
* By default, the function cancels any pending execution and aborts in-flight work when the component is destroyed.
|
|
31
|
-
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
32
|
-
*
|
|
33
|
-
* ```ts
|
|
34
|
-
* const throttler = injectAsyncThrottler(fn, {
|
|
35
|
-
* wait: 1000,
|
|
36
|
-
* onUnmount: (t) => t.flush()
|
|
37
|
-
* });
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```ts
|
|
44
|
-
* // Default behavior - no reactive state subscriptions
|
|
45
|
-
* const throttler = injectAsyncThrottler(
|
|
46
|
-
* async (data: Data) => {
|
|
47
|
-
* const response = await fetch('/api/update', {
|
|
48
|
-
* method: 'POST',
|
|
49
|
-
* body: JSON.stringify(data)
|
|
50
|
-
* });
|
|
51
|
-
* return response.json();
|
|
52
|
-
* },
|
|
53
|
-
* { wait: 1000 }
|
|
54
|
-
* );
|
|
55
|
-
*
|
|
56
|
-
* // In an event handler
|
|
57
|
-
* const handleUpdate = async (data: Data) => {
|
|
58
|
-
* const result = await throttler.maybeExecute(data);
|
|
59
|
-
* console.log('Update result:', result);
|
|
60
|
-
* };
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
function injectAsyncThrottler(fn, options, selector = () => ({})) {
|
|
64
|
-
const mergedOptions = {
|
|
65
|
-
...require_pacer_context.injectPacerOptions().asyncThrottler,
|
|
66
|
-
...options
|
|
67
|
-
};
|
|
68
|
-
const throttler = new _tanstack_pacer_async_throttler.AsyncThrottler(fn, mergedOptions);
|
|
69
|
-
const state = (0, _tanstack_angular_store.injectSelector)(throttler.store, selector);
|
|
70
|
-
const result = {
|
|
71
|
-
...throttler,
|
|
72
|
-
state
|
|
73
|
-
};
|
|
74
|
-
(0, _angular_core.inject)(_angular_core.DestroyRef, { optional: true })?.onDestroy(() => {
|
|
75
|
-
if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
|
|
76
|
-
else {
|
|
77
|
-
throttler.cancel();
|
|
78
|
-
throttler.abort();
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
return result;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
//#endregion
|
|
85
|
-
exports.injectAsyncThrottler = injectAsyncThrottler;
|
|
86
|
-
//# sourceMappingURL=injectAsyncThrottler.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectAsyncThrottler.cjs","names":["injectPacerOptions","AsyncThrottler","injectSelector","inject","DestroyRef"],"sources":["../../src/async-throttler/injectAsyncThrottler.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { AsyncThrottler } from '@tanstack/pacer/async-throttler'\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 AsyncThrottlerOptions,\n AsyncThrottlerState,\n} from '@tanstack/pacer/async-throttler'\n\nexport interface AngularAsyncThrottlerOptions<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends AsyncThrottlerOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the throttler 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?: (throttler: AngularAsyncThrottler<TFn, TSelected>) => void\n}\n\nexport interface AngularAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncThrottler<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the async throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `throttler.state` instead of `throttler.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<AsyncThrottlerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncThrottler instance.\n *\n * This is a lower-level function that provides direct access to the AsyncThrottler's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides async throttling functionality with promise support, error handling,\n * retry capabilities, and abort support.\n *\n * The throttler will execute the function at most once within the specified wait time.\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 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 throttler = injectAsyncThrottler(fn, {\n * wait: 1000,\n * onUnmount: (t) => t.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 throttler = injectAsyncThrottler(\n * async (data: Data) => {\n * const response = await fetch('/api/update', {\n * method: 'POST',\n * body: JSON.stringify(data)\n * });\n * return response.json();\n * },\n * { wait: 1000 }\n * );\n *\n * // In an event handler\n * const handleUpdate = async (data: Data) => {\n * const result = await throttler.maybeExecute(data);\n * console.log('Update result:', result);\n * };\n * ```\n */\nexport function injectAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AngularAsyncThrottlerOptions<TFn, TSelected>,\n selector: (state: AsyncThrottlerState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncThrottler,\n ...options,\n } as AngularAsyncThrottlerOptions<TFn, TSelected>\n\n const throttler = new AsyncThrottler<TFn>(fn, mergedOptions)\n const state = injectSelector(throttler.store, selector)\n\n const result = {\n ...throttler,\n state,\n } as AngularAsyncThrottler<TFn, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n throttler.cancel()\n throttler.abort()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiGA,SAAgB,qBAId,IACA,SACA,kBACG,CAAC,IACmC;CACvC,MAAM,gBAAgB;EACpB,GAAGA,yCAAmB,CAAC,CAAC;EACxB,GAAG;CACL;CAEA,MAAM,YAAY,IAAIC,+CAAoB,IAAI,aAAa;CAC3D,MAAM,YAAQC,wCAAe,UAAU,OAAO,QAAQ;CAEtD,MAAM,SAAS;EACb,GAAG;EACH;CACF;CAGA,IADmBC,sBAAOC,0BAAY,EAAE,UAAU,KAAK,CAC9C,CAAC,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,MAAM;OACzB;GACL,UAAU,OAAO;GACjB,UAAU,MAAM;EAClB;CACF,CAAC;CAED,OAAO;AACT"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { Signal } from "@angular/core";
|
|
2
|
-
import { Store } from "@tanstack/angular-store";
|
|
3
|
-
import { AnyAsyncFunction } from "@tanstack/pacer/types";
|
|
4
|
-
import { AsyncThrottler, AsyncThrottlerOptions, AsyncThrottlerState } from "@tanstack/pacer/async-throttler";
|
|
5
|
-
//#region src/async-throttler/injectAsyncThrottler.d.ts
|
|
6
|
-
interface AngularAsyncThrottlerOptions<TFn extends AnyAsyncFunction, TSelected = {}> extends AsyncThrottlerOptions<TFn> {
|
|
7
|
-
/**
|
|
8
|
-
* Optional callback invoked when the component is destroyed. Receives the throttler 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?: (throttler: AngularAsyncThrottler<TFn, TSelected>) => void;
|
|
13
|
-
}
|
|
14
|
-
interface AngularAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncThrottler<TFn>, 'store'> {
|
|
15
|
-
/**
|
|
16
|
-
* Reactive state signal that will be updated when the async throttler state changes
|
|
17
|
-
*
|
|
18
|
-
* Use this instead of `throttler.store.state`
|
|
19
|
-
*/
|
|
20
|
-
readonly state: Signal<Readonly<TSelected>>;
|
|
21
|
-
/**
|
|
22
|
-
* @deprecated Use `throttler.state` instead of `throttler.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<AsyncThrottlerState<TFn>>>;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* An Angular function that creates and manages an AsyncThrottler instance.
|
|
29
|
-
*
|
|
30
|
-
* This is a lower-level function that provides direct access to the AsyncThrottler's functionality.
|
|
31
|
-
* This allows you to integrate it with any state management solution you prefer.
|
|
32
|
-
*
|
|
33
|
-
* This function provides async throttling functionality with promise support, error handling,
|
|
34
|
-
* retry capabilities, and abort support.
|
|
35
|
-
*
|
|
36
|
-
* The throttler will execute the function at most once within the specified wait time.
|
|
37
|
-
*
|
|
38
|
-
* ## State Management and Selector
|
|
39
|
-
*
|
|
40
|
-
* The function uses TanStack Store for state management and wraps it with Angular signals.
|
|
41
|
-
* The `selector` parameter allows you to specify which state changes will trigger signal updates,
|
|
42
|
-
* optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
|
|
43
|
-
*
|
|
44
|
-
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
45
|
-
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
46
|
-
* full control over when your component tracks state changes.
|
|
47
|
-
*
|
|
48
|
-
* ## Cleanup on Destroy
|
|
49
|
-
*
|
|
50
|
-
* By default, the function cancels any pending execution and aborts in-flight work when the component is destroyed.
|
|
51
|
-
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
52
|
-
*
|
|
53
|
-
* ```ts
|
|
54
|
-
* const throttler = injectAsyncThrottler(fn, {
|
|
55
|
-
* wait: 1000,
|
|
56
|
-
* onUnmount: (t) => t.flush()
|
|
57
|
-
* });
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```ts
|
|
64
|
-
* // Default behavior - no reactive state subscriptions
|
|
65
|
-
* const throttler = injectAsyncThrottler(
|
|
66
|
-
* async (data: Data) => {
|
|
67
|
-
* const response = await fetch('/api/update', {
|
|
68
|
-
* method: 'POST',
|
|
69
|
-
* body: JSON.stringify(data)
|
|
70
|
-
* });
|
|
71
|
-
* return response.json();
|
|
72
|
-
* },
|
|
73
|
-
* { wait: 1000 }
|
|
74
|
-
* );
|
|
75
|
-
*
|
|
76
|
-
* // In an event handler
|
|
77
|
-
* const handleUpdate = async (data: Data) => {
|
|
78
|
-
* const result = await throttler.maybeExecute(data);
|
|
79
|
-
* console.log('Update result:', result);
|
|
80
|
-
* };
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
declare function injectAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: AngularAsyncThrottlerOptions<TFn, TSelected>, selector?: (state: AsyncThrottlerState<TFn>) => TSelected): AngularAsyncThrottler<TFn, TSelected>;
|
|
84
|
-
//#endregion
|
|
85
|
-
export { AngularAsyncThrottler, AngularAsyncThrottlerOptions, injectAsyncThrottler };
|
|
86
|
-
//# sourceMappingURL=injectAsyncThrottler.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectAsyncThrottler.js","names":[],"sources":["../../src/async-throttler/injectAsyncThrottler.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { AsyncThrottler } from '@tanstack/pacer/async-throttler'\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 AsyncThrottlerOptions,\n AsyncThrottlerState,\n} from '@tanstack/pacer/async-throttler'\n\nexport interface AngularAsyncThrottlerOptions<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends AsyncThrottlerOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the throttler 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?: (throttler: AngularAsyncThrottler<TFn, TSelected>) => void\n}\n\nexport interface AngularAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncThrottler<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the async throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `throttler.state` instead of `throttler.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<AsyncThrottlerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncThrottler instance.\n *\n * This is a lower-level function that provides direct access to the AsyncThrottler's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides async throttling functionality with promise support, error handling,\n * retry capabilities, and abort support.\n *\n * The throttler will execute the function at most once within the specified wait time.\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 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 throttler = injectAsyncThrottler(fn, {\n * wait: 1000,\n * onUnmount: (t) => t.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 throttler = injectAsyncThrottler(\n * async (data: Data) => {\n * const response = await fetch('/api/update', {\n * method: 'POST',\n * body: JSON.stringify(data)\n * });\n * return response.json();\n * },\n * { wait: 1000 }\n * );\n *\n * // In an event handler\n * const handleUpdate = async (data: Data) => {\n * const result = await throttler.maybeExecute(data);\n * console.log('Update result:', result);\n * };\n * ```\n */\nexport function injectAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AngularAsyncThrottlerOptions<TFn, TSelected>,\n selector: (state: AsyncThrottlerState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncThrottler,\n ...options,\n } as AngularAsyncThrottlerOptions<TFn, TSelected>\n\n const throttler = new AsyncThrottler<TFn>(fn, mergedOptions)\n const state = injectSelector(throttler.store, selector)\n\n const result = {\n ...throttler,\n state,\n } as AngularAsyncThrottler<TFn, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n throttler.cancel()\n throttler.abort()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiGA,SAAgB,qBAId,IACA,SACA,kBACG,CAAC,IACmC;CACvC,MAAM,gBAAgB;EACpB,GAAG,mBAAmB,CAAC,CAAC;EACxB,GAAG;CACL;CAEA,MAAM,YAAY,IAAI,eAAoB,IAAI,aAAa;CAC3D,MAAM,QAAQ,eAAe,UAAU,OAAO,QAAQ;CAEtD,MAAM,SAAS;EACb,GAAG;EACH;CACF;CAGA,AADmB,OAAO,YAAY,EAAE,UAAU,KAAK,CAC9C,CAAC,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,MAAM;OACzB;GACL,UAAU,OAAO;GACjB,UAAU,MAAM;EAClB;CACF,CAAC;CAED,OAAO;AACT"}
|
package/dist/batcher/index.cjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_injectBatcher = require('./injectBatcher.cjs');
|
|
3
|
-
const require_injectBatchedCallback = require('./injectBatchedCallback.cjs');
|
|
4
|
-
|
|
5
|
-
exports.injectBatchedCallback = require_injectBatchedCallback.injectBatchedCallback;
|
|
6
|
-
exports.injectBatcher = require_injectBatcher.injectBatcher;
|
|
7
|
-
var _tanstack_pacer_batcher = require("@tanstack/pacer/batcher");
|
|
8
|
-
Object.keys(_tanstack_pacer_batcher).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_batcher[k]; }
|
|
12
|
-
});
|
|
13
|
-
});
|
package/dist/batcher/index.d.cts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { injectBatchedCallback } from "./injectBatchedCallback.cjs";
|
|
2
|
-
import { AngularBatcher, AngularBatcherOptions, injectBatcher } from "./injectBatcher.cjs";
|
|
3
|
-
export * from "@tanstack/pacer/batcher";
|
|
4
|
-
export { AngularBatcher, AngularBatcherOptions, injectBatchedCallback, injectBatcher };
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
const require_injectBatcher = require('./injectBatcher.cjs');
|
|
2
|
-
|
|
3
|
-
//#region src/batcher/injectBatchedCallback.ts
|
|
4
|
-
/**
|
|
5
|
-
* An Angular function that creates a batched version of a callback function.
|
|
6
|
-
* This function is essentially a wrapper around `injectBatcher` that provides
|
|
7
|
-
* a simplified API for basic batching needs.
|
|
8
|
-
*
|
|
9
|
-
* The batched function will collect items and process them in batches based on
|
|
10
|
-
* the configured conditions (maxSize, wait time, etc.).
|
|
11
|
-
*
|
|
12
|
-
* This function provides a simpler API compared to `injectBatcher`, making it ideal for basic
|
|
13
|
-
* batching needs. However, it does not expose the underlying Batcher instance.
|
|
14
|
-
*
|
|
15
|
-
* For advanced usage requiring features like:
|
|
16
|
-
* - Manual flushing
|
|
17
|
-
* - Access to batch state
|
|
18
|
-
* - State tracking
|
|
19
|
-
*
|
|
20
|
-
* Consider using the `injectBatcher` function instead.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* // Batch API calls
|
|
25
|
-
* const batchApiCall = injectBatchedCallback(
|
|
26
|
-
* (items) => {
|
|
27
|
-
* return fetch('/api/batch', {
|
|
28
|
-
* method: 'POST',
|
|
29
|
-
* body: JSON.stringify(items)
|
|
30
|
-
* });
|
|
31
|
-
* },
|
|
32
|
-
* { maxSize: 10, wait: 1000 }
|
|
33
|
-
* );
|
|
34
|
-
*
|
|
35
|
-
* // Items will be batched and sent together
|
|
36
|
-
* batchApiCall('item1');
|
|
37
|
-
* batchApiCall('item2');
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
function injectBatchedCallback(fn, options) {
|
|
41
|
-
const batcher = require_injectBatcher.injectBatcher(fn, options);
|
|
42
|
-
return (item) => batcher.addItem(item);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
//#endregion
|
|
46
|
-
exports.injectBatchedCallback = injectBatchedCallback;
|
|
47
|
-
//# sourceMappingURL=injectBatchedCallback.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectBatchedCallback.cjs","names":["injectBatcher"],"sources":["../../src/batcher/injectBatchedCallback.ts"],"sourcesContent":["import { injectBatcher } from './injectBatcher'\nimport type { BatcherOptions } from '@tanstack/pacer/batcher'\n\n/**\n * An Angular function that creates a batched version of a callback function.\n * This function is essentially a wrapper around `injectBatcher` that provides\n * a simplified API for basic batching needs.\n *\n * The batched function will collect items and process them in batches based on\n * the configured conditions (maxSize, wait time, etc.).\n *\n * This function provides a simpler API compared to `injectBatcher`, making it ideal for basic\n * batching needs. However, it does not expose the underlying Batcher instance.\n *\n * For advanced usage requiring features like:\n * - Manual flushing\n * - Access to batch state\n * - State tracking\n *\n * Consider using the `injectBatcher` function instead.\n *\n * @example\n * ```ts\n * // Batch API calls\n * const batchApiCall = injectBatchedCallback(\n * (items) => {\n * return fetch('/api/batch', {\n * method: 'POST',\n * body: JSON.stringify(items)\n * });\n * },\n * { maxSize: 10, wait: 1000 }\n * );\n *\n * // Items will be batched and sent together\n * batchApiCall('item1');\n * batchApiCall('item2');\n * ```\n */\nexport function injectBatchedCallback<TValue>(\n fn: (items: Array<TValue>) => void,\n options: BatcherOptions<TValue>,\n): (item: TValue) => void {\n const batcher = injectBatcher(fn, options)\n return (item: TValue) => batcher.addItem(item)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,sBACd,IACA,SACwB;CACxB,MAAM,UAAUA,oCAAc,IAAI,OAAO;CACzC,QAAQ,SAAiB,QAAQ,QAAQ,IAAI;AAC/C"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { BatcherOptions } from "@tanstack/pacer/batcher";
|
|
2
|
-
//#region src/batcher/injectBatchedCallback.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* An Angular function that creates a batched version of a callback function.
|
|
5
|
-
* This function is essentially a wrapper around `injectBatcher` that provides
|
|
6
|
-
* a simplified API for basic batching needs.
|
|
7
|
-
*
|
|
8
|
-
* The batched function will collect items and process them in batches based on
|
|
9
|
-
* the configured conditions (maxSize, wait time, etc.).
|
|
10
|
-
*
|
|
11
|
-
* This function provides a simpler API compared to `injectBatcher`, making it ideal for basic
|
|
12
|
-
* batching needs. However, it does not expose the underlying Batcher instance.
|
|
13
|
-
*
|
|
14
|
-
* For advanced usage requiring features like:
|
|
15
|
-
* - Manual flushing
|
|
16
|
-
* - Access to batch state
|
|
17
|
-
* - State tracking
|
|
18
|
-
*
|
|
19
|
-
* Consider using the `injectBatcher` function instead.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* // Batch API calls
|
|
24
|
-
* const batchApiCall = injectBatchedCallback(
|
|
25
|
-
* (items) => {
|
|
26
|
-
* return fetch('/api/batch', {
|
|
27
|
-
* method: 'POST',
|
|
28
|
-
* body: JSON.stringify(items)
|
|
29
|
-
* });
|
|
30
|
-
* },
|
|
31
|
-
* { maxSize: 10, wait: 1000 }
|
|
32
|
-
* );
|
|
33
|
-
*
|
|
34
|
-
* // Items will be batched and sent together
|
|
35
|
-
* batchApiCall('item1');
|
|
36
|
-
* batchApiCall('item2');
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
declare function injectBatchedCallback<TValue>(fn: (items: Array<TValue>) => void, options: BatcherOptions<TValue>): (item: TValue) => void;
|
|
40
|
-
//#endregion
|
|
41
|
-
export { injectBatchedCallback };
|
|
42
|
-
//# sourceMappingURL=injectBatchedCallback.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectBatchedCallback.js","names":[],"sources":["../../src/batcher/injectBatchedCallback.ts"],"sourcesContent":["import { injectBatcher } from './injectBatcher'\nimport type { BatcherOptions } from '@tanstack/pacer/batcher'\n\n/**\n * An Angular function that creates a batched version of a callback function.\n * This function is essentially a wrapper around `injectBatcher` that provides\n * a simplified API for basic batching needs.\n *\n * The batched function will collect items and process them in batches based on\n * the configured conditions (maxSize, wait time, etc.).\n *\n * This function provides a simpler API compared to `injectBatcher`, making it ideal for basic\n * batching needs. However, it does not expose the underlying Batcher instance.\n *\n * For advanced usage requiring features like:\n * - Manual flushing\n * - Access to batch state\n * - State tracking\n *\n * Consider using the `injectBatcher` function instead.\n *\n * @example\n * ```ts\n * // Batch API calls\n * const batchApiCall = injectBatchedCallback(\n * (items) => {\n * return fetch('/api/batch', {\n * method: 'POST',\n * body: JSON.stringify(items)\n * });\n * },\n * { maxSize: 10, wait: 1000 }\n * );\n *\n * // Items will be batched and sent together\n * batchApiCall('item1');\n * batchApiCall('item2');\n * ```\n */\nexport function injectBatchedCallback<TValue>(\n fn: (items: Array<TValue>) => void,\n options: BatcherOptions<TValue>,\n): (item: TValue) => void {\n const batcher = injectBatcher(fn, options)\n return (item: TValue) => batcher.addItem(item)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,sBACd,IACA,SACwB;CACxB,MAAM,UAAU,cAAc,IAAI,OAAO;CACzC,QAAQ,SAAiB,QAAQ,QAAQ,IAAI;AAC/C"}
|
|
@@ -1,75 +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_batcher = require("@tanstack/pacer/batcher");
|
|
5
|
-
|
|
6
|
-
//#region src/batcher/injectBatcher.ts
|
|
7
|
-
/**
|
|
8
|
-
* An Angular function that creates and manages a Batcher instance.
|
|
9
|
-
*
|
|
10
|
-
* This is a lower-level function that provides direct access to the Batcher's functionality.
|
|
11
|
-
* This allows you to integrate it with any state management solution you prefer.
|
|
12
|
-
*
|
|
13
|
-
* The Batcher collects items and processes them in batches based on configurable conditions:
|
|
14
|
-
* - Maximum batch size
|
|
15
|
-
* - Time-based batching (process after X milliseconds)
|
|
16
|
-
* - Custom batch processing logic via getShouldExecute
|
|
17
|
-
*
|
|
18
|
-
* ## State Management and Selector
|
|
19
|
-
*
|
|
20
|
-
* The function uses TanStack Store for state management and wraps it with Angular signals.
|
|
21
|
-
* The `selector` parameter allows you to specify which state changes will trigger signal updates,
|
|
22
|
-
* optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
|
|
23
|
-
*
|
|
24
|
-
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
25
|
-
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
26
|
-
* full control over when your component tracks state changes.
|
|
27
|
-
*
|
|
28
|
-
* ## Cleanup on Destroy
|
|
29
|
-
*
|
|
30
|
-
* By default, the function cancels any pending batch when the component is destroyed.
|
|
31
|
-
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
32
|
-
*
|
|
33
|
-
* ```ts
|
|
34
|
-
* const batcher = injectBatcher(fn, {
|
|
35
|
-
* maxSize: 5,
|
|
36
|
-
* onUnmount: (b) => b.flush()
|
|
37
|
-
* });
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```ts
|
|
42
|
-
* // Default behavior - no reactive state subscriptions
|
|
43
|
-
* const batcher = injectBatcher(
|
|
44
|
-
* (items) => console.log('Processing batch:', items),
|
|
45
|
-
* { maxSize: 5, wait: 2000 }
|
|
46
|
-
* );
|
|
47
|
-
*
|
|
48
|
-
* // Add items
|
|
49
|
-
* batcher.addItem('task1');
|
|
50
|
-
*
|
|
51
|
-
* // Access the selected state
|
|
52
|
-
* const { items, isPending } = batcher.state();
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
function injectBatcher(fn, options = {}, selector = () => ({})) {
|
|
56
|
-
const mergedOptions = {
|
|
57
|
-
...require_pacer_context.injectPacerOptions().batcher,
|
|
58
|
-
...options
|
|
59
|
-
};
|
|
60
|
-
const batcher = new _tanstack_pacer_batcher.Batcher(fn, mergedOptions);
|
|
61
|
-
const state = (0, _tanstack_angular_store.injectSelector)(batcher.store, selector);
|
|
62
|
-
const result = {
|
|
63
|
-
...batcher,
|
|
64
|
-
state
|
|
65
|
-
};
|
|
66
|
-
(0, _angular_core.inject)(_angular_core.DestroyRef, { optional: true })?.onDestroy(() => {
|
|
67
|
-
if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
|
|
68
|
-
else batcher.cancel();
|
|
69
|
-
});
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
//#endregion
|
|
74
|
-
exports.injectBatcher = injectBatcher;
|
|
75
|
-
//# sourceMappingURL=injectBatcher.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectBatcher.cjs","names":["injectPacerOptions","Batcher","injectSelector","inject","DestroyRef"],"sources":["../../src/batcher/injectBatcher.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { Batcher } from '@tanstack/pacer/batcher'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { BatcherOptions, BatcherState } from '@tanstack/pacer/batcher'\n\nexport interface AngularBatcherOptions<\n TValue,\n TSelected = {},\n> extends BatcherOptions<TValue> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the batcher instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), cancel(), add logging, etc.\n */\n onUnmount?: (batcher: AngularBatcher<TValue, TSelected>) => void\n}\n\nexport interface AngularBatcher<TValue, TSelected = {}> extends Omit<\n Batcher<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the 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<BatcherState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages a Batcher instance.\n *\n * This is a lower-level function that provides direct access to the Batcher's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The Batcher collects items and processes them in batches based on configurable conditions:\n * - Maximum batch size\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\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 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 = injectBatcher(fn, {\n * maxSize: 5,\n * onUnmount: (b) => b.flush()\n * });\n * ```\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const batcher = injectBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 }\n * );\n *\n * // Add items\n * batcher.addItem('task1');\n *\n * // Access the selected state\n * const { items, isPending } = batcher.state();\n * ```\n */\nexport function injectBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => void,\n options: AngularBatcherOptions<TValue, TSelected> = {},\n selector: (state: BatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): AngularBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().batcher,\n ...options,\n } as AngularBatcherOptions<TValue, TSelected>\n\n const batcher = new Batcher<TValue>(fn, mergedOptions)\n const state = injectSelector(batcher.store, selector)\n\n const result = {\n ...batcher,\n state,\n } as AngularBatcher<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 }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoFA,SAAgB,cACd,IACA,UAAoD,CAAC,GACrD,kBACG,CAAC,IAC+B;CACnC,MAAM,gBAAgB;EACpB,GAAGA,yCAAmB,CAAC,CAAC;EACxB,GAAG;CACL;CAEA,MAAM,UAAU,IAAIC,gCAAgB,IAAI,aAAa;CACrD,MAAM,YAAQC,wCAAe,QAAQ,OAAO,QAAQ;CAEpD,MAAM,SAAS;EACb,GAAG;EACH;CACF;CAGA,IADmBC,sBAAOC,0BAAY,EAAE,UAAU,KAAK,CAC9C,CAAC,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,MAAM;OAE9B,QAAQ,OAAO;CAEnB,CAAC;CAED,OAAO;AACT"}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { Signal } from "@angular/core";
|
|
2
|
-
import { Store } from "@tanstack/angular-store";
|
|
3
|
-
import { Batcher, BatcherOptions, BatcherState } from "@tanstack/pacer/batcher";
|
|
4
|
-
//#region src/batcher/injectBatcher.d.ts
|
|
5
|
-
interface AngularBatcherOptions<TValue, TSelected = {}> extends BatcherOptions<TValue> {
|
|
6
|
-
/**
|
|
7
|
-
* Optional callback invoked when the component is destroyed. Receives the batcher instance.
|
|
8
|
-
* When provided, replaces the default cleanup (cancel); use it to call flush(), cancel(), add logging, etc.
|
|
9
|
-
*/
|
|
10
|
-
onUnmount?: (batcher: AngularBatcher<TValue, TSelected>) => void;
|
|
11
|
-
}
|
|
12
|
-
interface AngularBatcher<TValue, TSelected = {}> extends Omit<Batcher<TValue>, 'store'> {
|
|
13
|
-
/**
|
|
14
|
-
* Reactive state signal that will be updated when the batcher state changes
|
|
15
|
-
*
|
|
16
|
-
* Use this instead of `batcher.store.state`
|
|
17
|
-
*/
|
|
18
|
-
readonly state: Signal<Readonly<TSelected>>;
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.
|
|
21
|
-
* The state on the store object is not reactive in Angular signals.
|
|
22
|
-
*/
|
|
23
|
-
readonly store: Store<Readonly<BatcherState<TValue>>>;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* An Angular function that creates and manages a Batcher instance.
|
|
27
|
-
*
|
|
28
|
-
* This is a lower-level function that provides direct access to the Batcher's functionality.
|
|
29
|
-
* This allows you to integrate it with any state management solution you prefer.
|
|
30
|
-
*
|
|
31
|
-
* The Batcher collects items and processes them in batches based on configurable conditions:
|
|
32
|
-
* - Maximum batch size
|
|
33
|
-
* - Time-based batching (process after X milliseconds)
|
|
34
|
-
* - Custom batch processing logic via getShouldExecute
|
|
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 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 = injectBatcher(fn, {
|
|
53
|
-
* maxSize: 5,
|
|
54
|
-
* onUnmount: (b) => b.flush()
|
|
55
|
-
* });
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```ts
|
|
60
|
-
* // Default behavior - no reactive state subscriptions
|
|
61
|
-
* const batcher = injectBatcher(
|
|
62
|
-
* (items) => console.log('Processing batch:', items),
|
|
63
|
-
* { maxSize: 5, wait: 2000 }
|
|
64
|
-
* );
|
|
65
|
-
*
|
|
66
|
-
* // Add items
|
|
67
|
-
* batcher.addItem('task1');
|
|
68
|
-
*
|
|
69
|
-
* // Access the selected state
|
|
70
|
-
* const { items, isPending } = batcher.state();
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
declare function injectBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => void, options?: AngularBatcherOptions<TValue, TSelected>, selector?: (state: BatcherState<TValue>) => TSelected): AngularBatcher<TValue, TSelected>;
|
|
74
|
-
//#endregion
|
|
75
|
-
export { AngularBatcher, AngularBatcherOptions, injectBatcher };
|
|
76
|
-
//# sourceMappingURL=injectBatcher.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectBatcher.js","names":[],"sources":["../../src/batcher/injectBatcher.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { Batcher } from '@tanstack/pacer/batcher'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { BatcherOptions, BatcherState } from '@tanstack/pacer/batcher'\n\nexport interface AngularBatcherOptions<\n TValue,\n TSelected = {},\n> extends BatcherOptions<TValue> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the batcher instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), cancel(), add logging, etc.\n */\n onUnmount?: (batcher: AngularBatcher<TValue, TSelected>) => void\n}\n\nexport interface AngularBatcher<TValue, TSelected = {}> extends Omit<\n Batcher<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the 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<BatcherState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages a Batcher instance.\n *\n * This is a lower-level function that provides direct access to the Batcher's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The Batcher collects items and processes them in batches based on configurable conditions:\n * - Maximum batch size\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\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 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 = injectBatcher(fn, {\n * maxSize: 5,\n * onUnmount: (b) => b.flush()\n * });\n * ```\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const batcher = injectBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 }\n * );\n *\n * // Add items\n * batcher.addItem('task1');\n *\n * // Access the selected state\n * const { items, isPending } = batcher.state();\n * ```\n */\nexport function injectBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => void,\n options: AngularBatcherOptions<TValue, TSelected> = {},\n selector: (state: BatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): AngularBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().batcher,\n ...options,\n } as AngularBatcherOptions<TValue, TSelected>\n\n const batcher = new Batcher<TValue>(fn, mergedOptions)\n const state = injectSelector(batcher.store, selector)\n\n const result = {\n ...batcher,\n state,\n } as AngularBatcher<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 }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoFA,SAAgB,cACd,IACA,UAAoD,CAAC,GACrD,kBACG,CAAC,IAC+B;CACnC,MAAM,gBAAgB;EACpB,GAAG,mBAAmB,CAAC,CAAC;EACxB,GAAG;CACL;CAEA,MAAM,UAAU,IAAI,QAAgB,IAAI,aAAa;CACrD,MAAM,QAAQ,eAAe,QAAQ,OAAO,QAAQ;CAEpD,MAAM,SAAS;EACb,GAAG;EACH;CACF;CAGA,AADmB,OAAO,YAAY,EAAE,UAAU,KAAK,CAC9C,CAAC,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,MAAM;OAE9B,QAAQ,OAAO;CAEnB,CAAC;CAED,OAAO;AACT"}
|
package/dist/debouncer/index.cjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_injectDebouncer = require('./injectDebouncer.cjs');
|
|
3
|
-
const require_injectDebouncedCallback = require('./injectDebouncedCallback.cjs');
|
|
4
|
-
const require_injectDebouncedSignal = require('./injectDebouncedSignal.cjs');
|
|
5
|
-
const require_injectDebouncedValue = require('./injectDebouncedValue.cjs');
|
|
6
|
-
|
|
7
|
-
exports.injectDebouncedCallback = require_injectDebouncedCallback.injectDebouncedCallback;
|
|
8
|
-
exports.injectDebouncedSignal = require_injectDebouncedSignal.injectDebouncedSignal;
|
|
9
|
-
exports.injectDebouncedValue = require_injectDebouncedValue.injectDebouncedValue;
|
|
10
|
-
exports.injectDebouncer = require_injectDebouncer.injectDebouncer;
|
|
11
|
-
var _tanstack_pacer_debouncer = require("@tanstack/pacer/debouncer");
|
|
12
|
-
Object.keys(_tanstack_pacer_debouncer).forEach(function (k) {
|
|
13
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () { return _tanstack_pacer_debouncer[k]; }
|
|
16
|
-
});
|
|
17
|
-
});
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { injectDebouncedCallback } from "./injectDebouncedCallback.cjs";
|
|
2
|
-
import { AngularDebouncer, AngularDebouncerOptions, injectDebouncer } from "./injectDebouncer.cjs";
|
|
3
|
-
import { DebouncedSignal, injectDebouncedSignal } from "./injectDebouncedSignal.cjs";
|
|
4
|
-
import { injectDebouncedValue } from "./injectDebouncedValue.cjs";
|
|
5
|
-
export * from "@tanstack/pacer/debouncer";
|
|
6
|
-
export { AngularDebouncer, AngularDebouncerOptions, DebouncedSignal, injectDebouncedCallback, injectDebouncedSignal, injectDebouncedValue, injectDebouncer };
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
const require_injectDebouncer = require('./injectDebouncer.cjs');
|
|
2
|
-
|
|
3
|
-
//#region src/debouncer/injectDebouncedCallback.ts
|
|
4
|
-
/**
|
|
5
|
-
* An Angular function that creates a debounced version of a callback function.
|
|
6
|
-
* This function is essentially a wrapper around `injectDebouncer` that provides
|
|
7
|
-
* a simplified API for basic 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 `injectDebouncer`, making it ideal for basic
|
|
14
|
-
* debouncing needs. However, it does not expose the underlying Debouncer instance.
|
|
15
|
-
*
|
|
16
|
-
* For advanced usage requiring features like:
|
|
17
|
-
* - Manual cancellation
|
|
18
|
-
* - Access to execution counts
|
|
19
|
-
* - State tracking
|
|
20
|
-
*
|
|
21
|
-
* Consider using the `injectDebouncer` function instead.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* // Debounce a search handler
|
|
26
|
-
* const handleSearch = injectDebouncedCallback((query: string) => {
|
|
27
|
-
* fetchSearchResults(query);
|
|
28
|
-
* }, {
|
|
29
|
-
* wait: 500 // Wait 500ms between executions
|
|
30
|
-
* });
|
|
31
|
-
*
|
|
32
|
-
* // Use in an input
|
|
33
|
-
* <input
|
|
34
|
-
* type="search"
|
|
35
|
-
* (input)="handleSearch($event.target.value)"
|
|
36
|
-
* />
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
function injectDebouncedCallback(fn, options) {
|
|
40
|
-
const debouncer = require_injectDebouncer.injectDebouncer(fn, options);
|
|
41
|
-
return (...args) => debouncer.maybeExecute(...args);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
//#endregion
|
|
45
|
-
exports.injectDebouncedCallback = injectDebouncedCallback;
|
|
46
|
-
//# sourceMappingURL=injectDebouncedCallback.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectDebouncedCallback.cjs","names":["injectDebouncer"],"sources":["../../src/debouncer/injectDebouncedCallback.ts"],"sourcesContent":["import { injectDebouncer } from './injectDebouncer'\nimport type { DebouncerOptions } from '@tanstack/pacer/debouncer'\nimport type { AnyFunction } from '@tanstack/pacer/types'\n\n/**\n * An Angular function that creates a debounced version of a callback function.\n * This function is essentially a wrapper around `injectDebouncer` that provides\n * a simplified API for basic 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 `injectDebouncer`, making it ideal for basic\n * debouncing needs. However, it does not expose the underlying Debouncer instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - State tracking\n *\n * Consider using the `injectDebouncer` function instead.\n *\n * @example\n * ```ts\n * // Debounce a search handler\n * const handleSearch = injectDebouncedCallback((query: string) => {\n * fetchSearchResults(query);\n * }, {\n * wait: 500 // Wait 500ms between executions\n * });\n *\n * // Use in an input\n * <input\n * type=\"search\"\n * (input)=\"handleSearch($event.target.value)\"\n * />\n * ```\n */\nexport function injectDebouncedCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: DebouncerOptions<TFn>,\n): (...args: Parameters<TFn>) => void {\n const debouncer = injectDebouncer(fn, options)\n return (...args: Parameters<TFn>) => debouncer.maybeExecute(...args)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,wBACd,IACA,SACoC;CACpC,MAAM,YAAYA,wCAAgB,IAAI,OAAO;CAC7C,QAAQ,GAAG,SAA0B,UAAU,aAAa,GAAG,IAAI;AACrE"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { AnyFunction } from "@tanstack/pacer/types";
|
|
2
|
-
import { DebouncerOptions } from "@tanstack/pacer/debouncer";
|
|
3
|
-
//#region src/debouncer/injectDebouncedCallback.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* An Angular function that creates a debounced version of a callback function.
|
|
6
|
-
* This function is essentially a wrapper around `injectDebouncer` that provides
|
|
7
|
-
* a simplified API for basic 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 `injectDebouncer`, making it ideal for basic
|
|
14
|
-
* debouncing needs. However, it does not expose the underlying Debouncer instance.
|
|
15
|
-
*
|
|
16
|
-
* For advanced usage requiring features like:
|
|
17
|
-
* - Manual cancellation
|
|
18
|
-
* - Access to execution counts
|
|
19
|
-
* - State tracking
|
|
20
|
-
*
|
|
21
|
-
* Consider using the `injectDebouncer` function instead.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* // Debounce a search handler
|
|
26
|
-
* const handleSearch = injectDebouncedCallback((query: string) => {
|
|
27
|
-
* fetchSearchResults(query);
|
|
28
|
-
* }, {
|
|
29
|
-
* wait: 500 // Wait 500ms between executions
|
|
30
|
-
* });
|
|
31
|
-
*
|
|
32
|
-
* // Use in an input
|
|
33
|
-
* <input
|
|
34
|
-
* type="search"
|
|
35
|
-
* (input)="handleSearch($event.target.value)"
|
|
36
|
-
* />
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
declare function injectDebouncedCallback<TFn extends AnyFunction>(fn: TFn, options: DebouncerOptions<TFn>): (...args: Parameters<TFn>) => void;
|
|
40
|
-
//#endregion
|
|
41
|
-
export { injectDebouncedCallback };
|
|
42
|
-
//# sourceMappingURL=injectDebouncedCallback.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectDebouncedCallback.js","names":[],"sources":["../../src/debouncer/injectDebouncedCallback.ts"],"sourcesContent":["import { injectDebouncer } from './injectDebouncer'\nimport type { DebouncerOptions } from '@tanstack/pacer/debouncer'\nimport type { AnyFunction } from '@tanstack/pacer/types'\n\n/**\n * An Angular function that creates a debounced version of a callback function.\n * This function is essentially a wrapper around `injectDebouncer` that provides\n * a simplified API for basic 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 `injectDebouncer`, making it ideal for basic\n * debouncing needs. However, it does not expose the underlying Debouncer instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - State tracking\n *\n * Consider using the `injectDebouncer` function instead.\n *\n * @example\n * ```ts\n * // Debounce a search handler\n * const handleSearch = injectDebouncedCallback((query: string) => {\n * fetchSearchResults(query);\n * }, {\n * wait: 500 // Wait 500ms between executions\n * });\n *\n * // Use in an input\n * <input\n * type=\"search\"\n * (input)=\"handleSearch($event.target.value)\"\n * />\n * ```\n */\nexport function injectDebouncedCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: DebouncerOptions<TFn>,\n): (...args: Parameters<TFn>) => void {\n const debouncer = injectDebouncer(fn, options)\n return (...args: Parameters<TFn>) => debouncer.maybeExecute(...args)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,wBACd,IACA,SACoC;CACpC,MAAM,YAAY,gBAAgB,IAAI,OAAO;CAC7C,QAAQ,GAAG,SAA0B,UAAU,aAAa,GAAG,IAAI;AACrE"}
|