@tanstack/angular-pacer 0.20.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 +165 -0
- package/dist/async-batcher/index.cjs +13 -0
- package/dist/async-batcher/index.d.cts +4 -0
- package/dist/async-batcher/index.d.ts +4 -0
- package/dist/async-batcher/index.js +6 -0
- package/dist/async-batcher/injectAsyncBatchedCallback.cjs +49 -0
- package/dist/async-batcher/injectAsyncBatchedCallback.cjs.map +1 -0
- package/dist/async-batcher/injectAsyncBatchedCallback.d.cts +45 -0
- package/dist/async-batcher/injectAsyncBatchedCallback.d.ts +45 -0
- package/dist/async-batcher/injectAsyncBatchedCallback.js +49 -0
- package/dist/async-batcher/injectAsyncBatchedCallback.js.map +1 -0
- package/dist/async-batcher/injectAsyncBatcher.cjs +61 -0
- package/dist/async-batcher/injectAsyncBatcher.cjs.map +1 -0
- package/dist/async-batcher/injectAsyncBatcher.d.cts +63 -0
- package/dist/async-batcher/injectAsyncBatcher.d.ts +63 -0
- package/dist/async-batcher/injectAsyncBatcher.js +61 -0
- package/dist/async-batcher/injectAsyncBatcher.js.map +1 -0
- package/dist/async-debouncer/index.cjs +13 -0
- package/dist/async-debouncer/index.d.cts +4 -0
- package/dist/async-debouncer/index.d.ts +4 -0
- package/dist/async-debouncer/index.js +6 -0
- package/dist/async-debouncer/injectAsyncDebouncedCallback.cjs +49 -0
- package/dist/async-debouncer/injectAsyncDebouncedCallback.cjs.map +1 -0
- package/dist/async-debouncer/injectAsyncDebouncedCallback.d.cts +43 -0
- package/dist/async-debouncer/injectAsyncDebouncedCallback.d.ts +43 -0
- package/dist/async-debouncer/injectAsyncDebouncedCallback.js +49 -0
- package/dist/async-debouncer/injectAsyncDebouncedCallback.js.map +1 -0
- package/dist/async-debouncer/injectAsyncDebouncer.cjs +83 -0
- package/dist/async-debouncer/injectAsyncDebouncer.cjs.map +1 -0
- package/dist/async-debouncer/injectAsyncDebouncer.d.cts +86 -0
- package/dist/async-debouncer/injectAsyncDebouncer.d.ts +86 -0
- package/dist/async-debouncer/injectAsyncDebouncer.js +83 -0
- package/dist/async-debouncer/injectAsyncDebouncer.js.map +1 -0
- package/dist/async-queuer/index.cjs +13 -0
- package/dist/async-queuer/index.d.cts +4 -0
- package/dist/async-queuer/index.d.ts +4 -0
- package/dist/async-queuer/index.js +6 -0
- package/dist/async-queuer/injectAsyncQueuedSignal.cjs +53 -0
- package/dist/async-queuer/injectAsyncQueuedSignal.cjs.map +1 -0
- package/dist/async-queuer/injectAsyncQueuedSignal.d.cts +55 -0
- package/dist/async-queuer/injectAsyncQueuedSignal.d.ts +55 -0
- package/dist/async-queuer/injectAsyncQueuedSignal.js +53 -0
- package/dist/async-queuer/injectAsyncQueuedSignal.js.map +1 -0
- package/dist/async-queuer/injectAsyncQueuer.cjs +61 -0
- package/dist/async-queuer/injectAsyncQueuer.cjs.map +1 -0
- package/dist/async-queuer/injectAsyncQueuer.d.cts +63 -0
- package/dist/async-queuer/injectAsyncQueuer.d.ts +63 -0
- package/dist/async-queuer/injectAsyncQueuer.js +61 -0
- package/dist/async-queuer/injectAsyncQueuer.js.map +1 -0
- package/dist/async-rate-limiter/index.cjs +13 -0
- package/dist/async-rate-limiter/index.d.cts +4 -0
- package/dist/async-rate-limiter/index.d.ts +4 -0
- package/dist/async-rate-limiter/index.js +6 -0
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.cjs +52 -0
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.cjs.map +1 -0
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.d.cts +46 -0
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.d.ts +46 -0
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.js +52 -0
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.js.map +1 -0
- package/dist/async-rate-limiter/injectAsyncRateLimiter.cjs +57 -0
- package/dist/async-rate-limiter/injectAsyncRateLimiter.cjs.map +1 -0
- package/dist/async-rate-limiter/injectAsyncRateLimiter.d.cts +60 -0
- package/dist/async-rate-limiter/injectAsyncRateLimiter.d.ts +60 -0
- package/dist/async-rate-limiter/injectAsyncRateLimiter.js +57 -0
- package/dist/async-rate-limiter/injectAsyncRateLimiter.js.map +1 -0
- package/dist/async-retryer/index.cjs +9 -0
- package/dist/async-retryer/index.d.cts +1 -0
- package/dist/async-retryer/index.d.ts +1 -0
- package/dist/async-retryer/index.js +3 -0
- package/dist/async-throttler/index.cjs +13 -0
- package/dist/async-throttler/index.d.cts +4 -0
- package/dist/async-throttler/index.d.ts +4 -0
- package/dist/async-throttler/index.js +6 -0
- package/dist/async-throttler/injectAsyncThrottledCallback.cjs +50 -0
- package/dist/async-throttler/injectAsyncThrottledCallback.cjs.map +1 -0
- package/dist/async-throttler/injectAsyncThrottledCallback.d.cts +44 -0
- package/dist/async-throttler/injectAsyncThrottledCallback.d.ts +44 -0
- package/dist/async-throttler/injectAsyncThrottledCallback.js +50 -0
- package/dist/async-throttler/injectAsyncThrottledCallback.js.map +1 -0
- package/dist/async-throttler/injectAsyncThrottler.cjs +62 -0
- package/dist/async-throttler/injectAsyncThrottler.cjs.map +1 -0
- package/dist/async-throttler/injectAsyncThrottler.d.cts +65 -0
- package/dist/async-throttler/injectAsyncThrottler.d.ts +65 -0
- package/dist/async-throttler/injectAsyncThrottler.js +62 -0
- package/dist/async-throttler/injectAsyncThrottler.js.map +1 -0
- package/dist/batcher/index.cjs +13 -0
- package/dist/batcher/index.d.cts +4 -0
- package/dist/batcher/index.d.ts +4 -0
- package/dist/batcher/index.js +6 -0
- package/dist/batcher/injectBatchedCallback.cjs +47 -0
- package/dist/batcher/injectBatchedCallback.cjs.map +1 -0
- package/dist/batcher/injectBatchedCallback.d.cts +43 -0
- package/dist/batcher/injectBatchedCallback.d.ts +43 -0
- package/dist/batcher/injectBatchedCallback.js +47 -0
- package/dist/batcher/injectBatchedCallback.js.map +1 -0
- package/dist/batcher/injectBatcher.cjs +56 -0
- package/dist/batcher/injectBatcher.cjs.map +1 -0
- package/dist/batcher/injectBatcher.d.cts +58 -0
- package/dist/batcher/injectBatcher.d.ts +58 -0
- package/dist/batcher/injectBatcher.js +56 -0
- package/dist/batcher/injectBatcher.js.map +1 -0
- package/dist/debouncer/index.cjs +17 -0
- package/dist/debouncer/index.d.cts +6 -0
- package/dist/debouncer/index.d.ts +6 -0
- package/dist/debouncer/index.js +8 -0
- package/dist/debouncer/injectDebouncedCallback.cjs +46 -0
- package/dist/debouncer/injectDebouncedCallback.cjs.map +1 -0
- package/dist/debouncer/injectDebouncedCallback.d.cts +43 -0
- package/dist/debouncer/injectDebouncedCallback.d.ts +43 -0
- package/dist/debouncer/injectDebouncedCallback.js +46 -0
- package/dist/debouncer/injectDebouncedCallback.js.map +1 -0
- package/dist/debouncer/injectDebouncedSignal.cjs +68 -0
- package/dist/debouncer/injectDebouncedSignal.cjs.map +1 -0
- package/dist/debouncer/injectDebouncedSignal.d.cts +65 -0
- package/dist/debouncer/injectDebouncedSignal.d.ts +65 -0
- package/dist/debouncer/injectDebouncedSignal.js +68 -0
- package/dist/debouncer/injectDebouncedSignal.js.map +1 -0
- package/dist/debouncer/injectDebouncedValue.cjs +17 -0
- package/dist/debouncer/injectDebouncedValue.cjs.map +1 -0
- package/dist/debouncer/injectDebouncedValue.d.cts +76 -0
- package/dist/debouncer/injectDebouncedValue.d.ts +76 -0
- package/dist/debouncer/injectDebouncedValue.js +17 -0
- package/dist/debouncer/injectDebouncedValue.js.map +1 -0
- package/dist/debouncer/injectDebouncer.cjs +76 -0
- package/dist/debouncer/injectDebouncer.cjs.map +1 -0
- package/dist/debouncer/injectDebouncer.d.cts +79 -0
- package/dist/debouncer/injectDebouncer.d.ts +79 -0
- package/dist/debouncer/injectDebouncer.js +76 -0
- package/dist/debouncer/injectDebouncer.js.map +1 -0
- package/dist/index.cjs +65 -0
- package/dist/index.d.cts +30 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +32 -0
- package/dist/provider/index.cjs +7 -0
- package/dist/provider/index.d.cts +3 -0
- package/dist/provider/index.d.ts +3 -0
- package/dist/provider/index.js +4 -0
- package/dist/provider/pacer-context.cjs +20 -0
- package/dist/provider/pacer-context.cjs.map +1 -0
- package/dist/provider/pacer-context.d.cts +21 -0
- package/dist/provider/pacer-context.d.ts +21 -0
- package/dist/provider/pacer-context.js +19 -0
- package/dist/provider/pacer-context.js.map +1 -0
- package/dist/provider/pacer-provider.cjs +41 -0
- package/dist/provider/pacer-provider.cjs.map +1 -0
- package/dist/provider/pacer-provider.d.cts +36 -0
- package/dist/provider/pacer-provider.d.ts +36 -0
- package/dist/provider/pacer-provider.js +41 -0
- package/dist/provider/pacer-provider.js.map +1 -0
- package/dist/queuer/index.cjs +15 -0
- package/dist/queuer/index.d.cts +5 -0
- package/dist/queuer/index.d.ts +5 -0
- package/dist/queuer/index.js +7 -0
- package/dist/queuer/injectQueuedSignal.cjs +47 -0
- package/dist/queuer/injectQueuedSignal.cjs.map +1 -0
- package/dist/queuer/injectQueuedSignal.d.cts +49 -0
- package/dist/queuer/injectQueuedSignal.d.ts +49 -0
- package/dist/queuer/injectQueuedSignal.js +47 -0
- package/dist/queuer/injectQueuedSignal.js.map +1 -0
- package/dist/queuer/injectQueuedValue.cjs +23 -0
- package/dist/queuer/injectQueuedValue.cjs.map +1 -0
- package/dist/queuer/injectQueuedValue.d.cts +34 -0
- package/dist/queuer/injectQueuedValue.d.ts +34 -0
- package/dist/queuer/injectQueuedValue.js +23 -0
- package/dist/queuer/injectQueuedValue.js.map +1 -0
- package/dist/queuer/injectQueuer.cjs +61 -0
- package/dist/queuer/injectQueuer.cjs.map +1 -0
- package/dist/queuer/injectQueuer.d.cts +63 -0
- package/dist/queuer/injectQueuer.d.ts +63 -0
- package/dist/queuer/injectQueuer.js +61 -0
- package/dist/queuer/injectQueuer.js.map +1 -0
- package/dist/rate-limiter/index.cjs +17 -0
- package/dist/rate-limiter/index.d.cts +6 -0
- package/dist/rate-limiter/index.d.ts +6 -0
- package/dist/rate-limiter/index.js +8 -0
- package/dist/rate-limiter/injectRateLimitedCallback.cjs +45 -0
- package/dist/rate-limiter/injectRateLimitedCallback.cjs.map +1 -0
- package/dist/rate-limiter/injectRateLimitedCallback.d.cts +42 -0
- package/dist/rate-limiter/injectRateLimitedCallback.d.ts +42 -0
- package/dist/rate-limiter/injectRateLimitedCallback.js +45 -0
- package/dist/rate-limiter/injectRateLimitedCallback.js.map +1 -0
- package/dist/rate-limiter/injectRateLimitedSignal.cjs +62 -0
- package/dist/rate-limiter/injectRateLimitedSignal.cjs.map +1 -0
- package/dist/rate-limiter/injectRateLimitedSignal.d.cts +59 -0
- package/dist/rate-limiter/injectRateLimitedSignal.d.ts +59 -0
- package/dist/rate-limiter/injectRateLimitedSignal.js +62 -0
- package/dist/rate-limiter/injectRateLimitedSignal.js.map +1 -0
- package/dist/rate-limiter/injectRateLimitedValue.cjs +17 -0
- package/dist/rate-limiter/injectRateLimitedValue.cjs.map +1 -0
- package/dist/rate-limiter/injectRateLimitedValue.d.cts +49 -0
- package/dist/rate-limiter/injectRateLimitedValue.d.ts +49 -0
- package/dist/rate-limiter/injectRateLimitedValue.js +17 -0
- package/dist/rate-limiter/injectRateLimitedValue.js.map +1 -0
- package/dist/rate-limiter/injectRateLimiter.cjs +90 -0
- package/dist/rate-limiter/injectRateLimiter.cjs.map +1 -0
- package/dist/rate-limiter/injectRateLimiter.d.cts +93 -0
- package/dist/rate-limiter/injectRateLimiter.d.ts +93 -0
- package/dist/rate-limiter/injectRateLimiter.js +90 -0
- package/dist/rate-limiter/injectRateLimiter.js.map +1 -0
- package/dist/throttler/index.cjs +17 -0
- package/dist/throttler/index.d.cts +6 -0
- package/dist/throttler/index.d.ts +6 -0
- package/dist/throttler/index.js +8 -0
- package/dist/throttler/injectThrottledCallback.cjs +45 -0
- package/dist/throttler/injectThrottledCallback.cjs.map +1 -0
- package/dist/throttler/injectThrottledCallback.d.cts +42 -0
- package/dist/throttler/injectThrottledCallback.d.ts +42 -0
- package/dist/throttler/injectThrottledCallback.js +45 -0
- package/dist/throttler/injectThrottledCallback.js.map +1 -0
- package/dist/throttler/injectThrottledSignal.cjs +69 -0
- package/dist/throttler/injectThrottledSignal.cjs.map +1 -0
- package/dist/throttler/injectThrottledSignal.d.cts +66 -0
- package/dist/throttler/injectThrottledSignal.d.ts +66 -0
- package/dist/throttler/injectThrottledSignal.js +69 -0
- package/dist/throttler/injectThrottledSignal.js.map +1 -0
- package/dist/throttler/injectThrottledValue.cjs +17 -0
- package/dist/throttler/injectThrottledValue.cjs.map +1 -0
- package/dist/throttler/injectThrottledValue.d.cts +74 -0
- package/dist/throttler/injectThrottledValue.d.ts +74 -0
- package/dist/throttler/injectThrottledValue.js +17 -0
- package/dist/throttler/injectThrottledValue.js.map +1 -0
- package/dist/throttler/injectThrottler.cjs +76 -0
- package/dist/throttler/injectThrottler.cjs.map +1 -0
- package/dist/throttler/injectThrottler.d.cts +79 -0
- package/dist/throttler/injectThrottler.d.ts +79 -0
- package/dist/throttler/injectThrottler.js +76 -0
- package/dist/throttler/injectThrottler.js.map +1 -0
- package/dist/types/index.cjs +9 -0
- package/dist/types/index.d.cts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +3 -0
- package/dist/utils/index.cjs +9 -0
- package/dist/utils/index.d.cts +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +3 -0
- package/package.json +121 -0
- package/src/async-batcher/index.ts +4 -0
- package/src/async-batcher/injectAsyncBatchedCallback.ts +48 -0
- package/src/async-batcher/injectAsyncBatcher.ts +87 -0
- package/src/async-debouncer/index.ts +4 -0
- package/src/async-debouncer/injectAsyncDebouncedCallback.ts +50 -0
- package/src/async-debouncer/injectAsyncDebouncer.ts +113 -0
- package/src/async-queuer/index.ts +4 -0
- package/src/async-queuer/injectAsyncQueuedSignal.ts +82 -0
- package/src/async-queuer/injectAsyncQueuer.ts +87 -0
- package/src/async-rate-limiter/index.ts +4 -0
- package/src/async-rate-limiter/injectAsyncRateLimitedCallback.ts +52 -0
- package/src/async-rate-limiter/injectAsyncRateLimiter.ts +87 -0
- package/src/async-retryer/index.ts +1 -0
- package/src/async-throttler/index.ts +4 -0
- package/src/async-throttler/injectAsyncThrottledCallback.ts +50 -0
- package/src/async-throttler/injectAsyncThrottler.ts +92 -0
- package/src/batcher/index.ts +4 -0
- package/src/batcher/injectBatchedCallback.ts +46 -0
- package/src/batcher/injectBatcher.ts +79 -0
- package/src/debouncer/index.ts +6 -0
- package/src/debouncer/injectDebouncedCallback.ts +46 -0
- package/src/debouncer/injectDebouncedSignal.ts +101 -0
- package/src/debouncer/injectDebouncedValue.ts +126 -0
- package/src/debouncer/injectDebouncer.ts +102 -0
- package/src/index.ts +40 -0
- package/src/provider/index.ts +2 -0
- package/src/provider/pacer-context.ts +46 -0
- package/src/provider/pacer-provider.ts +38 -0
- package/src/queuer/index.ts +5 -0
- package/src/queuer/injectQueuedSignal.ts +70 -0
- package/src/queuer/injectQueuedValue.ts +101 -0
- package/src/queuer/injectQueuer.ts +83 -0
- package/src/rate-limiter/index.ts +6 -0
- package/src/rate-limiter/injectRateLimitedCallback.ts +45 -0
- package/src/rate-limiter/injectRateLimitedSignal.ts +95 -0
- package/src/rate-limiter/injectRateLimitedValue.ts +99 -0
- package/src/rate-limiter/injectRateLimiter.ts +116 -0
- package/src/throttler/index.ts +6 -0
- package/src/throttler/injectThrottledCallback.ts +45 -0
- package/src/throttler/injectThrottledSignal.ts +102 -0
- package/src/throttler/injectThrottledValue.ts +124 -0
- package/src/throttler/injectThrottler.ts +102 -0
- package/src/types/index.ts +1 -0
- package/src/utils/index.ts +1 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { AngularDebouncer } from "./injectDebouncer.js";
|
|
2
|
+
import { DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
|
|
3
|
+
|
|
4
|
+
//#region src/debouncer/injectDebouncedSignal.d.ts
|
|
5
|
+
type Setter<T> = (value: T | ((prev: T) => T)) => void;
|
|
6
|
+
type DebouncedSignal<TValue, TSelected = {}> = ((...args: []) => TValue) & {
|
|
7
|
+
/**
|
|
8
|
+
* Set or update the debounced value. This calls `debouncer.maybeExecute(...)`.
|
|
9
|
+
*/
|
|
10
|
+
readonly set: Setter<TValue>;
|
|
11
|
+
/**
|
|
12
|
+
* The debouncer instance with additional control methods and state signals.
|
|
13
|
+
*/
|
|
14
|
+
readonly debouncer: AngularDebouncer<Setter<TValue>, TSelected>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* An Angular function that creates a debounced state signal, combining Angular's signal with debouncing functionality.
|
|
18
|
+
* This function provides both the current debounced value and methods to update it.
|
|
19
|
+
*
|
|
20
|
+
* The state value is only updated after the specified wait time has elapsed since the last update attempt.
|
|
21
|
+
* If another update is attempted before the wait time expires, the timer resets and starts waiting again.
|
|
22
|
+
* This is useful for handling frequent state updates that should be throttled, like search input values
|
|
23
|
+
* or window resize dimensions.
|
|
24
|
+
*
|
|
25
|
+
* The function returns a callable object:
|
|
26
|
+
* - `debounced()`: Get the current debounced value
|
|
27
|
+
* - `debounced.set(...)`: Set or update the debounced value (debounced via maybeExecute)
|
|
28
|
+
* - `debounced.debouncer`: The debouncer instance with additional control methods and state signals
|
|
29
|
+
*
|
|
30
|
+
* ## State Management and Selector
|
|
31
|
+
*
|
|
32
|
+
* The function uses TanStack Store for reactive state management via the underlying debouncer instance.
|
|
33
|
+
* The `selector` parameter allows you to specify which debouncer state changes will trigger signal updates,
|
|
34
|
+
* optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
|
|
35
|
+
*
|
|
36
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
37
|
+
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
38
|
+
* full control over when your component tracks state changes. Only when you provide a selector will
|
|
39
|
+
* the reactive system track the selected state values.
|
|
40
|
+
*
|
|
41
|
+
* Available debouncer state properties:
|
|
42
|
+
* - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
|
|
43
|
+
* - `executionCount`: Number of function executions that have been completed
|
|
44
|
+
* - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
|
|
45
|
+
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
46
|
+
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* const debouncedQuery = injectDebouncedSignal('', { wait: 500 })
|
|
51
|
+
*
|
|
52
|
+
* // Get value
|
|
53
|
+
* console.log(debouncedQuery())
|
|
54
|
+
*
|
|
55
|
+
* // Set/update value (debounced)
|
|
56
|
+
* debouncedQuery.set('hello')
|
|
57
|
+
*
|
|
58
|
+
* // Access debouncer
|
|
59
|
+
* console.log(debouncedQuery.debouncer.state().isPending)
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
declare function injectDebouncedSignal<TValue, TSelected = {}>(value: TValue, initialOptions: DebouncerOptions<Setter<TValue>>, selector?: (state: DebouncerState<Setter<TValue>>) => TSelected): DebouncedSignal<TValue, TSelected>;
|
|
63
|
+
//#endregion
|
|
64
|
+
export { DebouncedSignal, injectDebouncedSignal };
|
|
65
|
+
//# sourceMappingURL=injectDebouncedSignal.d.ts.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { injectDebouncer } from "./injectDebouncer.js";
|
|
2
|
+
import { signal } from "@angular/core";
|
|
3
|
+
|
|
4
|
+
//#region src/debouncer/injectDebouncedSignal.ts
|
|
5
|
+
/**
|
|
6
|
+
* An Angular function that creates a debounced state signal, combining Angular's signal with debouncing functionality.
|
|
7
|
+
* This function provides both the current debounced value and methods to update it.
|
|
8
|
+
*
|
|
9
|
+
* The state value is only updated after the specified wait time has elapsed since the last update attempt.
|
|
10
|
+
* If another update is attempted before the wait time expires, the timer resets and starts waiting again.
|
|
11
|
+
* This is useful for handling frequent state updates that should be throttled, like search input values
|
|
12
|
+
* or window resize dimensions.
|
|
13
|
+
*
|
|
14
|
+
* The function returns a callable object:
|
|
15
|
+
* - `debounced()`: Get the current debounced value
|
|
16
|
+
* - `debounced.set(...)`: Set or update the debounced value (debounced via maybeExecute)
|
|
17
|
+
* - `debounced.debouncer`: The debouncer instance with additional control methods and state signals
|
|
18
|
+
*
|
|
19
|
+
* ## State Management and Selector
|
|
20
|
+
*
|
|
21
|
+
* The function uses TanStack Store for reactive state management via the underlying debouncer instance.
|
|
22
|
+
* The `selector` parameter allows you to specify which debouncer state changes will trigger signal updates,
|
|
23
|
+
* optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
|
|
24
|
+
*
|
|
25
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
26
|
+
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
27
|
+
* full control over when your component tracks state changes. Only when you provide a selector will
|
|
28
|
+
* the reactive system track the selected state values.
|
|
29
|
+
*
|
|
30
|
+
* Available debouncer state properties:
|
|
31
|
+
* - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
|
|
32
|
+
* - `executionCount`: Number of function executions that have been completed
|
|
33
|
+
* - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
|
|
34
|
+
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
35
|
+
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const debouncedQuery = injectDebouncedSignal('', { wait: 500 })
|
|
40
|
+
*
|
|
41
|
+
* // Get value
|
|
42
|
+
* console.log(debouncedQuery())
|
|
43
|
+
*
|
|
44
|
+
* // Set/update value (debounced)
|
|
45
|
+
* debouncedQuery.set('hello')
|
|
46
|
+
*
|
|
47
|
+
* // Access debouncer
|
|
48
|
+
* console.log(debouncedQuery.debouncer.state().isPending)
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
function injectDebouncedSignal(value, initialOptions, selector) {
|
|
52
|
+
const debouncedValue = signal(value);
|
|
53
|
+
const debouncer = injectDebouncer((newValue) => {
|
|
54
|
+
if (typeof newValue === "function") debouncedValue.update(newValue);
|
|
55
|
+
else debouncedValue.set(newValue);
|
|
56
|
+
}, initialOptions, selector);
|
|
57
|
+
const set = (newValue) => {
|
|
58
|
+
debouncer.maybeExecute(newValue);
|
|
59
|
+
};
|
|
60
|
+
return Object.assign(() => debouncedValue(), {
|
|
61
|
+
set,
|
|
62
|
+
debouncer
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
export { injectDebouncedSignal };
|
|
68
|
+
//# sourceMappingURL=injectDebouncedSignal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectDebouncedSignal.js","names":[],"sources":["../../src/debouncer/injectDebouncedSignal.ts"],"sourcesContent":["import { signal } from '@angular/core'\nimport { injectDebouncer } from './injectDebouncer'\nimport type { AngularDebouncer } from './injectDebouncer'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\nexport type DebouncedSignal<TValue, TSelected = {}> = ((\n ...args: []\n) => TValue) & {\n /**\n * Set or update the debounced value. This calls `debouncer.maybeExecute(...)`.\n */\n readonly set: Setter<TValue>\n /**\n * The debouncer instance with additional control methods and state signals.\n */\n readonly debouncer: AngularDebouncer<Setter<TValue>, TSelected>\n}\n\n/**\n * An Angular function that creates a debounced state signal, combining Angular's signal with debouncing functionality.\n * This function provides both the current debounced value and methods to update it.\n *\n * The state value is only updated after the specified wait time has elapsed since the last update attempt.\n * If another update is attempted before the wait time expires, the timer resets and starts waiting again.\n * This is useful for handling frequent state updates that should be throttled, like search input values\n * or window resize dimensions.\n *\n * The function returns a callable object:\n * - `debounced()`: Get the current debounced value\n * - `debounced.set(...)`: Set or update the debounced value (debounced via maybeExecute)\n * - `debounced.debouncer`: The debouncer instance with additional control methods and state signals\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary subscriptions 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. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * const debouncedQuery = injectDebouncedSignal('', { wait: 500 })\n *\n * // Get value\n * console.log(debouncedQuery())\n *\n * // Set/update value (debounced)\n * debouncedQuery.set('hello')\n *\n * // Access debouncer\n * console.log(debouncedQuery.debouncer.state().isPending)\n * ```\n */\nexport function injectDebouncedSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: DebouncerOptions<Setter<TValue>>,\n selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): DebouncedSignal<TValue, TSelected> {\n const debouncedValue = signal<TValue>(value)\n\n const debouncer = injectDebouncer(\n (newValue: TValue | ((prev: TValue) => TValue)) => {\n if (typeof newValue === 'function') {\n debouncedValue.update(newValue as (prev: TValue) => TValue)\n } else {\n debouncedValue.set(newValue)\n }\n },\n initialOptions,\n selector,\n )\n\n const set: Setter<TValue> = (\n newValue: TValue | ((prev: TValue) => TValue),\n ) => {\n debouncer.maybeExecute(newValue)\n }\n\n const debounced = Object.assign(() => debouncedValue(), {\n set,\n debouncer,\n }) as DebouncedSignal<TValue, TSelected>\n\n return debounced\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqEA,SAAgB,sBACd,OACA,gBACA,UACoC;CACpC,MAAM,iBAAiB,OAAe,MAAM;CAE5C,MAAM,YAAY,iBACf,aAAkD;AACjD,MAAI,OAAO,aAAa,WACtB,gBAAe,OAAO,SAAqC;MAE3D,gBAAe,IAAI,SAAS;IAGhC,gBACA,SACD;CAED,MAAM,OACJ,aACG;AACH,YAAU,aAAa,SAAS;;AAQlC,QALkB,OAAO,aAAa,gBAAgB,EAAE;EACtD;EACA;EACD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const require_injectDebouncedSignal = require('./injectDebouncedSignal.cjs');
|
|
2
|
+
let _angular_core = require("@angular/core");
|
|
3
|
+
|
|
4
|
+
//#region src/debouncer/injectDebouncedValue.ts
|
|
5
|
+
function injectDebouncedValue(value, initialValueOrOptions, initialOptionsOrSelector, maybeSelector) {
|
|
6
|
+
const hasInitialValue = initialOptionsOrSelector !== void 0 && !(typeof initialOptionsOrSelector === "function") || maybeSelector !== void 0;
|
|
7
|
+
const debounced = require_injectDebouncedSignal.injectDebouncedSignal(hasInitialValue ? initialValueOrOptions : void 0, hasInitialValue ? initialOptionsOrSelector : initialValueOrOptions, hasInitialValue ? maybeSelector : initialOptionsOrSelector);
|
|
8
|
+
(0, _angular_core.effect)(() => {
|
|
9
|
+
const latest = value();
|
|
10
|
+
debounced.set(latest);
|
|
11
|
+
});
|
|
12
|
+
return debounced;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.injectDebouncedValue = injectDebouncedValue;
|
|
17
|
+
//# sourceMappingURL=injectDebouncedValue.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectDebouncedValue.cjs","names":["injectDebouncedSignal"],"sources":["../../src/debouncer/injectDebouncedValue.ts"],"sourcesContent":["import { effect } from '@angular/core'\nimport { injectDebouncedSignal } from './injectDebouncedSignal'\nimport type { DebouncedSignal } from './injectDebouncedSignal'\nimport type { Signal } from '@angular/core'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\n/**\n * An Angular function that creates a debounced value that updates only after a specified delay.\n * Unlike injectDebouncedSignal, this function automatically tracks changes to the input signal\n * and updates the debounced value accordingly.\n *\n * The debounced value will only update after the specified wait time has elapsed since\n * the last change to the input value. If the input value changes again before the wait\n * time expires, the timer resets and starts waiting again.\n *\n * This is useful for deriving debounced values from signals that change frequently,\n * like search queries or form inputs, where you want to limit how often downstream effects\n * or calculations occur.\n *\n * The function returns a tuple containing:\n * - A Signal that provides the current debounced value\n * - The debouncer instance with control methods\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary subscriptions 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. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const searchQuery = signal('')\n * const debounced = injectDebouncedValue(searchQuery, {\n * wait: 500, // Wait 500ms after last change\n * })\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const debouncedWithPending = injectDebouncedValue(\n * searchQuery,\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending }),\n * )\n *\n * // Debounced value will update 500ms after searchQuery stops changing\n * effect(() => {\n * fetchSearchResults(debounced())\n * })\n *\n * // Access selected debouncer state via signals (only if you provided a selector)\n * effect(() => {\n * console.log('Is pending:', debouncedWithPending.state().isPending)\n * })\n *\n * // Control the debouncer\n * debounced.cancel() // Cancel any pending updates\n * ```\n */\nexport function injectDebouncedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialOptions: DebouncerOptions<Setter<TValue>>,\n selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): DebouncedSignal<TValue, TSelected>\nexport function injectDebouncedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValue: TValue,\n initialOptions: DebouncerOptions<Setter<TValue>>,\n selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): DebouncedSignal<TValue, TSelected>\nexport function injectDebouncedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValueOrOptions: TValue | DebouncerOptions<Setter<TValue>>,\n initialOptionsOrSelector?:\n | DebouncerOptions<Setter<TValue>>\n | ((state: DebouncerState<Setter<TValue>>) => TSelected),\n maybeSelector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): DebouncedSignal<TValue, TSelected> {\n const hasSelector = typeof initialOptionsOrSelector === 'function'\n\n const hasInitialValue =\n (initialOptionsOrSelector !== undefined && !hasSelector) ||\n maybeSelector !== undefined\n\n const initialValue = hasInitialValue\n ? (initialValueOrOptions as TValue)\n : (undefined as unknown as TValue)\n const initialOptions = hasInitialValue\n ? (initialOptionsOrSelector as DebouncerOptions<Setter<TValue>>)\n : (initialValueOrOptions as DebouncerOptions<Setter<TValue>>)\n const selector = hasInitialValue\n ? maybeSelector\n : (initialOptionsOrSelector as\n | ((state: DebouncerState<Setter<TValue>>) => TSelected)\n | undefined)\n\n const debounced = injectDebouncedSignal(\n initialValue,\n initialOptions,\n selector,\n )\n\n effect(() => {\n const latest = value()\n debounced.set(latest)\n })\n\n return debounced\n}\n"],"mappings":";;;;AAuFA,SAAgB,qBACd,OACA,uBACA,0BAGA,eACoC;CAGpC,MAAM,kBACH,6BAA6B,UAAa,EAHzB,OAAO,6BAA6B,eAItD,kBAAkB;CAcpB,MAAM,YAAYA,oDAZG,kBAChB,wBACA,QACkB,kBAClB,2BACA,uBACY,kBACb,gBACC,yBAQJ;AAED,iCAAa;EACX,MAAM,SAAS,OAAO;AACtB,YAAU,IAAI,OAAO;GACrB;AAEF,QAAO"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { DebouncedSignal } from "./injectDebouncedSignal.cjs";
|
|
2
|
+
import { Signal } from "@angular/core";
|
|
3
|
+
import { DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
|
|
4
|
+
|
|
5
|
+
//#region src/debouncer/injectDebouncedValue.d.ts
|
|
6
|
+
type Setter<T> = (value: T | ((prev: T) => T)) => void;
|
|
7
|
+
/**
|
|
8
|
+
* An Angular function that creates a debounced value that updates only after a specified delay.
|
|
9
|
+
* Unlike injectDebouncedSignal, this function automatically tracks changes to the input signal
|
|
10
|
+
* and updates the debounced value accordingly.
|
|
11
|
+
*
|
|
12
|
+
* The debounced value will only update after the specified wait time has elapsed since
|
|
13
|
+
* the last change to the input value. If the input value changes again before the wait
|
|
14
|
+
* time expires, the timer resets and starts waiting again.
|
|
15
|
+
*
|
|
16
|
+
* This is useful for deriving debounced values from signals that change frequently,
|
|
17
|
+
* like search queries or form inputs, where you want to limit how often downstream effects
|
|
18
|
+
* or calculations occur.
|
|
19
|
+
*
|
|
20
|
+
* The function returns a tuple containing:
|
|
21
|
+
* - A Signal that provides the current debounced value
|
|
22
|
+
* - The debouncer instance with control methods
|
|
23
|
+
*
|
|
24
|
+
* ## State Management and Selector
|
|
25
|
+
*
|
|
26
|
+
* The function uses TanStack Store for reactive state management via the underlying debouncer instance.
|
|
27
|
+
* The `selector` parameter allows you to specify which debouncer state changes will trigger signal updates,
|
|
28
|
+
* optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
|
|
29
|
+
*
|
|
30
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
31
|
+
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
32
|
+
* full control over when your component tracks state changes. Only when you provide a selector will
|
|
33
|
+
* the reactive system track the selected state values.
|
|
34
|
+
*
|
|
35
|
+
* Available debouncer state properties:
|
|
36
|
+
* - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
|
|
37
|
+
* - `executionCount`: Number of function executions that have been completed
|
|
38
|
+
* - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
|
|
39
|
+
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
40
|
+
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
41
|
+
*
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* // Default behavior - no reactive state subscriptions
|
|
46
|
+
* const searchQuery = signal('')
|
|
47
|
+
* const debounced = injectDebouncedValue(searchQuery, {
|
|
48
|
+
* wait: 500, // Wait 500ms after last change
|
|
49
|
+
* })
|
|
50
|
+
*
|
|
51
|
+
* // Opt-in to reactive updates when pending state changes (optimized for loading indicators)
|
|
52
|
+
* const debouncedWithPending = injectDebouncedValue(
|
|
53
|
+
* searchQuery,
|
|
54
|
+
* { wait: 500 },
|
|
55
|
+
* (state) => ({ isPending: state.isPending }),
|
|
56
|
+
* )
|
|
57
|
+
*
|
|
58
|
+
* // Debounced value will update 500ms after searchQuery stops changing
|
|
59
|
+
* effect(() => {
|
|
60
|
+
* fetchSearchResults(debounced())
|
|
61
|
+
* })
|
|
62
|
+
*
|
|
63
|
+
* // Access selected debouncer state via signals (only if you provided a selector)
|
|
64
|
+
* effect(() => {
|
|
65
|
+
* console.log('Is pending:', debouncedWithPending.state().isPending)
|
|
66
|
+
* })
|
|
67
|
+
*
|
|
68
|
+
* // Control the debouncer
|
|
69
|
+
* debounced.cancel() // Cancel any pending updates
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
declare function injectDebouncedValue<TValue, TSelected = {}>(value: Signal<TValue>, initialOptions: DebouncerOptions<Setter<TValue>>, selector?: (state: DebouncerState<Setter<TValue>>) => TSelected): DebouncedSignal<TValue, TSelected>;
|
|
73
|
+
declare function injectDebouncedValue<TValue, TSelected = {}>(value: Signal<TValue>, initialValue: TValue, initialOptions: DebouncerOptions<Setter<TValue>>, selector?: (state: DebouncerState<Setter<TValue>>) => TSelected): DebouncedSignal<TValue, TSelected>;
|
|
74
|
+
//#endregion
|
|
75
|
+
export { injectDebouncedValue };
|
|
76
|
+
//# sourceMappingURL=injectDebouncedValue.d.cts.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { DebouncedSignal } from "./injectDebouncedSignal.js";
|
|
2
|
+
import { Signal } from "@angular/core";
|
|
3
|
+
import { DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
|
|
4
|
+
|
|
5
|
+
//#region src/debouncer/injectDebouncedValue.d.ts
|
|
6
|
+
type Setter<T> = (value: T | ((prev: T) => T)) => void;
|
|
7
|
+
/**
|
|
8
|
+
* An Angular function that creates a debounced value that updates only after a specified delay.
|
|
9
|
+
* Unlike injectDebouncedSignal, this function automatically tracks changes to the input signal
|
|
10
|
+
* and updates the debounced value accordingly.
|
|
11
|
+
*
|
|
12
|
+
* The debounced value will only update after the specified wait time has elapsed since
|
|
13
|
+
* the last change to the input value. If the input value changes again before the wait
|
|
14
|
+
* time expires, the timer resets and starts waiting again.
|
|
15
|
+
*
|
|
16
|
+
* This is useful for deriving debounced values from signals that change frequently,
|
|
17
|
+
* like search queries or form inputs, where you want to limit how often downstream effects
|
|
18
|
+
* or calculations occur.
|
|
19
|
+
*
|
|
20
|
+
* The function returns a tuple containing:
|
|
21
|
+
* - A Signal that provides the current debounced value
|
|
22
|
+
* - The debouncer instance with control methods
|
|
23
|
+
*
|
|
24
|
+
* ## State Management and Selector
|
|
25
|
+
*
|
|
26
|
+
* The function uses TanStack Store for reactive state management via the underlying debouncer instance.
|
|
27
|
+
* The `selector` parameter allows you to specify which debouncer state changes will trigger signal updates,
|
|
28
|
+
* optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
|
|
29
|
+
*
|
|
30
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
31
|
+
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
32
|
+
* full control over when your component tracks state changes. Only when you provide a selector will
|
|
33
|
+
* the reactive system track the selected state values.
|
|
34
|
+
*
|
|
35
|
+
* Available debouncer state properties:
|
|
36
|
+
* - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
|
|
37
|
+
* - `executionCount`: Number of function executions that have been completed
|
|
38
|
+
* - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
|
|
39
|
+
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
40
|
+
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
41
|
+
*
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* // Default behavior - no reactive state subscriptions
|
|
46
|
+
* const searchQuery = signal('')
|
|
47
|
+
* const debounced = injectDebouncedValue(searchQuery, {
|
|
48
|
+
* wait: 500, // Wait 500ms after last change
|
|
49
|
+
* })
|
|
50
|
+
*
|
|
51
|
+
* // Opt-in to reactive updates when pending state changes (optimized for loading indicators)
|
|
52
|
+
* const debouncedWithPending = injectDebouncedValue(
|
|
53
|
+
* searchQuery,
|
|
54
|
+
* { wait: 500 },
|
|
55
|
+
* (state) => ({ isPending: state.isPending }),
|
|
56
|
+
* )
|
|
57
|
+
*
|
|
58
|
+
* // Debounced value will update 500ms after searchQuery stops changing
|
|
59
|
+
* effect(() => {
|
|
60
|
+
* fetchSearchResults(debounced())
|
|
61
|
+
* })
|
|
62
|
+
*
|
|
63
|
+
* // Access selected debouncer state via signals (only if you provided a selector)
|
|
64
|
+
* effect(() => {
|
|
65
|
+
* console.log('Is pending:', debouncedWithPending.state().isPending)
|
|
66
|
+
* })
|
|
67
|
+
*
|
|
68
|
+
* // Control the debouncer
|
|
69
|
+
* debounced.cancel() // Cancel any pending updates
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
declare function injectDebouncedValue<TValue, TSelected = {}>(value: Signal<TValue>, initialOptions: DebouncerOptions<Setter<TValue>>, selector?: (state: DebouncerState<Setter<TValue>>) => TSelected): DebouncedSignal<TValue, TSelected>;
|
|
73
|
+
declare function injectDebouncedValue<TValue, TSelected = {}>(value: Signal<TValue>, initialValue: TValue, initialOptions: DebouncerOptions<Setter<TValue>>, selector?: (state: DebouncerState<Setter<TValue>>) => TSelected): DebouncedSignal<TValue, TSelected>;
|
|
74
|
+
//#endregion
|
|
75
|
+
export { injectDebouncedValue };
|
|
76
|
+
//# sourceMappingURL=injectDebouncedValue.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { injectDebouncedSignal } from "./injectDebouncedSignal.js";
|
|
2
|
+
import { effect } from "@angular/core";
|
|
3
|
+
|
|
4
|
+
//#region src/debouncer/injectDebouncedValue.ts
|
|
5
|
+
function injectDebouncedValue(value, initialValueOrOptions, initialOptionsOrSelector, maybeSelector) {
|
|
6
|
+
const hasInitialValue = initialOptionsOrSelector !== void 0 && !(typeof initialOptionsOrSelector === "function") || maybeSelector !== void 0;
|
|
7
|
+
const debounced = injectDebouncedSignal(hasInitialValue ? initialValueOrOptions : void 0, hasInitialValue ? initialOptionsOrSelector : initialValueOrOptions, hasInitialValue ? maybeSelector : initialOptionsOrSelector);
|
|
8
|
+
effect(() => {
|
|
9
|
+
const latest = value();
|
|
10
|
+
debounced.set(latest);
|
|
11
|
+
});
|
|
12
|
+
return debounced;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { injectDebouncedValue };
|
|
17
|
+
//# sourceMappingURL=injectDebouncedValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectDebouncedValue.js","names":[],"sources":["../../src/debouncer/injectDebouncedValue.ts"],"sourcesContent":["import { effect } from '@angular/core'\nimport { injectDebouncedSignal } from './injectDebouncedSignal'\nimport type { DebouncedSignal } from './injectDebouncedSignal'\nimport type { Signal } from '@angular/core'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\n/**\n * An Angular function that creates a debounced value that updates only after a specified delay.\n * Unlike injectDebouncedSignal, this function automatically tracks changes to the input signal\n * and updates the debounced value accordingly.\n *\n * The debounced value will only update after the specified wait time has elapsed since\n * the last change to the input value. If the input value changes again before the wait\n * time expires, the timer resets and starts waiting again.\n *\n * This is useful for deriving debounced values from signals that change frequently,\n * like search queries or form inputs, where you want to limit how often downstream effects\n * or calculations occur.\n *\n * The function returns a tuple containing:\n * - A Signal that provides the current debounced value\n * - The debouncer instance with control methods\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary subscriptions 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. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const searchQuery = signal('')\n * const debounced = injectDebouncedValue(searchQuery, {\n * wait: 500, // Wait 500ms after last change\n * })\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const debouncedWithPending = injectDebouncedValue(\n * searchQuery,\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending }),\n * )\n *\n * // Debounced value will update 500ms after searchQuery stops changing\n * effect(() => {\n * fetchSearchResults(debounced())\n * })\n *\n * // Access selected debouncer state via signals (only if you provided a selector)\n * effect(() => {\n * console.log('Is pending:', debouncedWithPending.state().isPending)\n * })\n *\n * // Control the debouncer\n * debounced.cancel() // Cancel any pending updates\n * ```\n */\nexport function injectDebouncedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialOptions: DebouncerOptions<Setter<TValue>>,\n selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): DebouncedSignal<TValue, TSelected>\nexport function injectDebouncedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValue: TValue,\n initialOptions: DebouncerOptions<Setter<TValue>>,\n selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): DebouncedSignal<TValue, TSelected>\nexport function injectDebouncedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValueOrOptions: TValue | DebouncerOptions<Setter<TValue>>,\n initialOptionsOrSelector?:\n | DebouncerOptions<Setter<TValue>>\n | ((state: DebouncerState<Setter<TValue>>) => TSelected),\n maybeSelector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): DebouncedSignal<TValue, TSelected> {\n const hasSelector = typeof initialOptionsOrSelector === 'function'\n\n const hasInitialValue =\n (initialOptionsOrSelector !== undefined && !hasSelector) ||\n maybeSelector !== undefined\n\n const initialValue = hasInitialValue\n ? (initialValueOrOptions as TValue)\n : (undefined as unknown as TValue)\n const initialOptions = hasInitialValue\n ? (initialOptionsOrSelector as DebouncerOptions<Setter<TValue>>)\n : (initialValueOrOptions as DebouncerOptions<Setter<TValue>>)\n const selector = hasInitialValue\n ? maybeSelector\n : (initialOptionsOrSelector as\n | ((state: DebouncerState<Setter<TValue>>) => TSelected)\n | undefined)\n\n const debounced = injectDebouncedSignal(\n initialValue,\n initialOptions,\n selector,\n )\n\n effect(() => {\n const latest = value()\n debounced.set(latest)\n })\n\n return debounced\n}\n"],"mappings":";;;;AAuFA,SAAgB,qBACd,OACA,uBACA,0BAGA,eACoC;CAGpC,MAAM,kBACH,6BAA6B,UAAa,EAHzB,OAAO,6BAA6B,eAItD,kBAAkB;CAcpB,MAAM,YAAY,sBAZG,kBAChB,wBACA,QACkB,kBAClB,2BACA,uBACY,kBACb,gBACC,yBAQJ;AAED,cAAa;EACX,MAAM,SAAS,OAAO;AACtB,YAAU,IAAI,OAAO;GACrB;AAEF,QAAO"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const require_pacer_context = require('../provider/pacer-context.cjs');
|
|
2
|
+
let _tanstack_angular_store = require("@tanstack/angular-store");
|
|
3
|
+
let _tanstack_pacer_debouncer = require("@tanstack/pacer/debouncer");
|
|
4
|
+
|
|
5
|
+
//#region src/debouncer/injectDebouncer.ts
|
|
6
|
+
/**
|
|
7
|
+
* An Angular function that creates and manages a Debouncer instance.
|
|
8
|
+
*
|
|
9
|
+
* This is a lower-level function that provides direct access to the Debouncer's functionality.
|
|
10
|
+
* This allows you to integrate it with any state management solution you prefer.
|
|
11
|
+
*
|
|
12
|
+
* This function provides debouncing functionality to limit how often a function can be called,
|
|
13
|
+
* waiting for a specified delay before executing the latest call. This is useful for handling
|
|
14
|
+
* frequent events like window resizing, scroll events, or real-time search inputs.
|
|
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
|
+
* - `executionCount`: Number of function executions that have been completed
|
|
33
|
+
* - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
|
|
34
|
+
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
35
|
+
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* // Default behavior - no reactive state subscriptions
|
|
40
|
+
* const debouncer = injectDebouncer(
|
|
41
|
+
* (query: string) => fetchSearchResults(query),
|
|
42
|
+
* { wait: 500 }
|
|
43
|
+
* );
|
|
44
|
+
*
|
|
45
|
+
* // Opt-in to track isPending changes (optimized for loading states)
|
|
46
|
+
* const debouncer = injectDebouncer(
|
|
47
|
+
* (query: string) => fetchSearchResults(query),
|
|
48
|
+
* { wait: 500 },
|
|
49
|
+
* (state) => ({ isPending: state.isPending })
|
|
50
|
+
* );
|
|
51
|
+
*
|
|
52
|
+
* // In an event handler
|
|
53
|
+
* const handleChange = (e: Event) => {
|
|
54
|
+
* const target = e.target as HTMLInputElement
|
|
55
|
+
* debouncer.maybeExecute(target.value);
|
|
56
|
+
* };
|
|
57
|
+
*
|
|
58
|
+
* // Access the selected state (will be empty object {} unless selector provided)
|
|
59
|
+
* const { isPending } = debouncer.state();
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
function injectDebouncer(fn, options, selector = () => ({})) {
|
|
63
|
+
const debouncer = new _tanstack_pacer_debouncer.Debouncer(fn, {
|
|
64
|
+
...require_pacer_context.injectPacerOptions().debouncer,
|
|
65
|
+
...options
|
|
66
|
+
});
|
|
67
|
+
const state = (0, _tanstack_angular_store.injectStore)(debouncer.store, selector);
|
|
68
|
+
return {
|
|
69
|
+
...debouncer,
|
|
70
|
+
state
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
exports.injectDebouncer = injectDebouncer;
|
|
76
|
+
//# sourceMappingURL=injectDebouncer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectDebouncer.cjs","names":["Debouncer","injectPacerOptions"],"sources":["../../src/debouncer/injectDebouncer.ts"],"sourcesContent":["import { injectStore } from '@tanstack/angular-store'\nimport { Debouncer } from '@tanstack/pacer/debouncer'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/store'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\nexport interface AngularDebouncer<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Debouncer<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the debouncer state changes\n *\n * Use this instead of `debouncer.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<DebouncerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages a Debouncer instance.\n *\n * This is a lower-level function that provides direct access to the Debouncer's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides debouncing functionality to limit how often a function can be called,\n * waiting for a specified delay before executing the latest call. This is useful for handling\n * frequent events like window resizing, scroll events, or real-time search inputs.\n *\n * The debouncer will only execute the function after the specified wait time has elapsed\n * since the last call. If the function is called again before the wait time expires, the\n * timer resets and starts waiting again.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const debouncer = injectDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 }\n * );\n *\n * // Opt-in to track isPending changes (optimized for loading states)\n * const debouncer = injectDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // In an event handler\n * const handleChange = (e: Event) => {\n * const target = e.target as HTMLInputElement\n * debouncer.maybeExecute(target.value);\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = debouncer.state();\n * ```\n */\nexport function injectDebouncer<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: DebouncerOptions<TFn>,\n selector: (state: DebouncerState<TFn>) => TSelected = () => ({}) as TSelected,\n): AngularDebouncer<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().debouncer,\n ...options,\n } as DebouncerOptions<TFn>\n\n const debouncer = new Debouncer<TFn>(fn, mergedOptions)\n const state = injectStore(debouncer.store, selector)\n\n return {\n ...debouncer,\n state,\n } as AngularDebouncer<TFn, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoFA,SAAgB,gBACd,IACA,SACA,kBAA6D,EAAE,GAC7B;CAMlC,MAAM,YAAY,IAAIA,oCAAe,IALf;EACpB,GAAGC,0CAAoB,CAAC;EACxB,GAAG;EACJ,CAEsD;CACvD,MAAM,iDAAoB,UAAU,OAAO,SAAS;AAEpD,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Signal } from "@angular/core";
|
|
2
|
+
import { Store } from "@tanstack/store";
|
|
3
|
+
import { AnyFunction } from "@tanstack/pacer/types";
|
|
4
|
+
import { Debouncer, DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
|
|
5
|
+
|
|
6
|
+
//#region src/debouncer/injectDebouncer.d.ts
|
|
7
|
+
interface AngularDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<Debouncer<TFn>, 'store'> {
|
|
8
|
+
/**
|
|
9
|
+
* Reactive state signal that will be updated when the debouncer state changes
|
|
10
|
+
*
|
|
11
|
+
* Use this instead of `debouncer.store.state`
|
|
12
|
+
*/
|
|
13
|
+
readonly state: Signal<Readonly<TSelected>>;
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.
|
|
16
|
+
* The state on the store object is not reactive in Angular signals.
|
|
17
|
+
*/
|
|
18
|
+
readonly store: Store<Readonly<DebouncerState<TFn>>>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* An Angular function that creates and manages a Debouncer instance.
|
|
22
|
+
*
|
|
23
|
+
* This is a lower-level function that provides direct access to the Debouncer's functionality.
|
|
24
|
+
* This allows you to integrate it with any state management solution you prefer.
|
|
25
|
+
*
|
|
26
|
+
* This function provides debouncing functionality to limit how often a function can be called,
|
|
27
|
+
* waiting for a specified delay before executing the latest call. This is useful for handling
|
|
28
|
+
* frequent events like window resizing, scroll events, or real-time search inputs.
|
|
29
|
+
*
|
|
30
|
+
* The debouncer will only execute the function after the specified wait time has elapsed
|
|
31
|
+
* since the last call. If the function is called again before the wait time expires, the
|
|
32
|
+
* timer resets and starts waiting again.
|
|
33
|
+
*
|
|
34
|
+
* ## State Management and Selector
|
|
35
|
+
*
|
|
36
|
+
* The function uses TanStack Store for state management and wraps it with Angular signals.
|
|
37
|
+
* The `selector` parameter allows you to specify which state changes will trigger signal updates,
|
|
38
|
+
* optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
|
|
39
|
+
*
|
|
40
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
41
|
+
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
42
|
+
* full control over when your component tracks state changes.
|
|
43
|
+
*
|
|
44
|
+
* Available state properties:
|
|
45
|
+
* - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
|
|
46
|
+
* - `executionCount`: Number of function executions that have been completed
|
|
47
|
+
* - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
|
|
48
|
+
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
49
|
+
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* // Default behavior - no reactive state subscriptions
|
|
54
|
+
* const debouncer = injectDebouncer(
|
|
55
|
+
* (query: string) => fetchSearchResults(query),
|
|
56
|
+
* { wait: 500 }
|
|
57
|
+
* );
|
|
58
|
+
*
|
|
59
|
+
* // Opt-in to track isPending changes (optimized for loading states)
|
|
60
|
+
* const debouncer = injectDebouncer(
|
|
61
|
+
* (query: string) => fetchSearchResults(query),
|
|
62
|
+
* { wait: 500 },
|
|
63
|
+
* (state) => ({ isPending: state.isPending })
|
|
64
|
+
* );
|
|
65
|
+
*
|
|
66
|
+
* // In an event handler
|
|
67
|
+
* const handleChange = (e: Event) => {
|
|
68
|
+
* const target = e.target as HTMLInputElement
|
|
69
|
+
* debouncer.maybeExecute(target.value);
|
|
70
|
+
* };
|
|
71
|
+
*
|
|
72
|
+
* // Access the selected state (will be empty object {} unless selector provided)
|
|
73
|
+
* const { isPending } = debouncer.state();
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
declare function injectDebouncer<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: DebouncerOptions<TFn>, selector?: (state: DebouncerState<TFn>) => TSelected): AngularDebouncer<TFn, TSelected>;
|
|
77
|
+
//#endregion
|
|
78
|
+
export { AngularDebouncer, injectDebouncer };
|
|
79
|
+
//# sourceMappingURL=injectDebouncer.d.cts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Signal } from "@angular/core";
|
|
2
|
+
import { Debouncer, DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
|
|
3
|
+
import { AnyFunction } from "@tanstack/pacer/types";
|
|
4
|
+
import { Store } from "@tanstack/store";
|
|
5
|
+
|
|
6
|
+
//#region src/debouncer/injectDebouncer.d.ts
|
|
7
|
+
interface AngularDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<Debouncer<TFn>, 'store'> {
|
|
8
|
+
/**
|
|
9
|
+
* Reactive state signal that will be updated when the debouncer state changes
|
|
10
|
+
*
|
|
11
|
+
* Use this instead of `debouncer.store.state`
|
|
12
|
+
*/
|
|
13
|
+
readonly state: Signal<Readonly<TSelected>>;
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.
|
|
16
|
+
* The state on the store object is not reactive in Angular signals.
|
|
17
|
+
*/
|
|
18
|
+
readonly store: Store<Readonly<DebouncerState<TFn>>>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* An Angular function that creates and manages a Debouncer instance.
|
|
22
|
+
*
|
|
23
|
+
* This is a lower-level function that provides direct access to the Debouncer's functionality.
|
|
24
|
+
* This allows you to integrate it with any state management solution you prefer.
|
|
25
|
+
*
|
|
26
|
+
* This function provides debouncing functionality to limit how often a function can be called,
|
|
27
|
+
* waiting for a specified delay before executing the latest call. This is useful for handling
|
|
28
|
+
* frequent events like window resizing, scroll events, or real-time search inputs.
|
|
29
|
+
*
|
|
30
|
+
* The debouncer will only execute the function after the specified wait time has elapsed
|
|
31
|
+
* since the last call. If the function is called again before the wait time expires, the
|
|
32
|
+
* timer resets and starts waiting again.
|
|
33
|
+
*
|
|
34
|
+
* ## State Management and Selector
|
|
35
|
+
*
|
|
36
|
+
* The function uses TanStack Store for state management and wraps it with Angular signals.
|
|
37
|
+
* The `selector` parameter allows you to specify which state changes will trigger signal updates,
|
|
38
|
+
* optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
|
|
39
|
+
*
|
|
40
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
41
|
+
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
42
|
+
* full control over when your component tracks state changes.
|
|
43
|
+
*
|
|
44
|
+
* Available state properties:
|
|
45
|
+
* - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
|
|
46
|
+
* - `executionCount`: Number of function executions that have been completed
|
|
47
|
+
* - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
|
|
48
|
+
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
49
|
+
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* // Default behavior - no reactive state subscriptions
|
|
54
|
+
* const debouncer = injectDebouncer(
|
|
55
|
+
* (query: string) => fetchSearchResults(query),
|
|
56
|
+
* { wait: 500 }
|
|
57
|
+
* );
|
|
58
|
+
*
|
|
59
|
+
* // Opt-in to track isPending changes (optimized for loading states)
|
|
60
|
+
* const debouncer = injectDebouncer(
|
|
61
|
+
* (query: string) => fetchSearchResults(query),
|
|
62
|
+
* { wait: 500 },
|
|
63
|
+
* (state) => ({ isPending: state.isPending })
|
|
64
|
+
* );
|
|
65
|
+
*
|
|
66
|
+
* // In an event handler
|
|
67
|
+
* const handleChange = (e: Event) => {
|
|
68
|
+
* const target = e.target as HTMLInputElement
|
|
69
|
+
* debouncer.maybeExecute(target.value);
|
|
70
|
+
* };
|
|
71
|
+
*
|
|
72
|
+
* // Access the selected state (will be empty object {} unless selector provided)
|
|
73
|
+
* const { isPending } = debouncer.state();
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
declare function injectDebouncer<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: DebouncerOptions<TFn>, selector?: (state: DebouncerState<TFn>) => TSelected): AngularDebouncer<TFn, TSelected>;
|
|
77
|
+
//#endregion
|
|
78
|
+
export { AngularDebouncer, injectDebouncer };
|
|
79
|
+
//# sourceMappingURL=injectDebouncer.d.ts.map
|