@tanstack/solid-pacer 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- 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} +6 -26
- 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/{cjs/queuer → queuer}/createQueuedSignal.d.cts +9 -7
- package/dist/{esm/queuer → queuer}/createQueuedSignal.d.ts +9 -7
- 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 +10 -4
- package/dist/{esm/rate-limiter → rate-limiter}/createRateLimitedValue.d.ts +10 -4
- 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 +4 -2
- package/src/async-queuer/createAsyncQueuer.ts +4 -2
- package/src/batcher/createBatcher.ts +4 -2
- package/src/debouncer/createDebouncer.ts +4 -2
- package/src/provider/index.ts +1 -0
- package/src/queuer/createQueuer.ts +4 -2
- package/src/rate-limiter/createRateLimiter.ts +4 -2
- package/src/throttler/createThrottler.ts +4 -2
- package/dist/cjs/async-batcher/createAsyncBatcher.cjs +0 -19
- 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 -25
- 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 -19
- 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 -19
- 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 -19
- 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 -19
- 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 -25
- 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 -48
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/index.d.cts +0 -22
- package/dist/cjs/provider/PacerProvider.cjs +0 -28
- package/dist/cjs/provider/PacerProvider.cjs.map +0 -1
- package/dist/cjs/provider/PacerProvider.d.cts +0 -25
- package/dist/cjs/queuer/createQueuedSignal.cjs +0 -9
- package/dist/cjs/queuer/createQueuedSignal.cjs.map +0 -1
- package/dist/cjs/queuer/createQueuer.cjs +0 -19
- package/dist/cjs/queuer/createQueuer.cjs.map +0 -1
- package/dist/cjs/queuer/index.cjs +0 -14
- package/dist/cjs/queuer/index.cjs.map +0 -1
- package/dist/cjs/queuer/index.d.cts +0 -3
- 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 -19
- 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 -25
- 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 -19
- 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 -25
- 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 -19
- 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 -19
- 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 -19
- 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 -19
- 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 -25
- 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 -22
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/provider/PacerProvider.d.ts +0 -25
- package/dist/esm/provider/PacerProvider.js +0 -28
- package/dist/esm/provider/PacerProvider.js.map +0 -1
- package/dist/esm/queuer/createQueuedSignal.js +0 -9
- package/dist/esm/queuer/createQueuedSignal.js.map +0 -1
- package/dist/esm/queuer/createQueuer.js +0 -19
- package/dist/esm/queuer/createQueuer.js.map +0 -1
- package/dist/esm/queuer/index.d.ts +0 -3
- package/dist/esm/queuer/index.js +0 -8
- 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 -19
- 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 -25
- 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
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Store } from
|
|
3
|
-
import {
|
|
4
|
-
import { AnyAsyncFunction } from
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { Accessor } from "solid-js";
|
|
2
|
+
import { Store } from "@tanstack/solid-store";
|
|
3
|
+
import { AsyncThrottler, AsyncThrottlerOptions, AsyncThrottlerState } from "@tanstack/pacer/async-throttler";
|
|
4
|
+
import { AnyAsyncFunction } from "@tanstack/pacer/types";
|
|
5
|
+
|
|
6
|
+
//#region src/async-throttler/createAsyncThrottler.d.ts
|
|
7
|
+
interface SolidAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncThrottler<TFn>, 'store'> {
|
|
8
|
+
/**
|
|
9
|
+
* Reactive state that will be updated when the throttler state changes
|
|
10
|
+
*
|
|
11
|
+
* Use this instead of `throttler.store.state`
|
|
12
|
+
*/
|
|
13
|
+
readonly state: Accessor<Readonly<TSelected>>;
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.
|
|
16
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.
|
|
17
|
+
* Although, you can make the state reactive by using the `useStore` in your own usage.
|
|
18
|
+
*/
|
|
19
|
+
readonly store: Store<Readonly<AsyncThrottlerState<TFn>>>;
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
20
22
|
* A low-level Solid hook that creates an `AsyncThrottler` instance to limit how often an async function can execute.
|
|
@@ -104,4 +106,7 @@ export interface SolidAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {
|
|
|
104
106
|
* const { isPending, isExecuting } = throttler.state();
|
|
105
107
|
* ```
|
|
106
108
|
*/
|
|
107
|
-
|
|
109
|
+
declare function createAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: AsyncThrottlerOptions<TFn>, selector?: (state: AsyncThrottlerState<TFn>) => TSelected): SolidAsyncThrottler<TFn, TSelected>;
|
|
110
|
+
//#endregion
|
|
111
|
+
export { SolidAsyncThrottler, createAsyncThrottler };
|
|
112
|
+
//# sourceMappingURL=createAsyncThrottler.d.ts.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { useDefaultPacerOptions } from "../provider/PacerProvider.js";
|
|
2
|
+
import { useStore } from "@tanstack/solid-store";
|
|
3
|
+
import { AsyncThrottler } from "@tanstack/pacer/async-throttler";
|
|
4
|
+
|
|
5
|
+
//#region src/async-throttler/createAsyncThrottler.ts
|
|
6
|
+
/**
|
|
7
|
+
* A low-level Solid hook that creates an `AsyncThrottler` instance to limit how often an async function can execute.
|
|
8
|
+
*
|
|
9
|
+
* This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that
|
|
10
|
+
* you can integrate with any state management solution (createSignal, etc).
|
|
11
|
+
*
|
|
12
|
+
* Async throttling ensures an async function executes at most once within a specified time window,
|
|
13
|
+
* regardless of how many times it is called. This is useful for rate-limiting expensive API calls,
|
|
14
|
+
* database operations, or other async tasks.
|
|
15
|
+
*
|
|
16
|
+
* Unlike the non-async Throttler, this async version supports returning values from the throttled function,
|
|
17
|
+
* making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call
|
|
18
|
+
* instead of setting the result on a state variable from within the throttled function.
|
|
19
|
+
*
|
|
20
|
+
* Error Handling:
|
|
21
|
+
* - If an `onError` handler is provided, it will be called with the error and throttler instance
|
|
22
|
+
* - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
|
|
23
|
+
* - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
|
|
24
|
+
* - Both onError and throwOnError can be used together - the handler will be called before any error is thrown
|
|
25
|
+
* - The error state can be checked using the underlying AsyncThrottler instance
|
|
26
|
+
*
|
|
27
|
+
* ## State Management and Selector
|
|
28
|
+
*
|
|
29
|
+
* The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
|
|
30
|
+
* to specify which state changes will trigger a re-render, optimizing performance by preventing
|
|
31
|
+
* unnecessary re-renders when irrelevant state changes occur.
|
|
32
|
+
*
|
|
33
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
34
|
+
* tracking by providing a selector function. This prevents unnecessary re-renders and gives you
|
|
35
|
+
* full control over when your component updates. Only when you provide a selector will the
|
|
36
|
+
* component re-render when the selected state values change.
|
|
37
|
+
*
|
|
38
|
+
* Available state properties:
|
|
39
|
+
* - `canLeadingExecute`: Whether the throttler can execute on the leading edge
|
|
40
|
+
* - `canTrailingExecute`: Whether the throttler can execute on the trailing edge
|
|
41
|
+
* - `executionCount`: Number of function executions that have been completed
|
|
42
|
+
* - `hasError`: Whether the last execution resulted in an error
|
|
43
|
+
* - `isPending`: Whether the throttler is waiting for the timeout to trigger execution
|
|
44
|
+
* - `isExecuting`: Whether an async function execution is currently in progress
|
|
45
|
+
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
46
|
+
* - `lastError`: The error from the most recent failed execution (if any)
|
|
47
|
+
* - `lastExecutionTime`: Timestamp of the last execution
|
|
48
|
+
* - `lastResult`: The result from the most recent successful execution
|
|
49
|
+
* - `nextExecutionTime`: Timestamp of the next allowed execution
|
|
50
|
+
* - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing')
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```tsx
|
|
54
|
+
* // Default behavior - no reactive state subscriptions
|
|
55
|
+
* const { maybeExecute } = createAsyncThrottler(
|
|
56
|
+
* async (id: string) => {
|
|
57
|
+
* const data = await api.fetchData(id);
|
|
58
|
+
* return data;
|
|
59
|
+
* },
|
|
60
|
+
* { wait: 1000 }
|
|
61
|
+
* );
|
|
62
|
+
*
|
|
63
|
+
* // Opt-in to re-render when isPending or isExecuting changes (optimized for loading states)
|
|
64
|
+
* const throttler = createAsyncThrottler(
|
|
65
|
+
* async (query) => {
|
|
66
|
+
* const result = await searchAPI(query);
|
|
67
|
+
* return result;
|
|
68
|
+
* },
|
|
69
|
+
* { wait: 2000 },
|
|
70
|
+
* (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })
|
|
71
|
+
* );
|
|
72
|
+
*
|
|
73
|
+
* // Opt-in to re-render when error state changes (optimized for error handling)
|
|
74
|
+
* const throttler = createAsyncThrottler(
|
|
75
|
+
* async (query) => {
|
|
76
|
+
* const result = await searchAPI(query);
|
|
77
|
+
* return result;
|
|
78
|
+
* },
|
|
79
|
+
* {
|
|
80
|
+
* wait: 2000,
|
|
81
|
+
* leading: true, // Execute immediately on first call
|
|
82
|
+
* trailing: false, // Skip trailing edge updates
|
|
83
|
+
* onError: (error) => {
|
|
84
|
+
* console.error('API call failed:', error);
|
|
85
|
+
* }
|
|
86
|
+
* },
|
|
87
|
+
* (state) => ({ hasError: state.hasError, lastError: state.lastError })
|
|
88
|
+
* );
|
|
89
|
+
*
|
|
90
|
+
* // Access the selected state (will be empty object {} unless selector provided)
|
|
91
|
+
* const { isPending, isExecuting } = throttler.state();
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
function createAsyncThrottler(fn, options, selector = () => ({})) {
|
|
95
|
+
const asyncThrottler = new AsyncThrottler(fn, {
|
|
96
|
+
...useDefaultPacerOptions().asyncThrottler,
|
|
97
|
+
...options
|
|
98
|
+
});
|
|
99
|
+
const state = useStore(asyncThrottler.store, selector);
|
|
100
|
+
return {
|
|
101
|
+
...asyncThrottler,
|
|
102
|
+
state
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
//#endregion
|
|
107
|
+
export { createAsyncThrottler };
|
|
108
|
+
//# sourceMappingURL=createAsyncThrottler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createAsyncThrottler.js","names":[],"sources":["../../src/async-throttler/createAsyncThrottler.ts"],"sourcesContent":["import { AsyncThrottler } from '@tanstack/pacer/async-throttler'\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 { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncThrottlerOptions,\n AsyncThrottlerState,\n} from '@tanstack/pacer/async-throttler'\n\nexport interface SolidAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncThrottler<TFn>, 'store'> {\n /**\n * Reactive state that will be updated when the throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, 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<AsyncThrottlerState<TFn>>>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncThrottler` instance to limit how often an async function can execute.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Async throttling ensures an async function executes at most once within a specified time window,\n * regardless of how many times it is called. This is useful for rate-limiting expensive API calls,\n * database operations, or other async tasks.\n *\n * Unlike the non-async Throttler, this async version supports returning values from the throttled function,\n * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call\n * instead of setting the result on a state variable from within the throttled function.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and throttler 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 AsyncThrottler 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 * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `hasError`: Whether the last execution resulted in an error\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `isExecuting`: Whether an async function execution is currently in progress\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastError`: The error from the most recent failed execution (if any)\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `lastResult`: The result from the most recent successful execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const { maybeExecute } = createAsyncThrottler(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data;\n * },\n * { wait: 1000 }\n * );\n *\n * // Opt-in to re-render when isPending or isExecuting changes (optimized for loading states)\n * const throttler = createAsyncThrottler(\n * async (query) => {\n * const result = await searchAPI(query);\n * return result;\n * },\n * { wait: 2000 },\n * (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })\n * );\n *\n * // Opt-in to re-render when error state changes (optimized for error handling)\n * const throttler = createAsyncThrottler(\n * async (query) => {\n * const result = await searchAPI(query);\n * return result;\n * },\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false, // Skip trailing edge updates\n * onError: (error) => {\n * console.error('API call failed:', error);\n * }\n * },\n * (state) => ({ hasError: state.hasError, lastError: state.lastError })\n * );\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending, isExecuting } = throttler.state();\n * ```\n */\nexport function createAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AsyncThrottlerOptions<TFn>,\n selector: (state: AsyncThrottlerState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncThrottler,\n ...options,\n } as AsyncThrottlerOptions<TFn>\n\n const asyncThrottler = new AsyncThrottler(fn, mergedOptions)\n\n const state = useStore(asyncThrottler.store, selector)\n\n return {\n ...asyncThrottler,\n state,\n } as SolidAsyncThrottler<TFn, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqHA,SAAgB,qBAId,IACA,SACA,kBACG,EAAE,GACgC;CAMrC,MAAM,iBAAiB,IAAI,eAAe,IALpB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ,CAE2D;CAE5D,MAAM,QAAQ,SAAS,eAAe,OAAO,SAAS;AAEtD,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const require_createAsyncThrottler = require('./createAsyncThrottler.cjs');
|
|
2
|
+
|
|
3
|
+
exports.createAsyncThrottler = require_createAsyncThrottler.createAsyncThrottler;
|
|
4
|
+
var __tanstack_pacer_async_throttler = require("@tanstack/pacer/async-throttler");
|
|
5
|
+
Object.keys(__tanstack_pacer_async_throttler).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_throttler[k]; }
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const require_PacerProvider = require('../provider/PacerProvider.cjs');
|
|
2
|
+
let __tanstack_solid_store = require("@tanstack/solid-store");
|
|
3
|
+
let __tanstack_pacer_batcher = require("@tanstack/pacer/batcher");
|
|
4
|
+
|
|
5
|
+
//#region src/batcher/createBatcher.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Batch processing of items using the provided `fn` function
|
|
11
|
+
* - Configurable batch size and wait time
|
|
12
|
+
* - Custom batch processing logic via getShouldExecute
|
|
13
|
+
* - Event callbacks for monitoring batch operations
|
|
14
|
+
* - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity
|
|
15
|
+
*
|
|
16
|
+
* The batcher collects items and processes them in batches based on:
|
|
17
|
+
* - Maximum batch size
|
|
18
|
+
* - Time-based batching (process after X milliseconds)
|
|
19
|
+
* - Custom batch processing logic via getShouldExecute
|
|
20
|
+
*
|
|
21
|
+
* ## State Management and Selector
|
|
22
|
+
*
|
|
23
|
+
* The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
|
|
24
|
+
* to specify which state changes will trigger a re-render, optimizing performance by preventing
|
|
25
|
+
* unnecessary re-renders when irrelevant state changes occur.
|
|
26
|
+
*
|
|
27
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
28
|
+
* tracking by providing a selector function. This prevents unnecessary re-renders and gives you
|
|
29
|
+
* full control over when your component updates. Only when you provide a selector will the
|
|
30
|
+
* component re-render when the selected state values change.
|
|
31
|
+
*
|
|
32
|
+
* Available state properties:
|
|
33
|
+
* - `executionCount`: Number of batch executions that have been completed
|
|
34
|
+
* - `isRunning`: Whether the batcher is currently running (not stopped)
|
|
35
|
+
* - `items`: Array of items currently queued for batching
|
|
36
|
+
* - `totalItemsProcessed`: Total number of individual items that have been processed across all batches
|
|
37
|
+
*
|
|
38
|
+
* Example usage:
|
|
39
|
+
* ```tsx
|
|
40
|
+
* // Default behavior - no reactive state subscriptions
|
|
41
|
+
* const batcher = createBatcher(
|
|
42
|
+
* (items) => {
|
|
43
|
+
* // Process batch of items
|
|
44
|
+
* console.log('Processing batch:', items);
|
|
45
|
+
* },
|
|
46
|
+
* {
|
|
47
|
+
* maxSize: 5,
|
|
48
|
+
* wait: 2000,
|
|
49
|
+
* onExecute: (batcher) => console.log('Batch executed'),
|
|
50
|
+
* getShouldExecute: (items) => items.length >= 3
|
|
51
|
+
* }
|
|
52
|
+
* );
|
|
53
|
+
*
|
|
54
|
+
* // Opt-in to re-render when items or isRunning changes (optimized for UI updates)
|
|
55
|
+
* const batcher = createBatcher(
|
|
56
|
+
* (items) => console.log('Processing batch:', items),
|
|
57
|
+
* { maxSize: 5, wait: 2000 },
|
|
58
|
+
* (state) => ({ items: state.items, isRunning: state.isRunning })
|
|
59
|
+
* );
|
|
60
|
+
*
|
|
61
|
+
* // Opt-in to re-render when execution metrics change (optimized for tracking progress)
|
|
62
|
+
* const batcher = createBatcher(
|
|
63
|
+
* (items) => console.log('Processing batch:', items),
|
|
64
|
+
* { maxSize: 5, wait: 2000 },
|
|
65
|
+
* (state) => ({
|
|
66
|
+
* executionCount: state.executionCount,
|
|
67
|
+
* totalItemsProcessed: state.totalItemsProcessed
|
|
68
|
+
* })
|
|
69
|
+
* );
|
|
70
|
+
*
|
|
71
|
+
* // Add items to batch
|
|
72
|
+
* batcher.addItem('task1');
|
|
73
|
+
* batcher.addItem('task2');
|
|
74
|
+
*
|
|
75
|
+
* // Control the batcher
|
|
76
|
+
* batcher.stop(); // Pause processing
|
|
77
|
+
* batcher.start(); // Resume processing
|
|
78
|
+
*
|
|
79
|
+
* // Access the selected state (will be empty object {} unless selector provided)
|
|
80
|
+
* const { items, isRunning } = batcher.state();
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
function createBatcher(fn, options = {}, selector = () => ({})) {
|
|
84
|
+
const batcher = new __tanstack_pacer_batcher.Batcher(fn, {
|
|
85
|
+
...require_PacerProvider.useDefaultPacerOptions().batcher,
|
|
86
|
+
...options
|
|
87
|
+
});
|
|
88
|
+
const state = (0, __tanstack_solid_store.useStore)(batcher.store, selector);
|
|
89
|
+
return {
|
|
90
|
+
...batcher,
|
|
91
|
+
state
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
exports.createBatcher = createBatcher;
|
|
97
|
+
//# sourceMappingURL=createBatcher.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBatcher.cjs","names":["Batcher","useDefaultPacerOptions"],"sources":["../../src/batcher/createBatcher.ts"],"sourcesContent":["import { Batcher } from '@tanstack/pacer/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 { BatcherOptions, BatcherState } from '@tanstack/pacer/batcher'\n\nexport interface SolidBatcher<TValue, TSelected = {}> extends Omit<\n Batcher<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<BatcherState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Batch processing of items using the provided `fn` function\n * - Configurable batch size and wait time\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\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\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\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 * - `executionCount`: Number of batch executions that have been completed\n * - `isRunning`: Whether the batcher is currently running (not stopped)\n * - `items`: Array of items currently queued for batching\n * - `totalItemsProcessed`: Total number of individual items that have been processed across all batches\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const batcher = createBatcher(\n * (items) => {\n * // Process batch of items\n * console.log('Processing batch:', items);\n * },\n * {\n * maxSize: 5,\n * wait: 2000,\n * onExecute: (batcher) => console.log('Batch executed'),\n * getShouldExecute: (items) => items.length >= 3\n * }\n * );\n *\n * // Opt-in to re-render when items or isRunning changes (optimized for UI updates)\n * const batcher = createBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({ items: state.items, isRunning: state.isRunning })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for tracking progress)\n * const batcher = createBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * totalItemsProcessed: state.totalItemsProcessed\n * })\n * );\n *\n * // Add items to batch\n * batcher.addItem('task1');\n * batcher.addItem('task2');\n *\n * // Control the batcher\n * batcher.stop(); // Pause processing\n * batcher.start(); // Resume processing\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isRunning } = batcher.state();\n * ```\n */\nexport function createBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => void,\n options: BatcherOptions<TValue> = {},\n selector: (state: BatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): SolidBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().batcher,\n ...options,\n } as BatcherOptions<TValue>\n\n const batcher = new Batcher(fn, mergedOptions)\n\n const state = useStore(batcher.store, selector)\n return {\n ...batcher,\n state,\n } as SolidBatcher<TValue, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,SAAgB,cACd,IACA,UAAkC,EAAE,EACpC,kBACG,EAAE,GAC4B;CAMjC,MAAM,UAAU,IAAIA,iCAAQ,IALN;EACpB,GAAGC,8CAAwB,CAAC;EAC5B,GAAG;EACJ,CAE6C;CAE9C,MAAM,6CAAiB,QAAQ,OAAO,SAAS;AAC/C,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -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 { Store } from "@tanstack/solid-store";
|
|
2
|
+
import { Accessor } from "solid-js";
|
|
3
|
+
import { Batcher, BatcherOptions, BatcherState } from "@tanstack/pacer/batcher";
|
|
4
|
+
|
|
5
|
+
//#region src/batcher/createBatcher.d.ts
|
|
6
|
+
interface SolidBatcher<TValue, TSelected = {}> extends Omit<Batcher<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<BatcherState<TValue>>>;
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.
|
|
@@ -92,4 +94,7 @@ export interface SolidBatcher<TValue, TSelected = {}> extends Omit<Batcher<TValu
|
|
|
92
94
|
* const { items, isRunning } = batcher.state();
|
|
93
95
|
* ```
|
|
94
96
|
*/
|
|
95
|
-
|
|
97
|
+
declare function createBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => void, options?: BatcherOptions<TValue>, selector?: (state: BatcherState<TValue>) => TSelected): SolidBatcher<TValue, TSelected>;
|
|
98
|
+
//#endregion
|
|
99
|
+
export { SolidBatcher, createBatcher };
|
|
100
|
+
//# sourceMappingURL=createBatcher.d.cts.map
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Store } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { Accessor } from "solid-js";
|
|
2
|
+
import { Store } from "@tanstack/solid-store";
|
|
3
|
+
import { Batcher, BatcherOptions, BatcherState } from "@tanstack/pacer/batcher";
|
|
4
|
+
|
|
5
|
+
//#region src/batcher/createBatcher.d.ts
|
|
6
|
+
interface SolidBatcher<TValue, TSelected = {}> extends Omit<Batcher<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<BatcherState<TValue>>>;
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.
|
|
@@ -92,4 +94,7 @@ export interface SolidBatcher<TValue, TSelected = {}> extends Omit<Batcher<TValu
|
|
|
92
94
|
* const { items, isRunning } = batcher.state();
|
|
93
95
|
* ```
|
|
94
96
|
*/
|
|
95
|
-
|
|
97
|
+
declare function createBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => void, options?: BatcherOptions<TValue>, selector?: (state: BatcherState<TValue>) => TSelected): SolidBatcher<TValue, TSelected>;
|
|
98
|
+
//#endregion
|
|
99
|
+
export { SolidBatcher, createBatcher };
|
|
100
|
+
//# sourceMappingURL=createBatcher.d.ts.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { useDefaultPacerOptions } from "../provider/PacerProvider.js";
|
|
2
|
+
import { useStore } from "@tanstack/solid-store";
|
|
3
|
+
import { Batcher } from "@tanstack/pacer/batcher";
|
|
4
|
+
|
|
5
|
+
//#region src/batcher/createBatcher.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Batch processing of items using the provided `fn` function
|
|
11
|
+
* - Configurable batch size and wait time
|
|
12
|
+
* - Custom batch processing logic via getShouldExecute
|
|
13
|
+
* - Event callbacks for monitoring batch operations
|
|
14
|
+
* - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity
|
|
15
|
+
*
|
|
16
|
+
* The batcher collects items and processes them in batches based on:
|
|
17
|
+
* - Maximum batch size
|
|
18
|
+
* - Time-based batching (process after X milliseconds)
|
|
19
|
+
* - Custom batch processing logic via getShouldExecute
|
|
20
|
+
*
|
|
21
|
+
* ## State Management and Selector
|
|
22
|
+
*
|
|
23
|
+
* The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
|
|
24
|
+
* to specify which state changes will trigger a re-render, optimizing performance by preventing
|
|
25
|
+
* unnecessary re-renders when irrelevant state changes occur.
|
|
26
|
+
*
|
|
27
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
28
|
+
* tracking by providing a selector function. This prevents unnecessary re-renders and gives you
|
|
29
|
+
* full control over when your component updates. Only when you provide a selector will the
|
|
30
|
+
* component re-render when the selected state values change.
|
|
31
|
+
*
|
|
32
|
+
* Available state properties:
|
|
33
|
+
* - `executionCount`: Number of batch executions that have been completed
|
|
34
|
+
* - `isRunning`: Whether the batcher is currently running (not stopped)
|
|
35
|
+
* - `items`: Array of items currently queued for batching
|
|
36
|
+
* - `totalItemsProcessed`: Total number of individual items that have been processed across all batches
|
|
37
|
+
*
|
|
38
|
+
* Example usage:
|
|
39
|
+
* ```tsx
|
|
40
|
+
* // Default behavior - no reactive state subscriptions
|
|
41
|
+
* const batcher = createBatcher(
|
|
42
|
+
* (items) => {
|
|
43
|
+
* // Process batch of items
|
|
44
|
+
* console.log('Processing batch:', items);
|
|
45
|
+
* },
|
|
46
|
+
* {
|
|
47
|
+
* maxSize: 5,
|
|
48
|
+
* wait: 2000,
|
|
49
|
+
* onExecute: (batcher) => console.log('Batch executed'),
|
|
50
|
+
* getShouldExecute: (items) => items.length >= 3
|
|
51
|
+
* }
|
|
52
|
+
* );
|
|
53
|
+
*
|
|
54
|
+
* // Opt-in to re-render when items or isRunning changes (optimized for UI updates)
|
|
55
|
+
* const batcher = createBatcher(
|
|
56
|
+
* (items) => console.log('Processing batch:', items),
|
|
57
|
+
* { maxSize: 5, wait: 2000 },
|
|
58
|
+
* (state) => ({ items: state.items, isRunning: state.isRunning })
|
|
59
|
+
* );
|
|
60
|
+
*
|
|
61
|
+
* // Opt-in to re-render when execution metrics change (optimized for tracking progress)
|
|
62
|
+
* const batcher = createBatcher(
|
|
63
|
+
* (items) => console.log('Processing batch:', items),
|
|
64
|
+
* { maxSize: 5, wait: 2000 },
|
|
65
|
+
* (state) => ({
|
|
66
|
+
* executionCount: state.executionCount,
|
|
67
|
+
* totalItemsProcessed: state.totalItemsProcessed
|
|
68
|
+
* })
|
|
69
|
+
* );
|
|
70
|
+
*
|
|
71
|
+
* // Add items to batch
|
|
72
|
+
* batcher.addItem('task1');
|
|
73
|
+
* batcher.addItem('task2');
|
|
74
|
+
*
|
|
75
|
+
* // Control the batcher
|
|
76
|
+
* batcher.stop(); // Pause processing
|
|
77
|
+
* batcher.start(); // Resume processing
|
|
78
|
+
*
|
|
79
|
+
* // Access the selected state (will be empty object {} unless selector provided)
|
|
80
|
+
* const { items, isRunning } = batcher.state();
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
function createBatcher(fn, options = {}, selector = () => ({})) {
|
|
84
|
+
const batcher = new Batcher(fn, {
|
|
85
|
+
...useDefaultPacerOptions().batcher,
|
|
86
|
+
...options
|
|
87
|
+
});
|
|
88
|
+
const state = useStore(batcher.store, selector);
|
|
89
|
+
return {
|
|
90
|
+
...batcher,
|
|
91
|
+
state
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
export { createBatcher };
|
|
97
|
+
//# sourceMappingURL=createBatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBatcher.js","names":[],"sources":["../../src/batcher/createBatcher.ts"],"sourcesContent":["import { Batcher } from '@tanstack/pacer/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 { BatcherOptions, BatcherState } from '@tanstack/pacer/batcher'\n\nexport interface SolidBatcher<TValue, TSelected = {}> extends Omit<\n Batcher<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<BatcherState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Batch processing of items using the provided `fn` function\n * - Configurable batch size and wait time\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\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\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\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 * - `executionCount`: Number of batch executions that have been completed\n * - `isRunning`: Whether the batcher is currently running (not stopped)\n * - `items`: Array of items currently queued for batching\n * - `totalItemsProcessed`: Total number of individual items that have been processed across all batches\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const batcher = createBatcher(\n * (items) => {\n * // Process batch of items\n * console.log('Processing batch:', items);\n * },\n * {\n * maxSize: 5,\n * wait: 2000,\n * onExecute: (batcher) => console.log('Batch executed'),\n * getShouldExecute: (items) => items.length >= 3\n * }\n * );\n *\n * // Opt-in to re-render when items or isRunning changes (optimized for UI updates)\n * const batcher = createBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({ items: state.items, isRunning: state.isRunning })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for tracking progress)\n * const batcher = createBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * totalItemsProcessed: state.totalItemsProcessed\n * })\n * );\n *\n * // Add items to batch\n * batcher.addItem('task1');\n * batcher.addItem('task2');\n *\n * // Control the batcher\n * batcher.stop(); // Pause processing\n * batcher.start(); // Resume processing\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isRunning } = batcher.state();\n * ```\n */\nexport function createBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => void,\n options: BatcherOptions<TValue> = {},\n selector: (state: BatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): SolidBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().batcher,\n ...options,\n } as BatcherOptions<TValue>\n\n const batcher = new Batcher(fn, mergedOptions)\n\n const state = useStore(batcher.store, selector)\n return {\n ...batcher,\n state,\n } as SolidBatcher<TValue, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,SAAgB,cACd,IACA,UAAkC,EAAE,EACpC,kBACG,EAAE,GAC4B;CAMjC,MAAM,UAAU,IAAI,QAAQ,IALN;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ,CAE6C;CAE9C,MAAM,QAAQ,SAAS,QAAQ,OAAO,SAAS;AAC/C,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const require_createBatcher = require('./createBatcher.cjs');
|
|
2
|
+
|
|
3
|
+
exports.createBatcher = require_createBatcher.createBatcher;
|
|
4
|
+
var __tanstack_pacer_batcher = require("@tanstack/pacer/batcher");
|
|
5
|
+
Object.keys(__tanstack_pacer_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_batcher[k]; }
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const require_createDebouncer = require('./createDebouncer.cjs');
|
|
2
|
+
let solid_js = require("solid-js");
|
|
3
|
+
|
|
4
|
+
//#region src/debouncer/createDebouncedSignal.ts
|
|
5
|
+
/**
|
|
6
|
+
* A Solid hook that creates a debounced state value, combining Solid's createSignal with debouncing functionality.
|
|
7
|
+
* This hook provides both the current debounced value and methods to update it.
|
|
8
|
+
*
|
|
9
|
+
* The state value is only updated after the specified wait time has elapsed since the last update attempt.
|
|
10
|
+
* If another update is attempted before the wait time expires, the timer resets and starts waiting again.
|
|
11
|
+
* This is useful for handling frequent state updates that should be throttled, like search input values
|
|
12
|
+
* or window resize dimensions.
|
|
13
|
+
*
|
|
14
|
+
* The hook returns a tuple containing:
|
|
15
|
+
* - The current debounced value accessor
|
|
16
|
+
* - A function to update the debounced value
|
|
17
|
+
* - The debouncer instance with additional control methods and state signals
|
|
18
|
+
*
|
|
19
|
+
* ## State Management and Selector
|
|
20
|
+
*
|
|
21
|
+
* The hook uses TanStack Store for reactive state management via the underlying debouncer instance.
|
|
22
|
+
* The `selector` parameter allows you to specify which debouncer state changes will trigger reactive updates,
|
|
23
|
+
* optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
|
|
24
|
+
*
|
|
25
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
26
|
+
* tracking by providing a selector function. This prevents unnecessary reactive updates and gives you
|
|
27
|
+
* full control over when your component subscribes to state changes. Only when you provide a selector will
|
|
28
|
+
* the reactive system track the selected state values.
|
|
29
|
+
*
|
|
30
|
+
* Available debouncer state properties:
|
|
31
|
+
* - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
|
|
32
|
+
* - `executionCount`: Number of function executions that have been completed
|
|
33
|
+
* - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
|
|
34
|
+
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
35
|
+
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```tsx
|
|
39
|
+
* // Default behavior - no reactive state subscriptions
|
|
40
|
+
* const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {
|
|
41
|
+
* wait: 500 // Wait 500ms after last keystroke
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Opt-in to reactive updates when pending state changes (optimized for loading indicators)
|
|
45
|
+
* const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal(
|
|
46
|
+
* '',
|
|
47
|
+
* { wait: 500 },
|
|
48
|
+
* (state) => ({ isPending: state.isPending })
|
|
49
|
+
* );
|
|
50
|
+
*
|
|
51
|
+
* // Opt-in to reactive updates when execution count changes (optimized for tracking executions)
|
|
52
|
+
* const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal(
|
|
53
|
+
* '',
|
|
54
|
+
* { wait: 500 },
|
|
55
|
+
* (state) => ({ executionCount: state.executionCount })
|
|
56
|
+
* );
|
|
57
|
+
*
|
|
58
|
+
* // Update value - will be debounced
|
|
59
|
+
* const handleChange = (e) => {
|
|
60
|
+
* setSearchTerm(e.target.value);
|
|
61
|
+
* };
|
|
62
|
+
*
|
|
63
|
+
* // Access debouncer state via signals
|
|
64
|
+
* console.log('Executions:', debouncer.state().executionCount);
|
|
65
|
+
* console.log('Is pending:', debouncer.state().isPending);
|
|
66
|
+
*
|
|
67
|
+
* // In onExecute callback, use get* methods
|
|
68
|
+
* const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {
|
|
69
|
+
* wait: 500,
|
|
70
|
+
* onExecute: (debouncer) => {
|
|
71
|
+
* console.log('Total executions:', debouncer.getExecutionCount());
|
|
72
|
+
* }
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
function createDebouncedSignal(value, initialOptions, selector) {
|
|
77
|
+
const [debouncedValue, setDebouncedValue] = (0, solid_js.createSignal)(value);
|
|
78
|
+
const debouncer = require_createDebouncer.createDebouncer(setDebouncedValue, initialOptions, selector);
|
|
79
|
+
return [
|
|
80
|
+
debouncedValue,
|
|
81
|
+
debouncer.maybeExecute,
|
|
82
|
+
debouncer
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
exports.createDebouncedSignal = createDebouncedSignal;
|
|
88
|
+
//# sourceMappingURL=createDebouncedSignal.cjs.map
|