@tanstack/preact-pacer 0.23.0 → 0.24.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/dist/async-batcher/useAsyncBatchedCallback.d.ts +2 -4
- package/dist/async-batcher/useAsyncBatchedCallback.js +1 -2
- package/dist/async-batcher/useAsyncBatcher.d.ts +4 -7
- package/dist/async-batcher/useAsyncBatcher.js +1 -3
- package/dist/async-debouncer/useAsyncDebouncedCallback.d.ts +2 -4
- package/dist/async-debouncer/useAsyncDebouncedCallback.js +1 -2
- package/dist/async-debouncer/useAsyncDebouncer.d.ts +4 -6
- package/dist/async-debouncer/useAsyncDebouncer.js +1 -2
- package/dist/async-queuer/useAsyncQueuedState.d.ts +4 -6
- package/dist/async-queuer/useAsyncQueuedState.js +3 -4
- package/dist/async-queuer/useAsyncQueuer.d.ts +6 -8
- package/dist/async-queuer/useAsyncQueuer.js +3 -4
- package/dist/async-rate-limiter/useAsyncRateLimitedCallback.d.ts +2 -4
- package/dist/async-rate-limiter/useAsyncRateLimitedCallback.js +1 -2
- package/dist/async-rate-limiter/useAsyncRateLimiter.d.ts +4 -6
- package/dist/async-rate-limiter/useAsyncRateLimiter.js +1 -2
- package/dist/async-throttler/useAsyncThrottledCallback.d.ts +2 -4
- package/dist/async-throttler/useAsyncThrottledCallback.js +1 -2
- package/dist/async-throttler/useAsyncThrottler.d.ts +4 -6
- package/dist/async-throttler/useAsyncThrottler.js +1 -2
- package/dist/batcher/useBatchedCallback.d.ts +2 -4
- package/dist/batcher/useBatchedCallback.js +1 -2
- package/dist/batcher/useBatcher.d.ts +6 -10
- package/dist/batcher/useBatcher.js +3 -6
- package/dist/debouncer/useDebouncedCallback.d.ts +2 -4
- package/dist/debouncer/useDebouncedCallback.js +1 -2
- package/dist/debouncer/useDebouncedState.d.ts +2 -4
- package/dist/debouncer/useDebouncedState.js +1 -2
- package/dist/debouncer/useDebouncedValue.d.ts +2 -4
- package/dist/debouncer/useDebouncedValue.js +1 -2
- package/dist/debouncer/useDebouncer.d.ts +4 -6
- package/dist/debouncer/useDebouncer.js +1 -2
- package/dist/provider/PacerProvider.d.ts +6 -8
- package/dist/provider/PacerProvider.js +1 -2
- package/dist/queuer/useQueuedState.d.ts +2 -4
- package/dist/queuer/useQueuedState.js +1 -2
- package/dist/queuer/useQueuedValue.d.ts +2 -4
- package/dist/queuer/useQueuedValue.js +1 -2
- package/dist/queuer/useQueuer.d.ts +4 -6
- package/dist/queuer/useQueuer.js +1 -2
- package/dist/rate-limiter/useRateLimitedCallback.d.ts +2 -4
- package/dist/rate-limiter/useRateLimitedCallback.js +1 -2
- package/dist/rate-limiter/useRateLimitedState.d.ts +2 -4
- package/dist/rate-limiter/useRateLimitedState.js +1 -2
- package/dist/rate-limiter/useRateLimitedValue.d.ts +2 -4
- package/dist/rate-limiter/useRateLimitedValue.js +1 -2
- package/dist/rate-limiter/useRateLimiter.d.ts +4 -6
- package/dist/rate-limiter/useRateLimiter.js +1 -2
- package/dist/throttler/useThrottledCallback.d.ts +2 -4
- package/dist/throttler/useThrottledCallback.js +1 -2
- package/dist/throttler/useThrottledState.d.ts +2 -4
- package/dist/throttler/useThrottledState.js +1 -2
- package/dist/throttler/useThrottledValue.d.ts +2 -4
- package/dist/throttler/useThrottledValue.js +1 -2
- package/dist/throttler/useThrottler.d.ts +4 -6
- package/dist/throttler/useThrottler.js +1 -2
- package/package.json +22 -70
- package/dist/async-batcher/index.cjs +0 -13
- package/dist/async-batcher/index.d.cts +0 -4
- package/dist/async-batcher/useAsyncBatchedCallback.cjs +0 -51
- package/dist/async-batcher/useAsyncBatchedCallback.cjs.map +0 -1
- package/dist/async-batcher/useAsyncBatchedCallback.d.cts +0 -43
- package/dist/async-batcher/useAsyncBatchedCallback.js.map +0 -1
- package/dist/async-batcher/useAsyncBatcher.cjs +0 -217
- package/dist/async-batcher/useAsyncBatcher.cjs.map +0 -1
- package/dist/async-batcher/useAsyncBatcher.d.cts +0 -223
- package/dist/async-batcher/useAsyncBatcher.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/useAsyncDebouncedCallback.cjs +0 -52
- package/dist/async-debouncer/useAsyncDebouncedCallback.cjs.map +0 -1
- package/dist/async-debouncer/useAsyncDebouncedCallback.d.cts +0 -47
- package/dist/async-debouncer/useAsyncDebouncedCallback.js.map +0 -1
- package/dist/async-debouncer/useAsyncDebouncer.cjs +0 -195
- package/dist/async-debouncer/useAsyncDebouncer.cjs.map +0 -1
- package/dist/async-debouncer/useAsyncDebouncer.d.cts +0 -202
- package/dist/async-debouncer/useAsyncDebouncer.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/useAsyncQueuedState.cjs +0 -154
- package/dist/async-queuer/useAsyncQueuedState.cjs.map +0 -1
- package/dist/async-queuer/useAsyncQueuedState.d.cts +0 -150
- package/dist/async-queuer/useAsyncQueuedState.js.map +0 -1
- package/dist/async-queuer/useAsyncQueuer.cjs +0 -217
- package/dist/async-queuer/useAsyncQueuer.cjs.map +0 -1
- package/dist/async-queuer/useAsyncQueuer.d.cts +0 -223
- package/dist/async-queuer/useAsyncQueuer.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/useAsyncRateLimitedCallback.cjs +0 -65
- package/dist/async-rate-limiter/useAsyncRateLimitedCallback.cjs.map +0 -1
- package/dist/async-rate-limiter/useAsyncRateLimitedCallback.d.cts +0 -60
- package/dist/async-rate-limiter/useAsyncRateLimitedCallback.js.map +0 -1
- package/dist/async-rate-limiter/useAsyncRateLimiter.cjs +0 -209
- package/dist/async-rate-limiter/useAsyncRateLimiter.cjs.map +0 -1
- package/dist/async-rate-limiter/useAsyncRateLimiter.d.cts +0 -219
- package/dist/async-rate-limiter/useAsyncRateLimiter.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/useAsyncThrottledCallback.cjs +0 -49
- package/dist/async-throttler/useAsyncThrottledCallback.cjs.map +0 -1
- package/dist/async-throttler/useAsyncThrottledCallback.d.cts +0 -44
- package/dist/async-throttler/useAsyncThrottledCallback.js.map +0 -1
- package/dist/async-throttler/useAsyncThrottler.cjs +0 -206
- package/dist/async-throttler/useAsyncThrottler.cjs.map +0 -1
- package/dist/async-throttler/useAsyncThrottler.d.cts +0 -213
- package/dist/async-throttler/useAsyncThrottler.js.map +0 -1
- package/dist/batcher/index.cjs +0 -13
- package/dist/batcher/index.d.cts +0 -4
- package/dist/batcher/useBatchedCallback.cjs +0 -47
- package/dist/batcher/useBatchedCallback.cjs.map +0 -1
- package/dist/batcher/useBatchedCallback.d.cts +0 -41
- package/dist/batcher/useBatchedCallback.js.map +0 -1
- package/dist/batcher/useBatcher.cjs +0 -165
- package/dist/batcher/useBatcher.cjs.map +0 -1
- package/dist/batcher/useBatcher.d.cts +0 -174
- package/dist/batcher/useBatcher.js.map +0 -1
- package/dist/debouncer/index.cjs +0 -17
- package/dist/debouncer/index.d.cts +0 -6
- package/dist/debouncer/useDebouncedCallback.cjs +0 -48
- package/dist/debouncer/useDebouncedCallback.cjs.map +0 -1
- package/dist/debouncer/useDebouncedCallback.d.cts +0 -43
- package/dist/debouncer/useDebouncedCallback.js.map +0 -1
- package/dist/debouncer/useDebouncedState.cjs +0 -89
- package/dist/debouncer/useDebouncedState.cjs.map +0 -1
- package/dist/debouncer/useDebouncedState.d.cts +0 -80
- package/dist/debouncer/useDebouncedState.js.map +0 -1
- package/dist/debouncer/useDebouncedValue.cjs +0 -96
- package/dist/debouncer/useDebouncedValue.cjs.map +0 -1
- package/dist/debouncer/useDebouncedValue.d.cts +0 -89
- package/dist/debouncer/useDebouncedValue.js.map +0 -1
- package/dist/debouncer/useDebouncer.cjs +0 -141
- package/dist/debouncer/useDebouncer.cjs.map +0 -1
- package/dist/debouncer/useDebouncer.d.cts +0 -151
- package/dist/debouncer/useDebouncer.js.map +0 -1
- package/dist/index.cjs +0 -67
- package/dist/index.d.cts +0 -30
- package/dist/provider/PacerProvider.cjs +0 -26
- package/dist/provider/PacerProvider.cjs.map +0 -1
- package/dist/provider/PacerProvider.d.cts +0 -28
- package/dist/provider/PacerProvider.js.map +0 -1
- package/dist/provider/index.cjs +0 -6
- package/dist/provider/index.d.cts +0 -2
- package/dist/queuer/index.cjs +0 -15
- package/dist/queuer/index.d.cts +0 -5
- package/dist/queuer/useQueuedState.cjs +0 -129
- package/dist/queuer/useQueuedState.cjs.map +0 -1
- package/dist/queuer/useQueuedState.d.cts +0 -121
- package/dist/queuer/useQueuedState.js.map +0 -1
- package/dist/queuer/useQueuedValue.cjs +0 -115
- package/dist/queuer/useQueuedValue.cjs.map +0 -1
- package/dist/queuer/useQueuedValue.d.cts +0 -104
- package/dist/queuer/useQueuedValue.js.map +0 -1
- package/dist/queuer/useQueuer.cjs +0 -176
- package/dist/queuer/useQueuer.cjs.map +0 -1
- package/dist/queuer/useQueuer.d.cts +0 -185
- package/dist/queuer/useQueuer.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/useRateLimitedCallback.cjs +0 -65
- package/dist/rate-limiter/useRateLimitedCallback.cjs.map +0 -1
- package/dist/rate-limiter/useRateLimitedCallback.d.cts +0 -60
- package/dist/rate-limiter/useRateLimitedCallback.js.map +0 -1
- package/dist/rate-limiter/useRateLimitedState.cjs +0 -115
- package/dist/rate-limiter/useRateLimitedState.cjs.map +0 -1
- package/dist/rate-limiter/useRateLimitedState.d.cts +0 -106
- package/dist/rate-limiter/useRateLimitedState.js.map +0 -1
- package/dist/rate-limiter/useRateLimitedValue.cjs +0 -102
- package/dist/rate-limiter/useRateLimitedValue.cjs.map +0 -1
- package/dist/rate-limiter/useRateLimitedValue.d.cts +0 -95
- package/dist/rate-limiter/useRateLimitedValue.js.map +0 -1
- package/dist/rate-limiter/useRateLimiter.cjs +0 -167
- package/dist/rate-limiter/useRateLimiter.cjs.map +0 -1
- package/dist/rate-limiter/useRateLimiter.d.cts +0 -178
- package/dist/rate-limiter/useRateLimiter.js.map +0 -1
- package/dist/throttler/index.cjs +0 -17
- package/dist/throttler/index.d.cts +0 -6
- package/dist/throttler/useThrottledCallback.cjs +0 -49
- package/dist/throttler/useThrottledCallback.cjs.map +0 -1
- package/dist/throttler/useThrottledCallback.d.cts +0 -44
- package/dist/throttler/useThrottledCallback.js.map +0 -1
- package/dist/throttler/useThrottledState.cjs +0 -100
- package/dist/throttler/useThrottledState.cjs.map +0 -1
- package/dist/throttler/useThrottledState.d.cts +0 -91
- package/dist/throttler/useThrottledState.js.map +0 -1
- package/dist/throttler/useThrottledValue.cjs +0 -91
- package/dist/throttler/useThrottledValue.cjs.map +0 -1
- package/dist/throttler/useThrottledValue.d.cts +0 -84
- package/dist/throttler/useThrottledValue.js.map +0 -1
- package/dist/throttler/useThrottler.cjs +0 -146
- package/dist/throttler/useThrottler.cjs.map +0 -1
- package/dist/throttler/useThrottler.d.cts +0 -156
- package/dist/throttler/useThrottler.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/useAsyncBatchedCallback.ts +0 -53
- package/src/async-batcher/useAsyncBatcher.ts +0 -293
- package/src/async-debouncer/index.ts +0 -5
- package/src/async-debouncer/useAsyncDebouncedCallback.ts +0 -55
- package/src/async-debouncer/useAsyncDebouncer.ts +0 -274
- package/src/async-queuer/index.ts +0 -4
- package/src/async-queuer/useAsyncQueuedState.ts +0 -165
- package/src/async-queuer/useAsyncQueuer.ts +0 -293
- package/src/async-rate-limiter/index.ts +0 -5
- package/src/async-rate-limiter/useAsyncRateLimitedCallback.ts +0 -68
- package/src/async-rate-limiter/useAsyncRateLimiter.ts +0 -294
- package/src/async-retryer/index.ts +0 -2
- package/src/async-throttler/index.ts +0 -5
- package/src/async-throttler/useAsyncThrottledCallback.ts +0 -52
- package/src/async-throttler/useAsyncThrottler.ts +0 -285
- package/src/batcher/index.ts +0 -4
- package/src/batcher/useBatchedCallback.ts +0 -46
- package/src/batcher/useBatcher.ts +0 -241
- package/src/debouncer/index.ts +0 -7
- package/src/debouncer/useDebouncedCallback.ts +0 -51
- package/src/debouncer/useDebouncedState.ts +0 -106
- package/src/debouncer/useDebouncedValue.ts +0 -109
- package/src/debouncer/useDebouncer.ts +0 -219
- package/src/index.ts +0 -56
- package/src/provider/PacerProvider.tsx +0 -70
- package/src/provider/index.ts +0 -1
- package/src/queuer/index.ts +0 -5
- package/src/queuer/useQueuedState.ts +0 -133
- package/src/queuer/useQueuedValue.ts +0 -129
- package/src/queuer/useQueuer.ts +0 -251
- package/src/rate-limiter/index.ts +0 -6
- package/src/rate-limiter/useRateLimitedCallback.ts +0 -68
- package/src/rate-limiter/useRateLimitedState.ts +0 -124
- package/src/rate-limiter/useRateLimitedValue.ts +0 -110
- package/src/rate-limiter/useRateLimiter.ts +0 -244
- package/src/throttler/index.ts +0 -7
- package/src/throttler/useThrottledCallback.ts +0 -52
- package/src/throttler/useThrottledState.ts +0 -118
- package/src/throttler/useThrottledValue.ts +0 -104
- package/src/throttler/useThrottler.ts +0 -224
- package/src/types/index.ts +0 -1
- package/src/utils/index.ts +0 -1
|
@@ -98,7 +98,5 @@ import { QueuerState } from "@tanstack/pacer/queuer";
|
|
|
98
98
|
* const { size, isRunning, executionCount } = queuer.state;
|
|
99
99
|
* ```
|
|
100
100
|
*/
|
|
101
|
-
declare function useQueuedValue<TValue, TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<QueuerState<TValue>, 'items'>>(initialValue: TValue, options?: PreactQueuerOptions<TValue, TSelected>, selector?: (state: QueuerState<TValue>) => TSelected): [TValue, PreactQueuer<TValue, TSelected>];
|
|
102
|
-
//#endregion
|
|
103
|
-
export { useQueuedValue };
|
|
104
|
-
//# sourceMappingURL=useQueuedValue.d.ts.map
|
|
101
|
+
export declare function useQueuedValue<TValue, TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<QueuerState<TValue>, 'items'>>(initialValue: TValue, options?: PreactQueuerOptions<TValue, TSelected>, selector?: (state: QueuerState<TValue>) => TSelected): [TValue, PreactQueuer<TValue, TSelected>];
|
|
102
|
+
//#endregion
|
|
@@ -2,14 +2,14 @@ import { ComponentChildren } from "preact";
|
|
|
2
2
|
import { Store } from "@tanstack/preact-store";
|
|
3
3
|
import { Queuer, QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
|
|
4
4
|
//#region src/queuer/useQueuer.d.ts
|
|
5
|
-
interface PreactQueuerOptions<TValue, TSelected = {}> extends QueuerOptions<TValue> {
|
|
5
|
+
export interface PreactQueuerOptions<TValue, TSelected = {}> extends QueuerOptions<TValue> {
|
|
6
6
|
/**
|
|
7
7
|
* Optional callback invoked when the component unmounts. Receives the queuer instance.
|
|
8
8
|
* When provided, replaces the default cleanup (stop); use it to call flush(), flushAsBatch(), stop(), add logging, etc.
|
|
9
9
|
*/
|
|
10
10
|
onUnmount?: (queuer: PreactQueuer<TValue, TSelected>) => void;
|
|
11
11
|
}
|
|
12
|
-
interface PreactQueuer<TValue, TSelected = {}> extends Omit<Queuer<TValue>, 'store'> {
|
|
12
|
+
export interface PreactQueuer<TValue, TSelected = {}> extends Omit<Queuer<TValue>, 'store'> {
|
|
13
13
|
/**
|
|
14
14
|
* A Preact HOC (Higher Order Component) that allows you to subscribe to the queuer state.
|
|
15
15
|
*
|
|
@@ -179,7 +179,5 @@ interface PreactQueuer<TValue, TSelected = {}> extends Omit<Queuer<TValue>, 'sto
|
|
|
179
179
|
* const { size, isRunning, executionCount } = queue.state;
|
|
180
180
|
* ```
|
|
181
181
|
*/
|
|
182
|
-
declare function useQueuer<TValue, TSelected = {}>(fn: (item: TValue) => void, options?: PreactQueuerOptions<TValue, TSelected>, selector?: (state: QueuerState<TValue>) => TSelected): PreactQueuer<TValue, TSelected>;
|
|
183
|
-
//#endregion
|
|
184
|
-
export { PreactQueuer, PreactQueuerOptions, useQueuer };
|
|
185
|
-
//# sourceMappingURL=useQueuer.d.ts.map
|
|
182
|
+
export declare function useQueuer<TValue, TSelected = {}>(fn: (item: TValue) => void, options?: PreactQueuerOptions<TValue, TSelected>, selector?: (state: QueuerState<TValue>) => TSelected): PreactQueuer<TValue, TSelected>;
|
|
183
|
+
//#endregion
|
package/dist/queuer/useQueuer.js
CHANGED
|
@@ -54,7 +54,5 @@ import { AnyFunction } from "@tanstack/pacer/types";
|
|
|
54
54
|
* );
|
|
55
55
|
* ```
|
|
56
56
|
*/
|
|
57
|
-
declare function useRateLimitedCallback<TFn extends AnyFunction>(fn: TFn, options: PreactRateLimiterOptions<TFn, {}>): (...args: Parameters<TFn>) => boolean;
|
|
58
|
-
//#endregion
|
|
59
|
-
export { useRateLimitedCallback };
|
|
60
|
-
//# sourceMappingURL=useRateLimitedCallback.d.ts.map
|
|
57
|
+
export declare function useRateLimitedCallback<TFn extends AnyFunction>(fn: TFn, options: PreactRateLimiterOptions<TFn, {}>): (...args: Parameters<TFn>) => boolean;
|
|
58
|
+
//#endregion
|
|
@@ -100,7 +100,5 @@ import { RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
|
100
100
|
* const { executionCount, rejectionCount } = rateLimiter.state;
|
|
101
101
|
* ```
|
|
102
102
|
*/
|
|
103
|
-
declare function useRateLimitedState<TValue, TSelected = RateLimiterState>(value: TValue, options: PreactRateLimiterOptions<Dispatch<StateUpdater<TValue>>, TSelected>, selector?: (state: RateLimiterState) => TSelected): [TValue, Dispatch<StateUpdater<TValue>>, PreactRateLimiter<Dispatch<StateUpdater<TValue>>, TSelected>];
|
|
104
|
-
//#endregion
|
|
105
|
-
export { useRateLimitedState };
|
|
106
|
-
//# sourceMappingURL=useRateLimitedState.d.ts.map
|
|
103
|
+
export declare function useRateLimitedState<TValue, TSelected = RateLimiterState>(value: TValue, options: PreactRateLimiterOptions<Dispatch<StateUpdater<TValue>>, TSelected>, selector?: (state: RateLimiterState) => TSelected): [TValue, Dispatch<StateUpdater<TValue>>, PreactRateLimiter<Dispatch<StateUpdater<TValue>>, TSelected>];
|
|
104
|
+
//#endregion
|
|
@@ -89,7 +89,5 @@ import { RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
|
89
89
|
* const { executionCount, rejectionCount } = rateLimiter.state;
|
|
90
90
|
* ```
|
|
91
91
|
*/
|
|
92
|
-
declare function useRateLimitedValue<TValue, TSelected = RateLimiterState>(value: TValue, options: PreactRateLimiterOptions<Dispatch<StateUpdater<TValue>>, TSelected>, selector?: (state: RateLimiterState) => TSelected): [TValue, PreactRateLimiter<Dispatch<StateUpdater<TValue>>, TSelected>];
|
|
93
|
-
//#endregion
|
|
94
|
-
export { useRateLimitedValue };
|
|
95
|
-
//# sourceMappingURL=useRateLimitedValue.d.ts.map
|
|
92
|
+
export declare function useRateLimitedValue<TValue, TSelected = RateLimiterState>(value: TValue, options: PreactRateLimiterOptions<Dispatch<StateUpdater<TValue>>, TSelected>, selector?: (state: RateLimiterState) => TSelected): [TValue, PreactRateLimiter<Dispatch<StateUpdater<TValue>>, TSelected>];
|
|
93
|
+
//#endregion
|
|
@@ -3,14 +3,14 @@ import { Store } from "@tanstack/preact-store";
|
|
|
3
3
|
import { RateLimiter, RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
4
4
|
import { AnyFunction } from "@tanstack/pacer/types";
|
|
5
5
|
//#region src/rate-limiter/useRateLimiter.d.ts
|
|
6
|
-
interface PreactRateLimiterOptions<TFn extends AnyFunction, TSelected = {}> extends RateLimiterOptions<TFn> {
|
|
6
|
+
export interface PreactRateLimiterOptions<TFn extends AnyFunction, TSelected = {}> extends RateLimiterOptions<TFn> {
|
|
7
7
|
/**
|
|
8
8
|
* Optional callback invoked when the component unmounts. Receives the rate limiter instance.
|
|
9
9
|
* When provided, replaces the default cleanup; use it to call reset(), add logging, etc.
|
|
10
10
|
*/
|
|
11
11
|
onUnmount?: (rateLimiter: PreactRateLimiter<TFn, TSelected>) => void;
|
|
12
12
|
}
|
|
13
|
-
interface PreactRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Omit<RateLimiter<TFn>, 'store'> {
|
|
13
|
+
export interface PreactRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Omit<RateLimiter<TFn>, 'store'> {
|
|
14
14
|
/**
|
|
15
15
|
* A Preact HOC (Higher Order Component) that allows you to subscribe to the rate limiter state.
|
|
16
16
|
*
|
|
@@ -172,7 +172,5 @@ interface PreactRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Omi
|
|
|
172
172
|
* const { executionCount, rejectionCount } = rateLimiter.state;
|
|
173
173
|
* ```
|
|
174
174
|
*/
|
|
175
|
-
declare function useRateLimiter<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: PreactRateLimiterOptions<TFn, TSelected>, selector?: (state: RateLimiterState) => TSelected): PreactRateLimiter<TFn, TSelected>;
|
|
176
|
-
//#endregion
|
|
177
|
-
export { PreactRateLimiter, PreactRateLimiterOptions, useRateLimiter };
|
|
178
|
-
//# sourceMappingURL=useRateLimiter.d.ts.map
|
|
175
|
+
export declare function useRateLimiter<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: PreactRateLimiterOptions<TFn, TSelected>, selector?: (state: RateLimiterState) => TSelected): PreactRateLimiter<TFn, TSelected>;
|
|
176
|
+
//#endregion
|
|
@@ -38,7 +38,5 @@ import { AnyFunction } from "@tanstack/pacer/types";
|
|
|
38
38
|
* }, [handleResize]);
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
|
-
declare function useThrottledCallback<TFn extends AnyFunction>(fn: TFn, options: PreactThrottlerOptions<TFn, {}>): (...args: Parameters<TFn>) => void;
|
|
42
|
-
//#endregion
|
|
43
|
-
export { useThrottledCallback };
|
|
44
|
-
//# sourceMappingURL=useThrottledCallback.d.ts.map
|
|
41
|
+
export declare function useThrottledCallback<TFn extends AnyFunction>(fn: TFn, options: PreactThrottlerOptions<TFn, {}>): (...args: Parameters<TFn>) => void;
|
|
42
|
+
//#endregion
|
|
@@ -85,7 +85,5 @@ import { ThrottlerState } from "@tanstack/pacer/throttler";
|
|
|
85
85
|
* const { executionCount, isPending } = throttler.state;
|
|
86
86
|
* ```
|
|
87
87
|
*/
|
|
88
|
-
declare function useThrottledState<TValue, TSelected = ThrottlerState<Dispatch<StateUpdater<TValue>>>>(value: TValue, options: PreactThrottlerOptions<Dispatch<StateUpdater<TValue>>, TSelected>, selector?: (state: ThrottlerState<Dispatch<StateUpdater<TValue>>>) => TSelected): [TValue, Dispatch<StateUpdater<TValue>>, PreactThrottler<Dispatch<StateUpdater<TValue>>, TSelected>];
|
|
89
|
-
//#endregion
|
|
90
|
-
export { useThrottledState };
|
|
91
|
-
//# sourceMappingURL=useThrottledState.d.ts.map
|
|
88
|
+
export declare function useThrottledState<TValue, TSelected = ThrottlerState<Dispatch<StateUpdater<TValue>>>>(value: TValue, options: PreactThrottlerOptions<Dispatch<StateUpdater<TValue>>, TSelected>, selector?: (state: ThrottlerState<Dispatch<StateUpdater<TValue>>>) => TSelected): [TValue, Dispatch<StateUpdater<TValue>>, PreactThrottler<Dispatch<StateUpdater<TValue>>, TSelected>];
|
|
89
|
+
//#endregion
|
|
@@ -78,7 +78,5 @@ import { ThrottlerState } from "@tanstack/pacer/throttler";
|
|
|
78
78
|
* const { executionCount, isPending } = throttler.state;
|
|
79
79
|
* ```
|
|
80
80
|
*/
|
|
81
|
-
declare function useThrottledValue<TValue, TSelected = ThrottlerState<Dispatch<StateUpdater<TValue>>>>(value: TValue, options: PreactThrottlerOptions<Dispatch<StateUpdater<TValue>>, TSelected>, selector?: (state: ThrottlerState<Dispatch<StateUpdater<TValue>>>) => TSelected): [TValue, PreactThrottler<Dispatch<StateUpdater<TValue>>, TSelected>];
|
|
82
|
-
//#endregion
|
|
83
|
-
export { useThrottledValue };
|
|
84
|
-
//# sourceMappingURL=useThrottledValue.d.ts.map
|
|
81
|
+
export declare function useThrottledValue<TValue, TSelected = ThrottlerState<Dispatch<StateUpdater<TValue>>>>(value: TValue, options: PreactThrottlerOptions<Dispatch<StateUpdater<TValue>>, TSelected>, selector?: (state: ThrottlerState<Dispatch<StateUpdater<TValue>>>) => TSelected): [TValue, PreactThrottler<Dispatch<StateUpdater<TValue>>, TSelected>];
|
|
82
|
+
//#endregion
|
|
@@ -3,14 +3,14 @@ import { Store } from "@tanstack/preact-store";
|
|
|
3
3
|
import { Throttler, ThrottlerOptions, ThrottlerState } from "@tanstack/pacer/throttler";
|
|
4
4
|
import { AnyFunction } from "@tanstack/pacer/types";
|
|
5
5
|
//#region src/throttler/useThrottler.d.ts
|
|
6
|
-
interface PreactThrottlerOptions<TFn extends AnyFunction, TSelected = {}> extends ThrottlerOptions<TFn> {
|
|
6
|
+
export interface PreactThrottlerOptions<TFn extends AnyFunction, TSelected = {}> extends ThrottlerOptions<TFn> {
|
|
7
7
|
/**
|
|
8
8
|
* Optional callback invoked when the component unmounts. Receives the throttler instance.
|
|
9
9
|
* When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.
|
|
10
10
|
*/
|
|
11
11
|
onUnmount?: (throttler: PreactThrottler<TFn, TSelected>) => void;
|
|
12
12
|
}
|
|
13
|
-
interface PreactThrottler<TFn extends AnyFunction, TSelected = {}> extends Omit<Throttler<TFn>, 'store'> {
|
|
13
|
+
export interface PreactThrottler<TFn extends AnyFunction, TSelected = {}> extends Omit<Throttler<TFn>, 'store'> {
|
|
14
14
|
/**
|
|
15
15
|
* A Preact HOC (Higher Order Component) that allows you to subscribe to the throttler state.
|
|
16
16
|
*
|
|
@@ -150,7 +150,5 @@ interface PreactThrottler<TFn extends AnyFunction, TSelected = {}> extends Omit<
|
|
|
150
150
|
* const { executionCount, isPending } = throttler.state;
|
|
151
151
|
* ```
|
|
152
152
|
*/
|
|
153
|
-
declare function useThrottler<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: PreactThrottlerOptions<TFn, TSelected>, selector?: (state: ThrottlerState<TFn>) => TSelected): PreactThrottler<TFn, TSelected>;
|
|
154
|
-
//#endregion
|
|
155
|
-
export { PreactThrottler, PreactThrottlerOptions, useThrottler };
|
|
156
|
-
//# sourceMappingURL=useThrottler.d.ts.map
|
|
153
|
+
export declare function useThrottler<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: PreactThrottlerOptions<TFn, TSelected>, selector?: (state: ThrottlerState<TFn>) => TSelected): PreactThrottler<TFn, TSelected>;
|
|
154
|
+
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/preact-pacer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "Utilities for debouncing and throttling functions in Preact.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,83 +23,35 @@
|
|
|
23
23
|
"async"
|
|
24
24
|
],
|
|
25
25
|
"type": "module",
|
|
26
|
-
"types": "./dist/index.d.
|
|
27
|
-
"main": "./dist/index.cjs",
|
|
28
|
-
"module": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
29
27
|
"exports": {
|
|
30
|
-
".":
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"./async-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"./
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"./
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
},
|
|
46
|
-
"./async-rate-limiter": {
|
|
47
|
-
"import": "./dist/async-rate-limiter/index.js",
|
|
48
|
-
"require": "./dist/async-rate-limiter/index.cjs"
|
|
49
|
-
},
|
|
50
|
-
"./async-retryer": {
|
|
51
|
-
"import": "./dist/async-retryer/index.js",
|
|
52
|
-
"require": "./dist/async-retryer/index.cjs"
|
|
53
|
-
},
|
|
54
|
-
"./async-throttler": {
|
|
55
|
-
"import": "./dist/async-throttler/index.js",
|
|
56
|
-
"require": "./dist/async-throttler/index.cjs"
|
|
57
|
-
},
|
|
58
|
-
"./batcher": {
|
|
59
|
-
"import": "./dist/batcher/index.js",
|
|
60
|
-
"require": "./dist/batcher/index.cjs"
|
|
61
|
-
},
|
|
62
|
-
"./debouncer": {
|
|
63
|
-
"import": "./dist/debouncer/index.js",
|
|
64
|
-
"require": "./dist/debouncer/index.cjs"
|
|
65
|
-
},
|
|
66
|
-
"./provider": {
|
|
67
|
-
"import": "./dist/provider/index.js",
|
|
68
|
-
"require": "./dist/provider/index.cjs"
|
|
69
|
-
},
|
|
70
|
-
"./queuer": {
|
|
71
|
-
"import": "./dist/queuer/index.js",
|
|
72
|
-
"require": "./dist/queuer/index.cjs"
|
|
73
|
-
},
|
|
74
|
-
"./rate-limiter": {
|
|
75
|
-
"import": "./dist/rate-limiter/index.js",
|
|
76
|
-
"require": "./dist/rate-limiter/index.cjs"
|
|
77
|
-
},
|
|
78
|
-
"./throttler": {
|
|
79
|
-
"import": "./dist/throttler/index.js",
|
|
80
|
-
"require": "./dist/throttler/index.cjs"
|
|
81
|
-
},
|
|
82
|
-
"./types": {
|
|
83
|
-
"import": "./dist/types/index.js",
|
|
84
|
-
"require": "./dist/types/index.cjs"
|
|
85
|
-
},
|
|
86
|
-
"./utils": {
|
|
87
|
-
"import": "./dist/utils/index.js",
|
|
88
|
-
"require": "./dist/utils/index.cjs"
|
|
89
|
-
},
|
|
28
|
+
".": "./dist/index.js",
|
|
29
|
+
"./async-batcher": "./dist/async-batcher/index.js",
|
|
30
|
+
"./async-debouncer": "./dist/async-debouncer/index.js",
|
|
31
|
+
"./async-queuer": "./dist/async-queuer/index.js",
|
|
32
|
+
"./async-rate-limiter": "./dist/async-rate-limiter/index.js",
|
|
33
|
+
"./async-retryer": "./dist/async-retryer/index.js",
|
|
34
|
+
"./async-throttler": "./dist/async-throttler/index.js",
|
|
35
|
+
"./batcher": "./dist/batcher/index.js",
|
|
36
|
+
"./debouncer": "./dist/debouncer/index.js",
|
|
37
|
+
"./provider": "./dist/provider/index.js",
|
|
38
|
+
"./queuer": "./dist/queuer/index.js",
|
|
39
|
+
"./rate-limiter": "./dist/rate-limiter/index.js",
|
|
40
|
+
"./throttler": "./dist/throttler/index.js",
|
|
41
|
+
"./types": "./dist/types/index.js",
|
|
42
|
+
"./utils": "./dist/utils/index.js",
|
|
90
43
|
"./package.json": "./package.json"
|
|
91
44
|
},
|
|
92
45
|
"sideEffects": false,
|
|
93
46
|
"engines": {
|
|
94
|
-
"node": ">=
|
|
47
|
+
"node": ">=20"
|
|
95
48
|
},
|
|
96
49
|
"files": [
|
|
97
|
-
"dist"
|
|
98
|
-
"src"
|
|
50
|
+
"dist"
|
|
99
51
|
],
|
|
100
52
|
"dependencies": {
|
|
101
|
-
"@tanstack/
|
|
102
|
-
"@tanstack/
|
|
53
|
+
"@tanstack/pacer": "0.23.0",
|
|
54
|
+
"@tanstack/preact-store": "^0.13.3"
|
|
103
55
|
},
|
|
104
56
|
"devDependencies": {
|
|
105
57
|
"@preact/preset-vite": "^2.10.6",
|
|
@@ -116,7 +68,7 @@
|
|
|
116
68
|
"test:lib": "vitest --passWithNoTests",
|
|
117
69
|
"test:lib:dev": "pnpm test:lib --watch",
|
|
118
70
|
"test:types": "tsc",
|
|
119
|
-
"test:build": "publint --strict",
|
|
71
|
+
"test:build": "publint --strict && node ../../scripts/verify-package.ts",
|
|
120
72
|
"build": "tsdown"
|
|
121
73
|
}
|
|
122
74
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_useAsyncBatcher = require('./useAsyncBatcher.cjs');
|
|
3
|
-
const require_useAsyncBatchedCallback = require('./useAsyncBatchedCallback.cjs');
|
|
4
|
-
|
|
5
|
-
exports.useAsyncBatchedCallback = require_useAsyncBatchedCallback.useAsyncBatchedCallback;
|
|
6
|
-
exports.useAsyncBatcher = require_useAsyncBatcher.useAsyncBatcher;
|
|
7
|
-
var _tanstack_pacer_async_batcher = require("@tanstack/pacer/async-batcher");
|
|
8
|
-
Object.keys(_tanstack_pacer_async_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_async_batcher[k]; }
|
|
12
|
-
});
|
|
13
|
-
});
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { PreactAsyncBatcher, PreactAsyncBatcherOptions, useAsyncBatcher } from "./useAsyncBatcher.cjs";
|
|
2
|
-
import { useAsyncBatchedCallback } from "./useAsyncBatchedCallback.cjs";
|
|
3
|
-
export * from "@tanstack/pacer/async-batcher";
|
|
4
|
-
export { PreactAsyncBatcher, PreactAsyncBatcherOptions, useAsyncBatchedCallback, useAsyncBatcher };
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const require_useAsyncBatcher = require('./useAsyncBatcher.cjs');
|
|
2
|
-
let preact_hooks = require("preact/hooks");
|
|
3
|
-
|
|
4
|
-
//#region src/async-batcher/useAsyncBatchedCallback.ts
|
|
5
|
-
/**
|
|
6
|
-
* A Preact hook that creates a batched version of an async callback function.
|
|
7
|
-
* This hook is a convenient wrapper around the `useAsyncBatcher` hook,
|
|
8
|
-
* providing a stable, batched async function reference for use in Preact components.
|
|
9
|
-
*
|
|
10
|
-
* The batched async function will collect individual calls into batches and execute them
|
|
11
|
-
* when batch conditions are met (max size reached, wait time elapsed, or custom logic).
|
|
12
|
-
* The returned function always returns a promise that resolves with undefined (since the
|
|
13
|
-
* batch function processes multiple items together).
|
|
14
|
-
*
|
|
15
|
-
* This hook provides a simpler API compared to `useAsyncBatcher`, making it ideal for basic
|
|
16
|
-
* async batching needs. However, it does not expose the underlying AsyncBatcher instance.
|
|
17
|
-
*
|
|
18
|
-
* For advanced usage requiring features like:
|
|
19
|
-
* - Manual batch execution
|
|
20
|
-
* - Access to batch results and state
|
|
21
|
-
* - Custom useCallback dependencies
|
|
22
|
-
*
|
|
23
|
-
* Consider using the `useAsyncBatcher` hook instead.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```tsx
|
|
27
|
-
* // Batch API requests
|
|
28
|
-
* const batchApiCall = useAsyncBatchedCallback(async (requests: ApiRequest[]) => {
|
|
29
|
-
* const results = await Promise.all(requests.map(req => fetch(req.url)));
|
|
30
|
-
* return results.map(res => res.json());
|
|
31
|
-
* }, {
|
|
32
|
-
* maxSize: 10, // Process when 10 requests collected
|
|
33
|
-
* wait: 1000 // Or after 1 second
|
|
34
|
-
* });
|
|
35
|
-
*
|
|
36
|
-
* // Use in event handlers
|
|
37
|
-
* <button onClick={() => batchApiCall({ url: '/api/analytics', data: eventData })}>
|
|
38
|
-
* Track Event
|
|
39
|
-
* </button>
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
function useAsyncBatchedCallback(fn, options) {
|
|
43
|
-
const asyncBatchedFn = require_useAsyncBatcher.useAsyncBatcher(fn, options).addItem;
|
|
44
|
-
return (0, preact_hooks.useCallback)(async (item) => {
|
|
45
|
-
await asyncBatchedFn(item);
|
|
46
|
-
}, [asyncBatchedFn]);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
//#endregion
|
|
50
|
-
exports.useAsyncBatchedCallback = useAsyncBatchedCallback;
|
|
51
|
-
//# sourceMappingURL=useAsyncBatchedCallback.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useAsyncBatchedCallback.cjs","names":["useAsyncBatcher","useCallback"],"sources":["../../src/async-batcher/useAsyncBatchedCallback.ts"],"sourcesContent":["import { useCallback } from 'preact/hooks'\nimport { useAsyncBatcher } from './useAsyncBatcher'\nimport type { PreactAsyncBatcherOptions } from './useAsyncBatcher'\n\n/**\n * A Preact hook that creates a batched version of an async callback function.\n * This hook is a convenient wrapper around the `useAsyncBatcher` hook,\n * providing a stable, batched async function reference for use in Preact components.\n *\n * The batched async function will collect individual calls into batches and execute them\n * when batch conditions are met (max size reached, wait time elapsed, or custom logic).\n * The returned function always returns a promise that resolves with undefined (since the\n * batch function processes multiple items together).\n *\n * This hook provides a simpler API compared to `useAsyncBatcher`, making it ideal for basic\n * async batching needs. However, it does not expose the underlying AsyncBatcher instance.\n *\n * For advanced usage requiring features like:\n * - Manual batch execution\n * - Access to batch results and state\n * - Custom useCallback dependencies\n *\n * Consider using the `useAsyncBatcher` hook instead.\n *\n * @example\n * ```tsx\n * // Batch API requests\n * const batchApiCall = useAsyncBatchedCallback(async (requests: ApiRequest[]) => {\n * const results = await Promise.all(requests.map(req => fetch(req.url)));\n * return results.map(res => res.json());\n * }, {\n * maxSize: 10, // Process when 10 requests collected\n * wait: 1000 // Or after 1 second\n * });\n *\n * // Use in event handlers\n * <button onClick={() => batchApiCall({ url: '/api/analytics', data: eventData })}>\n * Track Event\n * </button>\n * ```\n */\nexport function useAsyncBatchedCallback<TValue>(\n fn: (items: Array<TValue>) => Promise<unknown>,\n options: PreactAsyncBatcherOptions<TValue, {}>,\n): (item: TValue) => Promise<void> {\n const asyncBatchedFn = useAsyncBatcher(fn, options).addItem\n return useCallback(\n async (item: TValue) => {\n await asyncBatchedFn(item)\n },\n [asyncBatchedFn],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,wBACd,IACA,SACiC;CACjC,MAAM,iBAAiBA,wCAAgB,IAAI,OAAO,CAAC,CAAC;CACpD,WAAOC,0BACL,OAAO,SAAiB;EACtB,MAAM,eAAe,IAAI;CAC3B,GACA,CAAC,cAAc,CACjB;AACF"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { PreactAsyncBatcherOptions } from "./useAsyncBatcher.cjs";
|
|
2
|
-
//#region src/async-batcher/useAsyncBatchedCallback.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* A Preact hook that creates a batched version of an async callback function.
|
|
5
|
-
* This hook is a convenient wrapper around the `useAsyncBatcher` hook,
|
|
6
|
-
* providing a stable, batched async function reference for use in Preact components.
|
|
7
|
-
*
|
|
8
|
-
* The batched async function will collect individual calls into batches and execute them
|
|
9
|
-
* when batch conditions are met (max size reached, wait time elapsed, or custom logic).
|
|
10
|
-
* The returned function always returns a promise that resolves with undefined (since the
|
|
11
|
-
* batch function processes multiple items together).
|
|
12
|
-
*
|
|
13
|
-
* This hook provides a simpler API compared to `useAsyncBatcher`, making it ideal for basic
|
|
14
|
-
* async batching needs. However, it does not expose the underlying AsyncBatcher instance.
|
|
15
|
-
*
|
|
16
|
-
* For advanced usage requiring features like:
|
|
17
|
-
* - Manual batch execution
|
|
18
|
-
* - Access to batch results and state
|
|
19
|
-
* - Custom useCallback dependencies
|
|
20
|
-
*
|
|
21
|
-
* Consider using the `useAsyncBatcher` hook instead.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```tsx
|
|
25
|
-
* // Batch API requests
|
|
26
|
-
* const batchApiCall = useAsyncBatchedCallback(async (requests: ApiRequest[]) => {
|
|
27
|
-
* const results = await Promise.all(requests.map(req => fetch(req.url)));
|
|
28
|
-
* return results.map(res => res.json());
|
|
29
|
-
* }, {
|
|
30
|
-
* maxSize: 10, // Process when 10 requests collected
|
|
31
|
-
* wait: 1000 // Or after 1 second
|
|
32
|
-
* });
|
|
33
|
-
*
|
|
34
|
-
* // Use in event handlers
|
|
35
|
-
* <button onClick={() => batchApiCall({ url: '/api/analytics', data: eventData })}>
|
|
36
|
-
* Track Event
|
|
37
|
-
* </button>
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
declare function useAsyncBatchedCallback<TValue>(fn: (items: Array<TValue>) => Promise<unknown>, options: PreactAsyncBatcherOptions<TValue, {}>): (item: TValue) => Promise<void>;
|
|
41
|
-
//#endregion
|
|
42
|
-
export { useAsyncBatchedCallback };
|
|
43
|
-
//# sourceMappingURL=useAsyncBatchedCallback.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useAsyncBatchedCallback.js","names":[],"sources":["../../src/async-batcher/useAsyncBatchedCallback.ts"],"sourcesContent":["import { useCallback } from 'preact/hooks'\nimport { useAsyncBatcher } from './useAsyncBatcher'\nimport type { PreactAsyncBatcherOptions } from './useAsyncBatcher'\n\n/**\n * A Preact hook that creates a batched version of an async callback function.\n * This hook is a convenient wrapper around the `useAsyncBatcher` hook,\n * providing a stable, batched async function reference for use in Preact components.\n *\n * The batched async function will collect individual calls into batches and execute them\n * when batch conditions are met (max size reached, wait time elapsed, or custom logic).\n * The returned function always returns a promise that resolves with undefined (since the\n * batch function processes multiple items together).\n *\n * This hook provides a simpler API compared to `useAsyncBatcher`, making it ideal for basic\n * async batching needs. However, it does not expose the underlying AsyncBatcher instance.\n *\n * For advanced usage requiring features like:\n * - Manual batch execution\n * - Access to batch results and state\n * - Custom useCallback dependencies\n *\n * Consider using the `useAsyncBatcher` hook instead.\n *\n * @example\n * ```tsx\n * // Batch API requests\n * const batchApiCall = useAsyncBatchedCallback(async (requests: ApiRequest[]) => {\n * const results = await Promise.all(requests.map(req => fetch(req.url)));\n * return results.map(res => res.json());\n * }, {\n * maxSize: 10, // Process when 10 requests collected\n * wait: 1000 // Or after 1 second\n * });\n *\n * // Use in event handlers\n * <button onClick={() => batchApiCall({ url: '/api/analytics', data: eventData })}>\n * Track Event\n * </button>\n * ```\n */\nexport function useAsyncBatchedCallback<TValue>(\n fn: (items: Array<TValue>) => Promise<unknown>,\n options: PreactAsyncBatcherOptions<TValue, {}>,\n): (item: TValue) => Promise<void> {\n const asyncBatchedFn = useAsyncBatcher(fn, options).addItem\n return useCallback(\n async (item: TValue) => {\n await asyncBatchedFn(item)\n },\n [asyncBatchedFn],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,wBACd,IACA,SACiC;CACjC,MAAM,iBAAiB,gBAAgB,IAAI,OAAO,CAAC,CAAC;CACpD,OAAO,YACL,OAAO,SAAiB;EACtB,MAAM,eAAe,IAAI;CAC3B,GACA,CAAC,cAAc,CACjB;AACF"}
|