@tanstack/solid-pacer 0.15.3 → 0.16.1
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/createAsyncBatcher.cjs +122 -0
- package/dist/async-batcher/createAsyncBatcher.cjs.map +1 -0
- package/dist/{cjs/async-batcher → async-batcher}/createAsyncBatcher.d.cts +22 -17
- package/dist/{esm/async-batcher → async-batcher}/createAsyncBatcher.d.ts +22 -17
- package/dist/async-batcher/createAsyncBatcher.js +122 -0
- package/dist/async-batcher/createAsyncBatcher.js.map +1 -0
- package/dist/async-batcher/index.cjs +10 -0
- package/dist/async-batcher/index.d.cts +3 -0
- package/dist/async-batcher/index.d.ts +3 -0
- package/dist/async-batcher/index.js +5 -0
- package/dist/async-debouncer/createAsyncDebouncer.cjs +114 -0
- package/dist/async-debouncer/createAsyncDebouncer.cjs.map +1 -0
- package/dist/{cjs/async-debouncer → async-debouncer}/createAsyncDebouncer.d.cts +23 -18
- package/dist/{esm/async-debouncer → async-debouncer}/createAsyncDebouncer.d.ts +23 -18
- package/dist/async-debouncer/createAsyncDebouncer.js +114 -0
- package/dist/async-debouncer/createAsyncDebouncer.js.map +1 -0
- package/dist/async-debouncer/index.cjs +10 -0
- package/dist/async-debouncer/index.d.cts +3 -0
- package/dist/async-debouncer/index.d.ts +3 -0
- package/dist/async-debouncer/index.js +5 -0
- package/dist/async-queuer/createAsyncQueuer.cjs +114 -0
- package/dist/async-queuer/createAsyncQueuer.cjs.map +1 -0
- package/dist/{cjs/async-queuer → async-queuer}/createAsyncQueuer.d.cts +22 -17
- package/dist/{esm/async-queuer → async-queuer}/createAsyncQueuer.d.ts +22 -17
- package/dist/async-queuer/createAsyncQueuer.js +114 -0
- package/dist/async-queuer/createAsyncQueuer.js.map +1 -0
- package/dist/async-queuer/index.cjs +10 -0
- package/dist/async-queuer/index.d.cts +3 -0
- package/dist/async-queuer/index.d.ts +3 -0
- package/dist/async-queuer/index.js +5 -0
- package/dist/async-rate-limiter/createAsyncRateLimiter.cjs +120 -0
- package/dist/async-rate-limiter/createAsyncRateLimiter.cjs.map +1 -0
- package/dist/{cjs/async-rate-limiter → async-rate-limiter}/createAsyncRateLimiter.d.cts +23 -18
- package/dist/{esm/async-rate-limiter → async-rate-limiter}/createAsyncRateLimiter.d.ts +23 -18
- package/dist/async-rate-limiter/createAsyncRateLimiter.js +120 -0
- package/dist/async-rate-limiter/createAsyncRateLimiter.js.map +1 -0
- package/dist/async-rate-limiter/index.cjs +10 -0
- package/dist/async-rate-limiter/index.d.cts +3 -0
- package/dist/async-rate-limiter/index.d.ts +3 -0
- package/dist/async-rate-limiter/index.js +5 -0
- package/dist/async-throttler/createAsyncThrottler.cjs +108 -0
- package/dist/async-throttler/createAsyncThrottler.cjs.map +1 -0
- package/dist/{cjs/async-throttler → async-throttler}/createAsyncThrottler.d.cts +23 -18
- package/dist/{esm/async-throttler → async-throttler}/createAsyncThrottler.d.ts +23 -18
- package/dist/async-throttler/createAsyncThrottler.js +108 -0
- package/dist/async-throttler/createAsyncThrottler.js.map +1 -0
- package/dist/async-throttler/index.cjs +10 -0
- package/dist/async-throttler/index.d.cts +3 -0
- package/dist/async-throttler/index.d.ts +3 -0
- package/dist/async-throttler/index.js +5 -0
- package/dist/batcher/createBatcher.cjs +97 -0
- package/dist/batcher/createBatcher.cjs.map +1 -0
- package/dist/{cjs/batcher → batcher}/createBatcher.d.cts +22 -17
- package/dist/{esm/batcher → batcher}/createBatcher.d.ts +22 -17
- package/dist/batcher/createBatcher.js +97 -0
- package/dist/batcher/createBatcher.js.map +1 -0
- package/dist/batcher/index.cjs +10 -0
- package/dist/batcher/index.d.cts +3 -0
- package/dist/batcher/index.d.ts +3 -0
- package/dist/batcher/index.js +5 -0
- package/dist/debouncer/createDebouncedSignal.cjs +88 -0
- package/dist/debouncer/createDebouncedSignal.cjs.map +1 -0
- package/dist/{cjs/debouncer → debouncer}/createDebouncedSignal.d.cts +10 -8
- package/dist/{esm/debouncer → debouncer}/createDebouncedSignal.d.ts +10 -8
- package/dist/debouncer/createDebouncedSignal.js +88 -0
- package/dist/debouncer/createDebouncedSignal.js.map +1 -0
- package/dist/debouncer/createDebouncedValue.cjs +77 -0
- package/dist/debouncer/createDebouncedValue.cjs.map +1 -0
- package/dist/{cjs/debouncer → debouncer}/createDebouncedValue.d.cts +10 -4
- package/dist/{esm/debouncer → debouncer}/createDebouncedValue.d.ts +10 -4
- package/dist/debouncer/createDebouncedValue.js +77 -0
- package/dist/debouncer/createDebouncedValue.js.map +1 -0
- package/dist/debouncer/createDebouncer.cjs +101 -0
- package/dist/debouncer/createDebouncer.cjs.map +1 -0
- package/dist/{cjs/debouncer → debouncer}/createDebouncer.d.cts +23 -18
- package/dist/{esm/debouncer → debouncer}/createDebouncer.d.ts +23 -18
- package/dist/debouncer/createDebouncer.js +101 -0
- package/dist/debouncer/createDebouncer.js.map +1 -0
- package/dist/debouncer/index.cjs +14 -0
- package/dist/debouncer/index.d.cts +5 -0
- package/dist/debouncer/index.d.ts +5 -0
- package/dist/{esm/debouncer → debouncer}/index.js +5 -8
- package/dist/index.cjs +46 -0
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/{esm/index.js → index.js} +8 -22
- package/dist/provider/PacerProvider.cjs +27 -0
- package/dist/provider/PacerProvider.cjs.map +1 -0
- package/dist/provider/PacerProvider.d.cts +29 -0
- package/dist/provider/PacerProvider.d.ts +29 -0
- package/dist/provider/PacerProvider.js +25 -0
- package/dist/provider/PacerProvider.js.map +1 -0
- package/dist/provider/index.cjs +5 -0
- package/dist/provider/index.d.cts +2 -0
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.js +3 -0
- package/dist/queuer/createQueuedSignal.cjs +129 -0
- package/dist/queuer/createQueuedSignal.cjs.map +1 -0
- package/dist/queuer/createQueuedSignal.d.cts +123 -0
- package/dist/queuer/createQueuedSignal.d.ts +123 -0
- package/dist/queuer/createQueuedSignal.js +129 -0
- package/dist/queuer/createQueuedSignal.js.map +1 -0
- package/dist/queuer/createQueuer.cjs +98 -0
- package/dist/queuer/createQueuer.cjs.map +1 -0
- package/dist/{cjs/queuer → queuer}/createQueuer.d.cts +22 -17
- package/dist/{esm/queuer → queuer}/createQueuer.d.ts +22 -17
- package/dist/queuer/createQueuer.js +98 -0
- package/dist/queuer/createQueuer.js.map +1 -0
- package/dist/queuer/index.cjs +12 -0
- package/dist/queuer/index.d.cts +4 -0
- package/dist/queuer/index.d.ts +4 -0
- package/dist/queuer/index.js +6 -0
- package/dist/rate-limiter/createRateLimitedSignal.cjs +102 -0
- package/dist/rate-limiter/createRateLimitedSignal.cjs.map +1 -0
- package/dist/{cjs/rate-limiter → rate-limiter}/createRateLimitedSignal.d.cts +10 -8
- package/dist/{esm/rate-limiter → rate-limiter}/createRateLimitedSignal.d.ts +10 -8
- package/dist/rate-limiter/createRateLimitedSignal.js +102 -0
- package/dist/rate-limiter/createRateLimitedSignal.js.map +1 -0
- package/dist/rate-limiter/createRateLimitedValue.cjs +102 -0
- package/dist/rate-limiter/createRateLimitedValue.cjs.map +1 -0
- package/dist/{cjs/rate-limiter → rate-limiter}/createRateLimitedValue.d.cts +40 -20
- package/dist/{esm/rate-limiter → rate-limiter}/createRateLimitedValue.d.ts +40 -20
- package/dist/rate-limiter/createRateLimitedValue.js +102 -0
- package/dist/rate-limiter/createRateLimitedValue.js.map +1 -0
- package/dist/rate-limiter/createRateLimiter.cjs +95 -0
- package/dist/rate-limiter/createRateLimiter.cjs.map +1 -0
- package/dist/{cjs/rate-limiter → rate-limiter}/createRateLimiter.d.cts +23 -18
- package/dist/{esm/rate-limiter → rate-limiter}/createRateLimiter.d.ts +23 -18
- package/dist/rate-limiter/createRateLimiter.js +95 -0
- package/dist/rate-limiter/createRateLimiter.js.map +1 -0
- package/dist/rate-limiter/index.cjs +14 -0
- package/dist/rate-limiter/index.d.cts +5 -0
- package/dist/rate-limiter/index.d.ts +5 -0
- package/dist/{esm/rate-limiter → rate-limiter}/index.js +4 -7
- package/dist/throttler/createThrottledSignal.cjs +79 -0
- package/dist/throttler/createThrottledSignal.cjs.map +1 -0
- package/dist/{cjs/throttler → throttler}/createThrottledSignal.d.cts +10 -8
- package/dist/{esm/throttler → throttler}/createThrottledSignal.d.ts +10 -8
- package/dist/throttler/createThrottledSignal.js +79 -0
- package/dist/throttler/createThrottledSignal.js.map +1 -0
- package/dist/throttler/createThrottledValue.cjs +74 -0
- package/dist/throttler/createThrottledValue.cjs.map +1 -0
- package/dist/{cjs/throttler → throttler}/createThrottledValue.d.cts +10 -4
- package/dist/{esm/throttler → throttler}/createThrottledValue.d.ts +10 -4
- package/dist/throttler/createThrottledValue.js +74 -0
- package/dist/throttler/createThrottledValue.js.map +1 -0
- package/dist/throttler/createThrottler.cjs +97 -0
- package/dist/throttler/createThrottler.cjs.map +1 -0
- package/dist/{cjs/throttler → throttler}/createThrottler.d.cts +23 -18
- package/dist/{esm/throttler → throttler}/createThrottler.d.ts +23 -18
- package/dist/throttler/createThrottler.js +97 -0
- package/dist/throttler/createThrottler.js.map +1 -0
- package/dist/throttler/index.cjs +14 -0
- package/dist/throttler/index.d.cts +5 -0
- package/dist/throttler/index.d.ts +5 -0
- package/dist/{esm/throttler → throttler}/index.js +5 -8
- 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 +37 -106
- package/src/async-batcher/createAsyncBatcher.ts +12 -4
- package/src/async-debouncer/createAsyncDebouncer.ts +8 -2
- package/src/async-queuer/createAsyncQueuer.ts +12 -4
- package/src/async-rate-limiter/createAsyncRateLimiter.ts +8 -2
- package/src/async-throttler/createAsyncThrottler.ts +8 -2
- package/src/batcher/createBatcher.ts +12 -4
- package/src/debouncer/createDebouncer.ts +12 -4
- package/src/index.ts +4 -0
- package/src/provider/PacerProvider.tsx +63 -0
- package/src/provider/index.ts +1 -0
- package/src/queuer/createQueuedSignal.ts +138 -0
- package/src/queuer/createQueuer.ts +12 -4
- package/src/queuer/index.ts +1 -0
- package/src/rate-limiter/createRateLimitedValue.ts +30 -16
- package/src/rate-limiter/createRateLimiter.ts +12 -4
- package/src/throttler/createThrottler.ts +12 -4
- package/dist/cjs/async-batcher/createAsyncBatcher.cjs +0 -14
- package/dist/cjs/async-batcher/createAsyncBatcher.cjs.map +0 -1
- package/dist/cjs/async-batcher/index.cjs +0 -12
- package/dist/cjs/async-batcher/index.cjs.map +0 -1
- package/dist/cjs/async-batcher/index.d.cts +0 -2
- package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs +0 -20
- package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs.map +0 -1
- package/dist/cjs/async-debouncer/index.cjs +0 -12
- package/dist/cjs/async-debouncer/index.cjs.map +0 -1
- package/dist/cjs/async-debouncer/index.d.cts +0 -2
- package/dist/cjs/async-queuer/createAsyncQueuer.cjs +0 -14
- package/dist/cjs/async-queuer/createAsyncQueuer.cjs.map +0 -1
- package/dist/cjs/async-queuer/index.cjs +0 -12
- package/dist/cjs/async-queuer/index.cjs.map +0 -1
- package/dist/cjs/async-queuer/index.d.cts +0 -2
- package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs +0 -14
- package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs.map +0 -1
- package/dist/cjs/async-rate-limiter/index.cjs +0 -12
- package/dist/cjs/async-rate-limiter/index.cjs.map +0 -1
- package/dist/cjs/async-rate-limiter/index.d.cts +0 -2
- package/dist/cjs/async-throttler/createAsyncThrottler.cjs +0 -14
- package/dist/cjs/async-throttler/createAsyncThrottler.cjs.map +0 -1
- package/dist/cjs/async-throttler/index.cjs +0 -12
- package/dist/cjs/async-throttler/index.cjs.map +0 -1
- package/dist/cjs/async-throttler/index.d.cts +0 -2
- package/dist/cjs/batcher/createBatcher.cjs +0 -14
- package/dist/cjs/batcher/createBatcher.cjs.map +0 -1
- package/dist/cjs/batcher/index.cjs +0 -12
- package/dist/cjs/batcher/index.cjs.map +0 -1
- package/dist/cjs/batcher/index.d.cts +0 -2
- package/dist/cjs/debouncer/createDebouncedSignal.cjs +0 -11
- package/dist/cjs/debouncer/createDebouncedSignal.cjs.map +0 -1
- package/dist/cjs/debouncer/createDebouncedValue.cjs +0 -17
- package/dist/cjs/debouncer/createDebouncedValue.cjs.map +0 -1
- package/dist/cjs/debouncer/createDebouncer.cjs +0 -20
- package/dist/cjs/debouncer/createDebouncer.cjs.map +0 -1
- package/dist/cjs/debouncer/index.cjs +0 -16
- package/dist/cjs/debouncer/index.cjs.map +0 -1
- package/dist/cjs/debouncer/index.d.cts +0 -4
- package/dist/cjs/index.cjs +0 -42
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/index.d.cts +0 -20
- package/dist/cjs/queuer/createQueuer.cjs +0 -14
- package/dist/cjs/queuer/createQueuer.cjs.map +0 -1
- package/dist/cjs/queuer/index.cjs +0 -12
- package/dist/cjs/queuer/index.cjs.map +0 -1
- package/dist/cjs/queuer/index.d.cts +0 -2
- package/dist/cjs/rate-limiter/createRateLimitedSignal.cjs +0 -19
- package/dist/cjs/rate-limiter/createRateLimitedSignal.cjs.map +0 -1
- package/dist/cjs/rate-limiter/createRateLimitedValue.cjs +0 -13
- package/dist/cjs/rate-limiter/createRateLimitedValue.cjs.map +0 -1
- package/dist/cjs/rate-limiter/createRateLimiter.cjs +0 -14
- package/dist/cjs/rate-limiter/createRateLimiter.cjs.map +0 -1
- package/dist/cjs/rate-limiter/index.cjs +0 -16
- package/dist/cjs/rate-limiter/index.cjs.map +0 -1
- package/dist/cjs/rate-limiter/index.d.cts +0 -4
- package/dist/cjs/throttler/createThrottledSignal.cjs +0 -11
- package/dist/cjs/throttler/createThrottledSignal.cjs.map +0 -1
- package/dist/cjs/throttler/createThrottledValue.cjs +0 -17
- package/dist/cjs/throttler/createThrottledValue.cjs.map +0 -1
- package/dist/cjs/throttler/createThrottler.cjs +0 -20
- package/dist/cjs/throttler/createThrottler.cjs.map +0 -1
- package/dist/cjs/throttler/index.cjs +0 -16
- package/dist/cjs/throttler/index.cjs.map +0 -1
- package/dist/cjs/throttler/index.d.cts +0 -4
- package/dist/cjs/types/index.cjs +0 -10
- package/dist/cjs/types/index.cjs.map +0 -1
- package/dist/cjs/types/index.d.cts +0 -1
- package/dist/cjs/utils/index.cjs +0 -10
- package/dist/cjs/utils/index.cjs.map +0 -1
- package/dist/cjs/utils/index.d.cts +0 -1
- package/dist/esm/async-batcher/createAsyncBatcher.js +0 -14
- package/dist/esm/async-batcher/createAsyncBatcher.js.map +0 -1
- package/dist/esm/async-batcher/index.d.ts +0 -2
- package/dist/esm/async-batcher/index.js +0 -6
- package/dist/esm/async-batcher/index.js.map +0 -1
- package/dist/esm/async-debouncer/createAsyncDebouncer.js +0 -20
- package/dist/esm/async-debouncer/createAsyncDebouncer.js.map +0 -1
- package/dist/esm/async-debouncer/index.d.ts +0 -2
- package/dist/esm/async-debouncer/index.js +0 -6
- package/dist/esm/async-debouncer/index.js.map +0 -1
- package/dist/esm/async-queuer/createAsyncQueuer.js +0 -14
- package/dist/esm/async-queuer/createAsyncQueuer.js.map +0 -1
- package/dist/esm/async-queuer/index.d.ts +0 -2
- package/dist/esm/async-queuer/index.js +0 -6
- package/dist/esm/async-queuer/index.js.map +0 -1
- package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js +0 -14
- package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js.map +0 -1
- package/dist/esm/async-rate-limiter/index.d.ts +0 -2
- package/dist/esm/async-rate-limiter/index.js +0 -6
- package/dist/esm/async-rate-limiter/index.js.map +0 -1
- package/dist/esm/async-throttler/createAsyncThrottler.js +0 -14
- package/dist/esm/async-throttler/createAsyncThrottler.js.map +0 -1
- package/dist/esm/async-throttler/index.d.ts +0 -2
- package/dist/esm/async-throttler/index.js +0 -6
- package/dist/esm/async-throttler/index.js.map +0 -1
- package/dist/esm/batcher/createBatcher.js +0 -14
- package/dist/esm/batcher/createBatcher.js.map +0 -1
- package/dist/esm/batcher/index.d.ts +0 -2
- package/dist/esm/batcher/index.js +0 -6
- package/dist/esm/batcher/index.js.map +0 -1
- package/dist/esm/debouncer/createDebouncedSignal.js +0 -11
- package/dist/esm/debouncer/createDebouncedSignal.js.map +0 -1
- package/dist/esm/debouncer/createDebouncedValue.js +0 -17
- package/dist/esm/debouncer/createDebouncedValue.js.map +0 -1
- package/dist/esm/debouncer/createDebouncer.js +0 -20
- package/dist/esm/debouncer/createDebouncer.js.map +0 -1
- package/dist/esm/debouncer/index.d.ts +0 -4
- package/dist/esm/debouncer/index.js.map +0 -1
- package/dist/esm/index.d.ts +0 -20
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/queuer/createQueuer.js +0 -14
- package/dist/esm/queuer/createQueuer.js.map +0 -1
- package/dist/esm/queuer/index.d.ts +0 -2
- package/dist/esm/queuer/index.js +0 -6
- package/dist/esm/queuer/index.js.map +0 -1
- package/dist/esm/rate-limiter/createRateLimitedSignal.js +0 -19
- package/dist/esm/rate-limiter/createRateLimitedSignal.js.map +0 -1
- package/dist/esm/rate-limiter/createRateLimitedValue.js +0 -13
- package/dist/esm/rate-limiter/createRateLimitedValue.js.map +0 -1
- package/dist/esm/rate-limiter/createRateLimiter.js +0 -14
- package/dist/esm/rate-limiter/createRateLimiter.js.map +0 -1
- package/dist/esm/rate-limiter/index.d.ts +0 -4
- package/dist/esm/rate-limiter/index.js.map +0 -1
- package/dist/esm/throttler/createThrottledSignal.js +0 -11
- package/dist/esm/throttler/createThrottledSignal.js.map +0 -1
- package/dist/esm/throttler/createThrottledValue.js +0 -17
- package/dist/esm/throttler/createThrottledValue.js.map +0 -1
- package/dist/esm/throttler/createThrottler.js +0 -20
- package/dist/esm/throttler/createThrottler.js.map +0 -1
- package/dist/esm/throttler/index.d.ts +0 -4
- package/dist/esm/throttler/index.js.map +0 -1
- package/dist/esm/types/index.d.ts +0 -1
- package/dist/esm/types/index.js +0 -2
- package/dist/esm/types/index.js.map +0 -1
- package/dist/esm/utils/index.d.ts +0 -1
- package/dist/esm/utils/index.js +0 -2
- package/dist/esm/utils/index.js.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="./media/header_pacer.png" >
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
<br />
|
|
6
|
+
|
|
7
|
+
<div align="center">
|
|
8
|
+
<a href="https://www.npmjs.com/package/@tanstack/pacer" target="\_parent">
|
|
9
|
+
<img alt="" src="https://img.shields.io/npm/dm/@tanstack/pacer.svg" alt="npm downloads" />
|
|
10
|
+
</a>
|
|
11
|
+
- <a href="https://github.com/TanStack/pacer" target="\_parent">
|
|
12
|
+
<img alt="" src="https://img.shields.io/github/stars/TanStack/pacer.svg?style=social&label=Star" alt="GitHub stars" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://bundlephobia.com/result?p=@tanstack/react-pacer@latest" target="\_parent">
|
|
15
|
+
<img alt="" src="https://badgen.net/bundlephobia/minzip/@tanstack/react-pacer@latest" alt="Bundle size" />
|
|
16
|
+
</a>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<div align="center">
|
|
20
|
+
<a href="#badge">
|
|
21
|
+
<img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg">
|
|
22
|
+
</a>
|
|
23
|
+
<a href="#badge">
|
|
24
|
+
<img src="https://img.shields.io/github/v/release/tanstack/pacer" alt="Release"/>
|
|
25
|
+
</a>
|
|
26
|
+
<a href="https://twitter.com/tan_stack">
|
|
27
|
+
<img src="https://img.shields.io/twitter/follow/tan_stack.svg?style=social" alt="Follow @TanStack"/>
|
|
28
|
+
</a>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<div align="center">
|
|
32
|
+
|
|
33
|
+
### [Become a Sponsor!](https://github.com/sponsors/tannerlinsley/)
|
|
34
|
+
</div>
|
|
35
|
+
|
|
36
|
+
# TanStack Pacer
|
|
37
|
+
|
|
38
|
+
A lightweight timing and scheduling library for debouncing, throttling, rate limiting, queuing, and batching.
|
|
39
|
+
|
|
40
|
+
> [!NOTE]
|
|
41
|
+
> TanStack Pacer is currently mostly a client-side only library, but it is being designed to be able to potentially be used on the server-side as well.
|
|
42
|
+
|
|
43
|
+
- **Debouncing**
|
|
44
|
+
- Delay execution until after a period of inactivity for when you only care about the last execution in a sequence.
|
|
45
|
+
- Synchronous or Asynchronous Debounce utilities with promise support and error handling
|
|
46
|
+
- Control of leading, trailing, and enabled options
|
|
47
|
+
- **Throttling**
|
|
48
|
+
- Smoothly limit the rate at which a function can fire
|
|
49
|
+
- Synchronous or Asynchronous Throttle utilities with promise support and error handling
|
|
50
|
+
- Control of leading, trailing, and enabled options.
|
|
51
|
+
- **Rate Limiting**
|
|
52
|
+
- Limit the rate at which a function can fire over a period of time
|
|
53
|
+
- Synchronous or Asynchronous Rate Limiting utilities with promise support and error handling
|
|
54
|
+
- Fixed or Sliding Window variations of Rate Limiting
|
|
55
|
+
- **Queuing**
|
|
56
|
+
- Queue functions to be executed in a specific order
|
|
57
|
+
- Choose from FIFO, LIFO, and Priority queue implementations
|
|
58
|
+
- Control processing speed with configurable wait times or concurrency limits
|
|
59
|
+
- Manage queue execution with start/stop capabilities
|
|
60
|
+
- Expire items from the queue after a configurable duration
|
|
61
|
+
- **Batching**
|
|
62
|
+
- Chunk up multiple operations into larger batches to reduce total back-and-forth operations
|
|
63
|
+
- Batch by time period, batch size, whichever comes first, or a custom condition to trigger batch executions
|
|
64
|
+
- **Async or Sync Variations**
|
|
65
|
+
- Choose between synchronous and asynchronous versions of each utility
|
|
66
|
+
- Optional error, success, and settled handling for async variations
|
|
67
|
+
- Retry and Abort support for async variations
|
|
68
|
+
- **State Management**
|
|
69
|
+
- Uses TanStack Store under the hood for state management with fine-grained reactivity
|
|
70
|
+
- Easily integrate with your own state management library of choice
|
|
71
|
+
- Persist state to local or session storage for some utilities like rate limiting and queuing
|
|
72
|
+
- **Convenient Hooks**
|
|
73
|
+
- Reduce boilerplate code with pre-built hooks like `useDebouncedCallback`, `useThrottledValue`, and `useQueuedState`, and more.
|
|
74
|
+
- Multiple layers of abstraction to choose from depending on your use case.
|
|
75
|
+
- Works with each framework's default state management solutions, or with whatever custom state management library that you prefer.
|
|
76
|
+
- **Type Safety**
|
|
77
|
+
- Full type safety with TypeScript that makes sure that your functions will always be called with the correct arguments
|
|
78
|
+
- Generics for flexible and reusable utilities
|
|
79
|
+
- **Framework Adapters**
|
|
80
|
+
- React, Solid, and more
|
|
81
|
+
- **Tree Shaking**
|
|
82
|
+
- We, of course, get tree-shaking right for your applications by default, but we also provide extra deep imports for each utility, making it easier to embed these utilities into your libraries without increasing the bundle-phobia reports of your library.
|
|
83
|
+
|
|
84
|
+
### <a href="https://tanstack.com/pacer">Read the docs →</b></a>
|
|
85
|
+
|
|
86
|
+
<br />
|
|
87
|
+
|
|
88
|
+
> [!NOTE]
|
|
89
|
+
> You may know **TanSack Pacer** by our adapter names, too!
|
|
90
|
+
>
|
|
91
|
+
> - [**React Pacer**](https://tanstack.com/pacer/latest/docs/framework/react/react-pacer)
|
|
92
|
+
> - [**Solid Pacer**](https://tanstack.com/pacer/latest/docs/framework/solid/solid-pacer)
|
|
93
|
+
> - Angular Pacer - needs a contributor!
|
|
94
|
+
> - Preact Pacer - Coming soon! (After React Pacer is more fleshed out)
|
|
95
|
+
> - Svelte Pacer - needs a contributor!
|
|
96
|
+
> - Vue Pacer - needs a contributor!
|
|
97
|
+
|
|
98
|
+
## Get Involved
|
|
99
|
+
|
|
100
|
+
- We welcome issues and pull requests!
|
|
101
|
+
- Participate in [GitHub discussions](https://github.com/TanStack/pacer/discussions)
|
|
102
|
+
- Chat with the community on [Discord](https://discord.com/invite/WrRKjPJ)
|
|
103
|
+
- See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup instructions
|
|
104
|
+
|
|
105
|
+
## Partners
|
|
106
|
+
|
|
107
|
+
<table align="center">
|
|
108
|
+
<tr>
|
|
109
|
+
<td>
|
|
110
|
+
<a href="https://www.coderabbit.ai/?via=tanstack&dub_id=aCcEEdAOqqutX6OS" >
|
|
111
|
+
<picture>
|
|
112
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/coderabbit-dark-CMcuvjEy.svg" height="40" />
|
|
113
|
+
<source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/coderabbit-light-DVMJ2jHi.svg" height="40" />
|
|
114
|
+
<img src="https://tanstack.com/assets/coderabbit-light-DVMJ2jHi.svg" height="40" alt="CodeRabbit" />
|
|
115
|
+
</picture>
|
|
116
|
+
</a>
|
|
117
|
+
</td>
|
|
118
|
+
<td>
|
|
119
|
+
<a href="https://www.cloudflare.com?utm_source=tanstack">
|
|
120
|
+
<picture>
|
|
121
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/cloudflare-white-DQDB7UaL.svg" height="60" />
|
|
122
|
+
<source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/cloudflare-black-CPufaW0B.svg" height="60" />
|
|
123
|
+
<img src="https://tanstack.com/assets/cloudflare-black-CPufaW0B.svg" height="60" alt="Cloudflare" />
|
|
124
|
+
</picture>
|
|
125
|
+
</a>
|
|
126
|
+
</td>
|
|
127
|
+
<td>
|
|
128
|
+
<a href="https://www.unkey.com/?utm_source=tanstack">
|
|
129
|
+
<picture>
|
|
130
|
+
<source media="(prefers-color-scheme: dark)" srcset="./media/unkey_dark.svg" height="60" />
|
|
131
|
+
<source media="(prefers-color-scheme: light)" srcset="./media/unkey_logo.svg" height="60" />
|
|
132
|
+
<img src="./media/unkey_logo.svg" height="60" alt="Unkey"/>
|
|
133
|
+
</picture>
|
|
134
|
+
</a>
|
|
135
|
+
</td>
|
|
136
|
+
</tr>
|
|
137
|
+
</table>
|
|
138
|
+
|
|
139
|
+
<div align="center">
|
|
140
|
+
<img src="./media/partner_logo.svg" alt="Pacer & you?" height="65">
|
|
141
|
+
<p>
|
|
142
|
+
We're looking for TanStack Pacer Partners to join our mission! Partner with us to push the boundaries of TanStack Pacer and build amazing things together.
|
|
143
|
+
</p>
|
|
144
|
+
<a href="mailto:partners@tanstack.com?subject=TanStack Pacer Partnership"><b>LET'S CHAT</b></a>
|
|
145
|
+
</div>
|
|
146
|
+
|
|
147
|
+
</div>
|
|
148
|
+
|
|
149
|
+
## Explore the TanStack Ecosystem
|
|
150
|
+
|
|
151
|
+
- <a href="https://github.com/tanstack/config"><b>TanStack Config</b></a> – Tooling for JS/TS packages
|
|
152
|
+
- <a href="https://github.com/tanstack/db"><b>TanStack DB</b></a> – Reactive sync client store
|
|
153
|
+
- <a href="https://github.com/tanstack/devtools"><b>TanStack DevTools</b></a> – Unified devtools panel
|
|
154
|
+
- <a href="https://github.com/tanstack/form"><b>TanStack Form</b></a> – Type‑safe form state
|
|
155
|
+
- <a href="https://github.com/tanstack/query"><b>TanStack Query</b></a> – Async state & caching
|
|
156
|
+
- <a href="https://github.com/tanstack/ranger"><b>TanStack Ranger</b></a> – Range & slider primitives
|
|
157
|
+
- <a href="https://github.com/tanstack/router"><b>TanStack Router</b></a> – Type‑safe routing, caching & URL state
|
|
158
|
+
- <a href="https://github.com/tanstack/router"><b>TanStack Start</b></a> – Full‑stack SSR & streaming
|
|
159
|
+
- <a href="https://github.com/tanstack/store"><b>TanStack Store</b></a> – Reactive data store
|
|
160
|
+
- <a href="https://github.com/tanstack/table"><b>TanStack Table</b></a> – Headless datagrids
|
|
161
|
+
- <a href="https://github.com/tanstack/virtual"><b>TanStack Virtual</b></a> – Virtualized rendering
|
|
162
|
+
|
|
163
|
+
… and more at <a href="https://tanstack.com"><b>TanStack.com »</b></a>
|
|
164
|
+
|
|
165
|
+
<!-- USE THE FORCE LUKE -->
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
const require_PacerProvider = require('../provider/PacerProvider.cjs');
|
|
2
|
+
let __tanstack_pacer_async_batcher = require("@tanstack/pacer/async-batcher");
|
|
3
|
+
let __tanstack_solid_store = require("@tanstack/solid-store");
|
|
4
|
+
|
|
5
|
+
//#region src/async-batcher/createAsyncBatcher.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates a Solid-compatible AsyncBatcher instance for managing asynchronous batches of items, exposing Solid signals for all stateful properties.
|
|
8
|
+
*
|
|
9
|
+
* This is the async version of the createBatcher hook. Unlike the sync version, this async batcher:
|
|
10
|
+
* - Handles promises and returns results from batch executions
|
|
11
|
+
* - Provides error handling with configurable error behavior
|
|
12
|
+
* - Tracks success, error, and settle counts separately
|
|
13
|
+
* - Has state tracking for when batches are executing
|
|
14
|
+
* - Returns the result of the batch function execution
|
|
15
|
+
*
|
|
16
|
+
* Features:
|
|
17
|
+
* - Configurable batch size and wait time
|
|
18
|
+
* - Custom batch processing logic via getShouldExecute
|
|
19
|
+
* - Event callbacks for monitoring batch operations
|
|
20
|
+
* - Error handling for failed batch operations
|
|
21
|
+
* - Automatic or manual batch processing
|
|
22
|
+
* - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity
|
|
23
|
+
*
|
|
24
|
+
* The batcher collects items and processes them in batches based on:
|
|
25
|
+
* - Maximum batch size (number of items per batch)
|
|
26
|
+
* - Time-based batching (process after X milliseconds)
|
|
27
|
+
* - Custom batch processing logic via getShouldExecute
|
|
28
|
+
*
|
|
29
|
+
* Error Handling:
|
|
30
|
+
* - If an `onError` handler is provided, it will be called with the error and batcher instance
|
|
31
|
+
* - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
|
|
32
|
+
* - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
|
|
33
|
+
* - Both onError and throwOnError can be used together; the handler will be called before any error is thrown
|
|
34
|
+
* - The error state can be checked using the underlying AsyncBatcher instance
|
|
35
|
+
*
|
|
36
|
+
* ## State Management and Selector
|
|
37
|
+
*
|
|
38
|
+
* The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
|
|
39
|
+
* to specify which state changes will trigger a re-render, optimizing performance by preventing
|
|
40
|
+
* unnecessary re-renders when irrelevant state changes occur.
|
|
41
|
+
*
|
|
42
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
43
|
+
* tracking by providing a selector function. This prevents unnecessary re-renders and gives you
|
|
44
|
+
* full control over when your component updates. Only when you provide a selector will the
|
|
45
|
+
* component re-render when the selected state values change.
|
|
46
|
+
*
|
|
47
|
+
* Available state properties:
|
|
48
|
+
* - `errorCount`: Number of failed batch executions
|
|
49
|
+
* - `executionCount`: Total number of batch execution attempts (successful + failed)
|
|
50
|
+
* - `hasError`: Whether the last batch execution resulted in an error
|
|
51
|
+
* - `isExecuting`: Whether a batch execution is currently in progress
|
|
52
|
+
* - `items`: Array of items currently queued for batching
|
|
53
|
+
* - `lastError`: The error from the most recent failed batch execution (if any)
|
|
54
|
+
* - `lastResult`: The result from the most recent successful batch execution
|
|
55
|
+
* - `settleCount`: Number of batch executions that have completed (successful or failed)
|
|
56
|
+
* - `successCount`: Number of successful batch executions
|
|
57
|
+
*
|
|
58
|
+
* Example usage:
|
|
59
|
+
* ```tsx
|
|
60
|
+
* // Default behavior - no reactive state subscriptions
|
|
61
|
+
* const asyncBatcher = createAsyncBatcher(
|
|
62
|
+
* async (items) => {
|
|
63
|
+
* const results = await Promise.all(items.map(item => processItem(item)));
|
|
64
|
+
* return results;
|
|
65
|
+
* },
|
|
66
|
+
* {
|
|
67
|
+
* maxSize: 10,
|
|
68
|
+
* wait: 2000,
|
|
69
|
+
* onSuccess: (result) => {
|
|
70
|
+
* console.log('Batch processed successfully:', result);
|
|
71
|
+
* },
|
|
72
|
+
* onError: (error) => {
|
|
73
|
+
* console.error('Batch processing failed:', error);
|
|
74
|
+
* }
|
|
75
|
+
* }
|
|
76
|
+
* );
|
|
77
|
+
*
|
|
78
|
+
* // Opt-in to re-render when items or isExecuting changes (optimized for UI updates)
|
|
79
|
+
* const asyncBatcher = createAsyncBatcher(
|
|
80
|
+
* async (items) => {
|
|
81
|
+
* const results = await Promise.all(items.map(item => processItem(item)));
|
|
82
|
+
* return results;
|
|
83
|
+
* },
|
|
84
|
+
* { maxSize: 10, wait: 2000 },
|
|
85
|
+
* (state) => ({ items: state.items, isExecuting: state.isExecuting })
|
|
86
|
+
* );
|
|
87
|
+
*
|
|
88
|
+
* // Opt-in to re-render when error state changes (optimized for error handling)
|
|
89
|
+
* const asyncBatcher = createAsyncBatcher(
|
|
90
|
+
* async (items) => {
|
|
91
|
+
* const results = await Promise.all(items.map(item => processItem(item)));
|
|
92
|
+
* return results;
|
|
93
|
+
* },
|
|
94
|
+
* { maxSize: 10, wait: 2000 },
|
|
95
|
+
* (state) => ({ hasError: state.hasError, lastError: state.lastError })
|
|
96
|
+
* );
|
|
97
|
+
*
|
|
98
|
+
* // Add items to batch
|
|
99
|
+
* asyncBatcher.addItem(newItem);
|
|
100
|
+
*
|
|
101
|
+
* // Manually execute batch
|
|
102
|
+
* const result = await asyncBatcher.execute();
|
|
103
|
+
*
|
|
104
|
+
* // Access the selected state (will be empty object {} unless selector provided)
|
|
105
|
+
* const { items, isExecuting } = asyncBatcher.state();
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
function createAsyncBatcher(fn, options = {}, selector = () => ({})) {
|
|
109
|
+
const asyncBatcher = new __tanstack_pacer_async_batcher.AsyncBatcher(fn, {
|
|
110
|
+
...require_PacerProvider.useDefaultPacerOptions().asyncBatcher,
|
|
111
|
+
...options
|
|
112
|
+
});
|
|
113
|
+
const state = (0, __tanstack_solid_store.useStore)(asyncBatcher.store, selector);
|
|
114
|
+
return {
|
|
115
|
+
...asyncBatcher,
|
|
116
|
+
state
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
exports.createAsyncBatcher = createAsyncBatcher;
|
|
122
|
+
//# sourceMappingURL=createAsyncBatcher.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createAsyncBatcher.cjs","names":["AsyncBatcher","useDefaultPacerOptions"],"sources":["../../src/async-batcher/createAsyncBatcher.ts"],"sourcesContent":["import { AsyncBatcher } from '@tanstack/pacer/async-batcher'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type {\n AsyncBatcherOptions,\n AsyncBatcherState,\n} from '@tanstack/pacer/async-batcher'\n\nexport interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<\n AsyncBatcher<TValue>,\n 'store'\n> {\n /**\n * Reactive state that will be updated when the batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<AsyncBatcherState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible AsyncBatcher instance for managing asynchronous batches of items, exposing Solid signals for all stateful properties.\n *\n * This is the async version of the createBatcher hook. Unlike the sync version, this async batcher:\n * - Handles promises and returns results from batch executions\n * - Provides error handling with configurable error behavior\n * - Tracks success, error, and settle counts separately\n * - Has state tracking for when batches are executing\n * - Returns the result of the batch function execution\n *\n * Features:\n * - Configurable batch size and wait time\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\n * - Error handling for failed batch operations\n * - Automatic or manual batch processing\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The batcher collects items and processes them in batches based on:\n * - Maximum batch size (number of items per batch)\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and batcher instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncBatcher instance\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you\n * to specify which state changes will trigger a re-render, optimizing performance by preventing\n * unnecessary re-renders 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 re-renders and gives you\n * full control over when your component updates. Only when you provide a selector will the\n * component re-render when the selected state values change.\n *\n * Available state properties:\n * - `errorCount`: Number of failed batch executions\n * - `executionCount`: Total number of batch execution attempts (successful + failed)\n * - `hasError`: Whether the last batch execution resulted in an error\n * - `isExecuting`: Whether a batch execution is currently in progress\n * - `items`: Array of items currently queued for batching\n * - `lastError`: The error from the most recent failed batch execution (if any)\n * - `lastResult`: The result from the most recent successful batch execution\n * - `settleCount`: Number of batch executions that have completed (successful or failed)\n * - `successCount`: Number of successful batch executions\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * {\n * maxSize: 10,\n * wait: 2000,\n * onSuccess: (result) => {\n * console.log('Batch processed successfully:', result);\n * },\n * onError: (error) => {\n * console.error('Batch processing failed:', error);\n * }\n * }\n * );\n *\n * // Opt-in to re-render when items or isExecuting changes (optimized for UI updates)\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * { maxSize: 10, wait: 2000 },\n * (state) => ({ items: state.items, isExecuting: state.isExecuting })\n * );\n *\n * // Opt-in to re-render when error state changes (optimized for error handling)\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * { maxSize: 10, wait: 2000 },\n * (state) => ({ hasError: state.hasError, lastError: state.lastError })\n * );\n *\n * // Add items to batch\n * asyncBatcher.addItem(newItem);\n *\n * // Manually execute batch\n * const result = await asyncBatcher.execute();\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isExecuting } = asyncBatcher.state();\n * ```\n */\nexport function createAsyncBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => Promise<any>,\n options: AsyncBatcherOptions<TValue> = {},\n selector: (state: AsyncBatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncBatcher,\n ...options,\n } as AsyncBatcherOptions<TValue>\n\n const asyncBatcher = new AsyncBatcher<TValue>(fn, mergedOptions)\n\n const state = useStore(asyncBatcher.store, selector)\n\n return {\n ...asyncBatcher,\n state,\n } as SolidAsyncBatcher<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkIA,SAAgB,mBACd,IACA,UAAuC,EAAE,EACzC,kBACG,EAAE,GACiC;CAMtC,MAAM,eAAe,IAAIA,4CAAqB,IALxB;EACpB,GAAGC,8CAAwB,CAAC;EAC5B,GAAG;EACJ,CAE+D;CAEhE,MAAM,6CAAiB,aAAa,OAAO,SAAS;AAEpD,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import { AsyncBatcher, AsyncBatcherOptions, AsyncBatcherState } from
|
|
2
|
-
import { Store } from
|
|
3
|
-
import { Accessor } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { AsyncBatcher, AsyncBatcherOptions, AsyncBatcherState } from "@tanstack/pacer/async-batcher";
|
|
2
|
+
import { Store } from "@tanstack/solid-store";
|
|
3
|
+
import { Accessor } from "solid-js";
|
|
4
|
+
|
|
5
|
+
//#region src/async-batcher/createAsyncBatcher.d.ts
|
|
6
|
+
interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBatcher<TValue>, 'store'> {
|
|
7
|
+
/**
|
|
8
|
+
* Reactive state that will be updated when the batcher state changes
|
|
9
|
+
*
|
|
10
|
+
* Use this instead of `batcher.store.state`
|
|
11
|
+
*/
|
|
12
|
+
readonly state: Accessor<Readonly<TSelected>>;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.
|
|
15
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.
|
|
16
|
+
* Although, you can make the state reactive by using the `useStore` in your own usage.
|
|
17
|
+
*/
|
|
18
|
+
readonly store: Store<Readonly<AsyncBatcherState<TValue>>>;
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* Creates a Solid-compatible AsyncBatcher instance for managing asynchronous batches of items, exposing Solid signals for all stateful properties.
|
|
@@ -117,4 +119,7 @@ export interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBat
|
|
|
117
119
|
* const { items, isExecuting } = asyncBatcher.state();
|
|
118
120
|
* ```
|
|
119
121
|
*/
|
|
120
|
-
|
|
122
|
+
declare function createAsyncBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => Promise<any>, options?: AsyncBatcherOptions<TValue>, selector?: (state: AsyncBatcherState<TValue>) => TSelected): SolidAsyncBatcher<TValue, TSelected>;
|
|
123
|
+
//#endregion
|
|
124
|
+
export { SolidAsyncBatcher, createAsyncBatcher };
|
|
125
|
+
//# sourceMappingURL=createAsyncBatcher.d.cts.map
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { Accessor } from "solid-js";
|
|
2
|
+
import { AsyncBatcher, AsyncBatcherOptions, AsyncBatcherState } from "@tanstack/pacer/async-batcher";
|
|
3
|
+
import { Store } from "@tanstack/solid-store";
|
|
4
|
+
|
|
5
|
+
//#region src/async-batcher/createAsyncBatcher.d.ts
|
|
6
|
+
interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBatcher<TValue>, 'store'> {
|
|
7
|
+
/**
|
|
8
|
+
* Reactive state that will be updated when the batcher state changes
|
|
9
|
+
*
|
|
10
|
+
* Use this instead of `batcher.store.state`
|
|
11
|
+
*/
|
|
12
|
+
readonly state: Accessor<Readonly<TSelected>>;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.
|
|
15
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.
|
|
16
|
+
* Although, you can make the state reactive by using the `useStore` in your own usage.
|
|
17
|
+
*/
|
|
18
|
+
readonly store: Store<Readonly<AsyncBatcherState<TValue>>>;
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* Creates a Solid-compatible AsyncBatcher instance for managing asynchronous batches of items, exposing Solid signals for all stateful properties.
|
|
@@ -117,4 +119,7 @@ export interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBat
|
|
|
117
119
|
* const { items, isExecuting } = asyncBatcher.state();
|
|
118
120
|
* ```
|
|
119
121
|
*/
|
|
120
|
-
|
|
122
|
+
declare function createAsyncBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => Promise<any>, options?: AsyncBatcherOptions<TValue>, selector?: (state: AsyncBatcherState<TValue>) => TSelected): SolidAsyncBatcher<TValue, TSelected>;
|
|
123
|
+
//#endregion
|
|
124
|
+
export { SolidAsyncBatcher, createAsyncBatcher };
|
|
125
|
+
//# sourceMappingURL=createAsyncBatcher.d.ts.map
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { useDefaultPacerOptions } from "../provider/PacerProvider.js";
|
|
2
|
+
import { AsyncBatcher } from "@tanstack/pacer/async-batcher";
|
|
3
|
+
import { useStore } from "@tanstack/solid-store";
|
|
4
|
+
|
|
5
|
+
//#region src/async-batcher/createAsyncBatcher.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates a Solid-compatible AsyncBatcher instance for managing asynchronous batches of items, exposing Solid signals for all stateful properties.
|
|
8
|
+
*
|
|
9
|
+
* This is the async version of the createBatcher hook. Unlike the sync version, this async batcher:
|
|
10
|
+
* - Handles promises and returns results from batch executions
|
|
11
|
+
* - Provides error handling with configurable error behavior
|
|
12
|
+
* - Tracks success, error, and settle counts separately
|
|
13
|
+
* - Has state tracking for when batches are executing
|
|
14
|
+
* - Returns the result of the batch function execution
|
|
15
|
+
*
|
|
16
|
+
* Features:
|
|
17
|
+
* - Configurable batch size and wait time
|
|
18
|
+
* - Custom batch processing logic via getShouldExecute
|
|
19
|
+
* - Event callbacks for monitoring batch operations
|
|
20
|
+
* - Error handling for failed batch operations
|
|
21
|
+
* - Automatic or manual batch processing
|
|
22
|
+
* - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity
|
|
23
|
+
*
|
|
24
|
+
* The batcher collects items and processes them in batches based on:
|
|
25
|
+
* - Maximum batch size (number of items per batch)
|
|
26
|
+
* - Time-based batching (process after X milliseconds)
|
|
27
|
+
* - Custom batch processing logic via getShouldExecute
|
|
28
|
+
*
|
|
29
|
+
* Error Handling:
|
|
30
|
+
* - If an `onError` handler is provided, it will be called with the error and batcher instance
|
|
31
|
+
* - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
|
|
32
|
+
* - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
|
|
33
|
+
* - Both onError and throwOnError can be used together; the handler will be called before any error is thrown
|
|
34
|
+
* - The error state can be checked using the underlying AsyncBatcher instance
|
|
35
|
+
*
|
|
36
|
+
* ## State Management and Selector
|
|
37
|
+
*
|
|
38
|
+
* The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
|
|
39
|
+
* to specify which state changes will trigger a re-render, optimizing performance by preventing
|
|
40
|
+
* unnecessary re-renders when irrelevant state changes occur.
|
|
41
|
+
*
|
|
42
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
43
|
+
* tracking by providing a selector function. This prevents unnecessary re-renders and gives you
|
|
44
|
+
* full control over when your component updates. Only when you provide a selector will the
|
|
45
|
+
* component re-render when the selected state values change.
|
|
46
|
+
*
|
|
47
|
+
* Available state properties:
|
|
48
|
+
* - `errorCount`: Number of failed batch executions
|
|
49
|
+
* - `executionCount`: Total number of batch execution attempts (successful + failed)
|
|
50
|
+
* - `hasError`: Whether the last batch execution resulted in an error
|
|
51
|
+
* - `isExecuting`: Whether a batch execution is currently in progress
|
|
52
|
+
* - `items`: Array of items currently queued for batching
|
|
53
|
+
* - `lastError`: The error from the most recent failed batch execution (if any)
|
|
54
|
+
* - `lastResult`: The result from the most recent successful batch execution
|
|
55
|
+
* - `settleCount`: Number of batch executions that have completed (successful or failed)
|
|
56
|
+
* - `successCount`: Number of successful batch executions
|
|
57
|
+
*
|
|
58
|
+
* Example usage:
|
|
59
|
+
* ```tsx
|
|
60
|
+
* // Default behavior - no reactive state subscriptions
|
|
61
|
+
* const asyncBatcher = createAsyncBatcher(
|
|
62
|
+
* async (items) => {
|
|
63
|
+
* const results = await Promise.all(items.map(item => processItem(item)));
|
|
64
|
+
* return results;
|
|
65
|
+
* },
|
|
66
|
+
* {
|
|
67
|
+
* maxSize: 10,
|
|
68
|
+
* wait: 2000,
|
|
69
|
+
* onSuccess: (result) => {
|
|
70
|
+
* console.log('Batch processed successfully:', result);
|
|
71
|
+
* },
|
|
72
|
+
* onError: (error) => {
|
|
73
|
+
* console.error('Batch processing failed:', error);
|
|
74
|
+
* }
|
|
75
|
+
* }
|
|
76
|
+
* );
|
|
77
|
+
*
|
|
78
|
+
* // Opt-in to re-render when items or isExecuting changes (optimized for UI updates)
|
|
79
|
+
* const asyncBatcher = createAsyncBatcher(
|
|
80
|
+
* async (items) => {
|
|
81
|
+
* const results = await Promise.all(items.map(item => processItem(item)));
|
|
82
|
+
* return results;
|
|
83
|
+
* },
|
|
84
|
+
* { maxSize: 10, wait: 2000 },
|
|
85
|
+
* (state) => ({ items: state.items, isExecuting: state.isExecuting })
|
|
86
|
+
* );
|
|
87
|
+
*
|
|
88
|
+
* // Opt-in to re-render when error state changes (optimized for error handling)
|
|
89
|
+
* const asyncBatcher = createAsyncBatcher(
|
|
90
|
+
* async (items) => {
|
|
91
|
+
* const results = await Promise.all(items.map(item => processItem(item)));
|
|
92
|
+
* return results;
|
|
93
|
+
* },
|
|
94
|
+
* { maxSize: 10, wait: 2000 },
|
|
95
|
+
* (state) => ({ hasError: state.hasError, lastError: state.lastError })
|
|
96
|
+
* );
|
|
97
|
+
*
|
|
98
|
+
* // Add items to batch
|
|
99
|
+
* asyncBatcher.addItem(newItem);
|
|
100
|
+
*
|
|
101
|
+
* // Manually execute batch
|
|
102
|
+
* const result = await asyncBatcher.execute();
|
|
103
|
+
*
|
|
104
|
+
* // Access the selected state (will be empty object {} unless selector provided)
|
|
105
|
+
* const { items, isExecuting } = asyncBatcher.state();
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
function createAsyncBatcher(fn, options = {}, selector = () => ({})) {
|
|
109
|
+
const asyncBatcher = new AsyncBatcher(fn, {
|
|
110
|
+
...useDefaultPacerOptions().asyncBatcher,
|
|
111
|
+
...options
|
|
112
|
+
});
|
|
113
|
+
const state = useStore(asyncBatcher.store, selector);
|
|
114
|
+
return {
|
|
115
|
+
...asyncBatcher,
|
|
116
|
+
state
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
export { createAsyncBatcher };
|
|
122
|
+
//# sourceMappingURL=createAsyncBatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createAsyncBatcher.js","names":[],"sources":["../../src/async-batcher/createAsyncBatcher.ts"],"sourcesContent":["import { AsyncBatcher } from '@tanstack/pacer/async-batcher'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type {\n AsyncBatcherOptions,\n AsyncBatcherState,\n} from '@tanstack/pacer/async-batcher'\n\nexport interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<\n AsyncBatcher<TValue>,\n 'store'\n> {\n /**\n * Reactive state that will be updated when the batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<AsyncBatcherState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible AsyncBatcher instance for managing asynchronous batches of items, exposing Solid signals for all stateful properties.\n *\n * This is the async version of the createBatcher hook. Unlike the sync version, this async batcher:\n * - Handles promises and returns results from batch executions\n * - Provides error handling with configurable error behavior\n * - Tracks success, error, and settle counts separately\n * - Has state tracking for when batches are executing\n * - Returns the result of the batch function execution\n *\n * Features:\n * - Configurable batch size and wait time\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\n * - Error handling for failed batch operations\n * - Automatic or manual batch processing\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The batcher collects items and processes them in batches based on:\n * - Maximum batch size (number of items per batch)\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and batcher instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncBatcher instance\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you\n * to specify which state changes will trigger a re-render, optimizing performance by preventing\n * unnecessary re-renders 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 re-renders and gives you\n * full control over when your component updates. Only when you provide a selector will the\n * component re-render when the selected state values change.\n *\n * Available state properties:\n * - `errorCount`: Number of failed batch executions\n * - `executionCount`: Total number of batch execution attempts (successful + failed)\n * - `hasError`: Whether the last batch execution resulted in an error\n * - `isExecuting`: Whether a batch execution is currently in progress\n * - `items`: Array of items currently queued for batching\n * - `lastError`: The error from the most recent failed batch execution (if any)\n * - `lastResult`: The result from the most recent successful batch execution\n * - `settleCount`: Number of batch executions that have completed (successful or failed)\n * - `successCount`: Number of successful batch executions\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * {\n * maxSize: 10,\n * wait: 2000,\n * onSuccess: (result) => {\n * console.log('Batch processed successfully:', result);\n * },\n * onError: (error) => {\n * console.error('Batch processing failed:', error);\n * }\n * }\n * );\n *\n * // Opt-in to re-render when items or isExecuting changes (optimized for UI updates)\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * { maxSize: 10, wait: 2000 },\n * (state) => ({ items: state.items, isExecuting: state.isExecuting })\n * );\n *\n * // Opt-in to re-render when error state changes (optimized for error handling)\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * { maxSize: 10, wait: 2000 },\n * (state) => ({ hasError: state.hasError, lastError: state.lastError })\n * );\n *\n * // Add items to batch\n * asyncBatcher.addItem(newItem);\n *\n * // Manually execute batch\n * const result = await asyncBatcher.execute();\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isExecuting } = asyncBatcher.state();\n * ```\n */\nexport function createAsyncBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => Promise<any>,\n options: AsyncBatcherOptions<TValue> = {},\n selector: (state: AsyncBatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncBatcher,\n ...options,\n } as AsyncBatcherOptions<TValue>\n\n const asyncBatcher = new AsyncBatcher<TValue>(fn, mergedOptions)\n\n const state = useStore(asyncBatcher.store, selector)\n\n return {\n ...asyncBatcher,\n state,\n } as SolidAsyncBatcher<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkIA,SAAgB,mBACd,IACA,UAAuC,EAAE,EACzC,kBACG,EAAE,GACiC;CAMtC,MAAM,eAAe,IAAI,aAAqB,IALxB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ,CAE+D;CAEhE,MAAM,QAAQ,SAAS,aAAa,OAAO,SAAS;AAEpD,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const require_createAsyncBatcher = require('./createAsyncBatcher.cjs');
|
|
2
|
+
|
|
3
|
+
exports.createAsyncBatcher = require_createAsyncBatcher.createAsyncBatcher;
|
|
4
|
+
var __tanstack_pacer_async_batcher = require("@tanstack/pacer/async-batcher");
|
|
5
|
+
Object.keys(__tanstack_pacer_async_batcher).forEach(function (k) {
|
|
6
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () { return __tanstack_pacer_async_batcher[k]; }
|
|
9
|
+
});
|
|
10
|
+
});
|