@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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AsyncBatcher } from '@tanstack/pacer/async-batcher'
|
|
2
2
|
import { useStore } from '@tanstack/solid-store'
|
|
3
|
+
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
3
4
|
import type { Store } from '@tanstack/solid-store'
|
|
4
5
|
import type { Accessor } from 'solid-js'
|
|
5
6
|
import type {
|
|
@@ -7,8 +8,10 @@ import type {
|
|
|
7
8
|
AsyncBatcherState,
|
|
8
9
|
} from '@tanstack/pacer/async-batcher'
|
|
9
10
|
|
|
10
|
-
export interface SolidAsyncBatcher<TValue, TSelected = {}>
|
|
11
|
-
|
|
11
|
+
export interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<
|
|
12
|
+
AsyncBatcher<TValue>,
|
|
13
|
+
'store'
|
|
14
|
+
> {
|
|
12
15
|
/**
|
|
13
16
|
* Reactive state that will be updated when the batcher state changes
|
|
14
17
|
*
|
|
@@ -127,11 +130,16 @@ export interface SolidAsyncBatcher<TValue, TSelected = {}>
|
|
|
127
130
|
*/
|
|
128
131
|
export function createAsyncBatcher<TValue, TSelected = {}>(
|
|
129
132
|
fn: (items: Array<TValue>) => Promise<any>,
|
|
130
|
-
|
|
133
|
+
options: AsyncBatcherOptions<TValue> = {},
|
|
131
134
|
selector: (state: AsyncBatcherState<TValue>) => TSelected = () =>
|
|
132
135
|
({}) as TSelected,
|
|
133
136
|
): SolidAsyncBatcher<TValue, TSelected> {
|
|
134
|
-
const
|
|
137
|
+
const mergedOptions = {
|
|
138
|
+
...useDefaultPacerOptions().asyncBatcher,
|
|
139
|
+
...options,
|
|
140
|
+
} as AsyncBatcherOptions<TValue>
|
|
141
|
+
|
|
142
|
+
const asyncBatcher = new AsyncBatcher<TValue>(fn, mergedOptions)
|
|
135
143
|
|
|
136
144
|
const state = useStore(asyncBatcher.store, selector)
|
|
137
145
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AsyncDebouncer } from '@tanstack/pacer/async-debouncer'
|
|
2
2
|
import { useStore } from '@tanstack/solid-store'
|
|
3
3
|
import { createEffect, onCleanup } from 'solid-js'
|
|
4
|
+
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
4
5
|
import type { Store } from '@tanstack/solid-store'
|
|
5
6
|
import type { Accessor } from 'solid-js'
|
|
6
7
|
import type {
|
|
@@ -120,11 +121,16 @@ export function createAsyncDebouncer<
|
|
|
120
121
|
TSelected = {},
|
|
121
122
|
>(
|
|
122
123
|
fn: TFn,
|
|
123
|
-
|
|
124
|
+
options: AsyncDebouncerOptions<TFn>,
|
|
124
125
|
selector: (state: AsyncDebouncerState<TFn>) => TSelected = () =>
|
|
125
126
|
({}) as TSelected,
|
|
126
127
|
): SolidAsyncDebouncer<TFn, TSelected> {
|
|
127
|
-
const
|
|
128
|
+
const mergedOptions = {
|
|
129
|
+
...useDefaultPacerOptions().asyncDebouncer,
|
|
130
|
+
...options,
|
|
131
|
+
} as AsyncDebouncerOptions<TFn>
|
|
132
|
+
|
|
133
|
+
const asyncDebouncer = new AsyncDebouncer<TFn>(fn, mergedOptions)
|
|
128
134
|
|
|
129
135
|
const state = useStore(asyncDebouncer.store, selector)
|
|
130
136
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AsyncQueuer } from '@tanstack/pacer/async-queuer'
|
|
2
2
|
import { useStore } from '@tanstack/solid-store'
|
|
3
|
+
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
3
4
|
import type { Store } from '@tanstack/solid-store'
|
|
4
5
|
import type { Accessor } from 'solid-js'
|
|
5
6
|
import type {
|
|
@@ -7,8 +8,10 @@ import type {
|
|
|
7
8
|
AsyncQueuerState,
|
|
8
9
|
} from '@tanstack/pacer/async-queuer'
|
|
9
10
|
|
|
10
|
-
export interface SolidAsyncQueuer<TValue, TSelected = {}>
|
|
11
|
-
|
|
11
|
+
export interface SolidAsyncQueuer<TValue, TSelected = {}> extends Omit<
|
|
12
|
+
AsyncQueuer<TValue>,
|
|
13
|
+
'store'
|
|
14
|
+
> {
|
|
12
15
|
/**
|
|
13
16
|
* Reactive state that will be updated when the queuer state changes
|
|
14
17
|
*
|
|
@@ -119,11 +122,16 @@ export interface SolidAsyncQueuer<TValue, TSelected = {}>
|
|
|
119
122
|
*/
|
|
120
123
|
export function createAsyncQueuer<TValue, TSelected = {}>(
|
|
121
124
|
fn: (value: TValue) => Promise<any>,
|
|
122
|
-
|
|
125
|
+
options: AsyncQueuerOptions<TValue> = {},
|
|
123
126
|
selector: (state: AsyncQueuerState<TValue>) => TSelected = () =>
|
|
124
127
|
({}) as TSelected,
|
|
125
128
|
): SolidAsyncQueuer<TValue, TSelected> {
|
|
126
|
-
const
|
|
129
|
+
const mergedOptions = {
|
|
130
|
+
...useDefaultPacerOptions().asyncQueuer,
|
|
131
|
+
...options,
|
|
132
|
+
} as AsyncQueuerOptions<TValue>
|
|
133
|
+
|
|
134
|
+
const asyncQueuer = new AsyncQueuer<TValue>(fn, mergedOptions)
|
|
127
135
|
|
|
128
136
|
const state = useStore(asyncQueuer.store, selector)
|
|
129
137
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AsyncRateLimiter } from '@tanstack/pacer/async-rate-limiter'
|
|
2
2
|
import { useStore } from '@tanstack/solid-store'
|
|
3
|
+
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
3
4
|
import type { Store } from '@tanstack/solid-store'
|
|
4
5
|
import type { Accessor } from 'solid-js'
|
|
5
6
|
import type { AnyAsyncFunction } from '@tanstack/pacer/types'
|
|
@@ -131,11 +132,16 @@ export function createAsyncRateLimiter<
|
|
|
131
132
|
TSelected = {},
|
|
132
133
|
>(
|
|
133
134
|
fn: TFn,
|
|
134
|
-
|
|
135
|
+
options: AsyncRateLimiterOptions<TFn>,
|
|
135
136
|
selector: (state: AsyncRateLimiterState<TFn>) => TSelected = () =>
|
|
136
137
|
({}) as TSelected,
|
|
137
138
|
): SolidAsyncRateLimiter<TFn, TSelected> {
|
|
138
|
-
const
|
|
139
|
+
const mergedOptions = {
|
|
140
|
+
...useDefaultPacerOptions().asyncRateLimiter,
|
|
141
|
+
...options,
|
|
142
|
+
} as AsyncRateLimiterOptions<TFn>
|
|
143
|
+
|
|
144
|
+
const asyncRateLimiter = new AsyncRateLimiter<TFn>(fn, mergedOptions)
|
|
139
145
|
|
|
140
146
|
const state = useStore(asyncRateLimiter.store, selector)
|
|
141
147
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AsyncThrottler } from '@tanstack/pacer/async-throttler'
|
|
2
2
|
import { useStore } from '@tanstack/solid-store'
|
|
3
|
+
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
3
4
|
import type { Store } from '@tanstack/solid-store'
|
|
4
5
|
import type { Accessor } from 'solid-js'
|
|
5
6
|
import type { AnyAsyncFunction } from '@tanstack/pacer/types'
|
|
@@ -119,11 +120,16 @@ export function createAsyncThrottler<
|
|
|
119
120
|
TSelected = {},
|
|
120
121
|
>(
|
|
121
122
|
fn: TFn,
|
|
122
|
-
|
|
123
|
+
options: AsyncThrottlerOptions<TFn>,
|
|
123
124
|
selector: (state: AsyncThrottlerState<TFn>) => TSelected = () =>
|
|
124
125
|
({}) as TSelected,
|
|
125
126
|
): SolidAsyncThrottler<TFn, TSelected> {
|
|
126
|
-
const
|
|
127
|
+
const mergedOptions = {
|
|
128
|
+
...useDefaultPacerOptions().asyncThrottler,
|
|
129
|
+
...options,
|
|
130
|
+
} as AsyncThrottlerOptions<TFn>
|
|
131
|
+
|
|
132
|
+
const asyncThrottler = new AsyncThrottler(fn, mergedOptions)
|
|
127
133
|
|
|
128
134
|
const state = useStore(asyncThrottler.store, selector)
|
|
129
135
|
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Batcher } from '@tanstack/pacer/batcher'
|
|
2
2
|
import { useStore } from '@tanstack/solid-store'
|
|
3
|
+
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
3
4
|
import type { Store } from '@tanstack/solid-store'
|
|
4
5
|
import type { Accessor } from 'solid-js'
|
|
5
6
|
import type { BatcherOptions, BatcherState } from '@tanstack/pacer/batcher'
|
|
6
7
|
|
|
7
|
-
export interface SolidBatcher<TValue, TSelected = {}>
|
|
8
|
-
|
|
8
|
+
export interface SolidBatcher<TValue, TSelected = {}> extends Omit<
|
|
9
|
+
Batcher<TValue>,
|
|
10
|
+
'store'
|
|
11
|
+
> {
|
|
9
12
|
/**
|
|
10
13
|
* Reactive state that will be updated when the batcher state changes
|
|
11
14
|
*
|
|
@@ -99,11 +102,16 @@ export interface SolidBatcher<TValue, TSelected = {}>
|
|
|
99
102
|
*/
|
|
100
103
|
export function createBatcher<TValue, TSelected = {}>(
|
|
101
104
|
fn: (items: Array<TValue>) => void,
|
|
102
|
-
|
|
105
|
+
options: BatcherOptions<TValue> = {},
|
|
103
106
|
selector: (state: BatcherState<TValue>) => TSelected = () =>
|
|
104
107
|
({}) as TSelected,
|
|
105
108
|
): SolidBatcher<TValue, TSelected> {
|
|
106
|
-
const
|
|
109
|
+
const mergedOptions = {
|
|
110
|
+
...useDefaultPacerOptions().batcher,
|
|
111
|
+
...options,
|
|
112
|
+
} as BatcherOptions<TValue>
|
|
113
|
+
|
|
114
|
+
const batcher = new Batcher(fn, mergedOptions)
|
|
107
115
|
|
|
108
116
|
const state = useStore(batcher.store, selector)
|
|
109
117
|
return {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Debouncer } from '@tanstack/pacer/debouncer'
|
|
2
2
|
import { createEffect, onCleanup } from 'solid-js'
|
|
3
3
|
import { useStore } from '@tanstack/solid-store'
|
|
4
|
+
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
4
5
|
import type { Store } from '@tanstack/solid-store'
|
|
5
6
|
import type { Accessor } from 'solid-js'
|
|
6
7
|
import type { AnyFunction } from '@tanstack/pacer/types'
|
|
@@ -9,8 +10,10 @@ import type {
|
|
|
9
10
|
DebouncerState,
|
|
10
11
|
} from '@tanstack/pacer/debouncer'
|
|
11
12
|
|
|
12
|
-
export interface SolidDebouncer<
|
|
13
|
-
|
|
13
|
+
export interface SolidDebouncer<
|
|
14
|
+
TFn extends AnyFunction,
|
|
15
|
+
TSelected = {},
|
|
16
|
+
> extends Omit<Debouncer<TFn>, 'store'> {
|
|
14
17
|
/**
|
|
15
18
|
* Reactive state that will be updated when the debouncer state changes
|
|
16
19
|
*
|
|
@@ -102,10 +105,15 @@ export interface SolidDebouncer<TFn extends AnyFunction, TSelected = {}>
|
|
|
102
105
|
*/
|
|
103
106
|
export function createDebouncer<TFn extends AnyFunction, TSelected = {}>(
|
|
104
107
|
fn: TFn,
|
|
105
|
-
|
|
108
|
+
options: DebouncerOptions<TFn>,
|
|
106
109
|
selector: (state: DebouncerState<TFn>) => TSelected = () => ({}) as TSelected,
|
|
107
110
|
): SolidDebouncer<TFn, TSelected> {
|
|
108
|
-
const
|
|
111
|
+
const mergedOptions = {
|
|
112
|
+
...useDefaultPacerOptions().debouncer,
|
|
113
|
+
...options,
|
|
114
|
+
} as DebouncerOptions<TFn>
|
|
115
|
+
|
|
116
|
+
const asyncDebouncer = new Debouncer<TFn>(fn, mergedOptions)
|
|
109
117
|
|
|
110
118
|
const state = useStore(asyncDebouncer.store, selector)
|
|
111
119
|
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// re-export everything from the core pacer package
|
|
2
2
|
export * from '@tanstack/pacer'
|
|
3
3
|
|
|
4
|
+
// provider
|
|
5
|
+
export * from './provider/PacerProvider'
|
|
6
|
+
|
|
4
7
|
/**
|
|
5
8
|
* Export every hook individually - DON'T export from barrel files
|
|
6
9
|
*/
|
|
@@ -30,6 +33,7 @@ export * from './debouncer/createDebouncer'
|
|
|
30
33
|
|
|
31
34
|
// queuer
|
|
32
35
|
export * from './queuer/createQueuer'
|
|
36
|
+
export * from './queuer/createQueuedSignal'
|
|
33
37
|
|
|
34
38
|
// rate-limiter
|
|
35
39
|
export * from './rate-limiter/createRateLimiter'
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { createContext, useContext } from 'solid-js'
|
|
2
|
+
import type { JSX } from 'solid-js'
|
|
3
|
+
import type {
|
|
4
|
+
AnyAsyncFunction,
|
|
5
|
+
AnyFunction,
|
|
6
|
+
AsyncBatcherOptions,
|
|
7
|
+
AsyncDebouncerOptions,
|
|
8
|
+
AsyncQueuerOptions,
|
|
9
|
+
AsyncRateLimiterOptions,
|
|
10
|
+
AsyncThrottlerOptions,
|
|
11
|
+
BatcherOptions,
|
|
12
|
+
DebouncerOptions,
|
|
13
|
+
QueuerOptions,
|
|
14
|
+
RateLimiterOptions,
|
|
15
|
+
ThrottlerOptions,
|
|
16
|
+
} from '@tanstack/pacer'
|
|
17
|
+
|
|
18
|
+
export interface PacerProviderOptions {
|
|
19
|
+
asyncBatcher?: Partial<AsyncBatcherOptions<any>>
|
|
20
|
+
asyncDebouncer?: Partial<AsyncDebouncerOptions<AnyAsyncFunction>>
|
|
21
|
+
asyncQueuer?: Partial<AsyncQueuerOptions<any>>
|
|
22
|
+
asyncRateLimiter?: Partial<AsyncRateLimiterOptions<AnyAsyncFunction>>
|
|
23
|
+
asyncThrottler?: Partial<AsyncThrottlerOptions<AnyAsyncFunction>>
|
|
24
|
+
batcher?: Partial<BatcherOptions<any>>
|
|
25
|
+
debouncer?: Partial<DebouncerOptions<AnyFunction>>
|
|
26
|
+
queuer?: Partial<QueuerOptions<any>>
|
|
27
|
+
rateLimiter?: Partial<RateLimiterOptions<AnyFunction>>
|
|
28
|
+
throttler?: Partial<ThrottlerOptions<AnyFunction>>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface PacerContextValue {
|
|
32
|
+
defaultOptions: PacerProviderOptions
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const PacerContext = createContext<PacerContextValue | null>(null)
|
|
36
|
+
|
|
37
|
+
export interface PacerProviderProps {
|
|
38
|
+
children: JSX.Element
|
|
39
|
+
defaultOptions?: PacerProviderOptions
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const DEFAULT_OPTIONS: PacerProviderOptions = {}
|
|
43
|
+
|
|
44
|
+
export function PacerProvider(props: PacerProviderProps) {
|
|
45
|
+
const contextValue: PacerContextValue = {
|
|
46
|
+
defaultOptions: props.defaultOptions ?? DEFAULT_OPTIONS,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<PacerContext.Provider value={contextValue}>
|
|
51
|
+
{props.children}
|
|
52
|
+
</PacerContext.Provider>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function usePacerContext() {
|
|
57
|
+
return useContext(PacerContext)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function useDefaultPacerOptions() {
|
|
61
|
+
const context = useContext(PacerContext)
|
|
62
|
+
return context?.defaultOptions ?? {}
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './PacerProvider'
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { createQueuer } from './createQueuer'
|
|
2
|
+
import type { SolidQueuer } from './createQueuer'
|
|
3
|
+
import type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A Solid primitive that creates a queuer with managed state, combining Solid's signals with queuing functionality.
|
|
7
|
+
* This primitive provides both the current queue state and queue control methods.
|
|
8
|
+
*
|
|
9
|
+
* The queue state is automatically updated whenever items are added, removed, or reordered in the queue.
|
|
10
|
+
* All queue operations are reflected in the state array returned by the primitive.
|
|
11
|
+
*
|
|
12
|
+
* The queue can be started and stopped to automatically process items at a specified interval,
|
|
13
|
+
* making it useful as a scheduler. When started, it will process one item per tick, with an
|
|
14
|
+
* optional wait time between ticks.
|
|
15
|
+
*
|
|
16
|
+
* The primitive returns a tuple containing:
|
|
17
|
+
* - The current queue state as an array
|
|
18
|
+
* - The queue instance with methods for queue manipulation
|
|
19
|
+
*
|
|
20
|
+
* ## State Management and Selector
|
|
21
|
+
*
|
|
22
|
+
* The primitive uses Solid's reactive state management via the underlying queuer instance.
|
|
23
|
+
* The `selector` parameter allows you to specify which queuer state changes will trigger a re-render,
|
|
24
|
+
* optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur.
|
|
25
|
+
*
|
|
26
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
27
|
+
* tracking by providing a selector function. This prevents unnecessary re-renders and gives you
|
|
28
|
+
* full control over when your component updates. Only when you provide a selector will the
|
|
29
|
+
* component re-render when the selected state values change.
|
|
30
|
+
*
|
|
31
|
+
* Available queuer state properties:
|
|
32
|
+
* - `executionCount`: Number of items that have been processed by the queuer
|
|
33
|
+
* - `expirationCount`: Number of items that have been removed due to expiration
|
|
34
|
+
* - `isEmpty`: Whether the queuer has no items to process
|
|
35
|
+
* - `isFull`: Whether the queuer has reached its maximum capacity
|
|
36
|
+
* - `isIdle`: Whether the queuer is not currently processing any items
|
|
37
|
+
* - `isRunning`: Whether the queuer is active and will process items automatically
|
|
38
|
+
* - `items`: Array of items currently waiting to be processed
|
|
39
|
+
* - `itemTimestamps`: Timestamps when items were added for expiration tracking
|
|
40
|
+
* - `pendingTick`: Whether the queuer has a pending timeout for processing the next item
|
|
41
|
+
* - `rejectionCount`: Number of items that have been rejected from being added
|
|
42
|
+
* - `size`: Number of items currently in the queue
|
|
43
|
+
* - `status`: Current processing status ('idle' | 'running' | 'stopped')
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```tsx
|
|
47
|
+
* // Default behavior - no reactive state subscriptions
|
|
48
|
+
* const [items, addItem, queue] = createQueuedSignal(
|
|
49
|
+
* (item) => console.log('Processing:', item),
|
|
50
|
+
* {
|
|
51
|
+
* initialItems: ['item1', 'item2'],
|
|
52
|
+
* started: true,
|
|
53
|
+
* wait: 1000,
|
|
54
|
+
* getPriority: (item) => item.priority
|
|
55
|
+
* }
|
|
56
|
+
* );
|
|
57
|
+
*
|
|
58
|
+
* // Opt-in to re-render when queue contents change (optimized for displaying queue items)
|
|
59
|
+
* const [items, addItem, queue] = createQueuedSignal(
|
|
60
|
+
* (item) => console.log('Processing:', item),
|
|
61
|
+
* { started: true, wait: 1000 },
|
|
62
|
+
* (state) => ({
|
|
63
|
+
* items: state.items,
|
|
64
|
+
* size: state.size,
|
|
65
|
+
* isEmpty: state.isEmpty
|
|
66
|
+
* })
|
|
67
|
+
* );
|
|
68
|
+
*
|
|
69
|
+
* // Opt-in to re-render when processing state changes (optimized for loading indicators)
|
|
70
|
+
* const [items, addItem, queue] = createQueuedSignal(
|
|
71
|
+
* (item) => console.log('Processing:', item),
|
|
72
|
+
* { started: true, wait: 1000 },
|
|
73
|
+
* (state) => ({
|
|
74
|
+
* isRunning: state.isRunning,
|
|
75
|
+
* isIdle: state.isIdle,
|
|
76
|
+
* status: state.status,
|
|
77
|
+
* pendingTick: state.pendingTick
|
|
78
|
+
* })
|
|
79
|
+
* );
|
|
80
|
+
*
|
|
81
|
+
* // Opt-in to re-render when execution metrics change (optimized for stats display)
|
|
82
|
+
* const [items, addItem, queue] = createQueuedSignal(
|
|
83
|
+
* (item) => console.log('Processing:', item),
|
|
84
|
+
* { started: true, wait: 1000 },
|
|
85
|
+
* (state) => ({
|
|
86
|
+
* executionCount: state.executionCount,
|
|
87
|
+
* expirationCount: state.expirationCount,
|
|
88
|
+
* rejectionCount: state.rejectionCount
|
|
89
|
+
* })
|
|
90
|
+
* );
|
|
91
|
+
*
|
|
92
|
+
* // Add items to queue
|
|
93
|
+
* const handleAdd = (item) => {
|
|
94
|
+
* addItem(item);
|
|
95
|
+
* };
|
|
96
|
+
*
|
|
97
|
+
* // Start automatic processing
|
|
98
|
+
* const startProcessing = () => {
|
|
99
|
+
* queue.start();
|
|
100
|
+
* };
|
|
101
|
+
*
|
|
102
|
+
* // Stop automatic processing
|
|
103
|
+
* const stopProcessing = () => {
|
|
104
|
+
* queue.stop();
|
|
105
|
+
* };
|
|
106
|
+
*
|
|
107
|
+
* // Manual processing still available
|
|
108
|
+
* const handleProcess = () => {
|
|
109
|
+
* const nextItem = queue.getNextItem();
|
|
110
|
+
* if (nextItem) {
|
|
111
|
+
* processItem(nextItem);
|
|
112
|
+
* }
|
|
113
|
+
* };
|
|
114
|
+
*
|
|
115
|
+
* // Access the selected queuer state (will be empty object {} unless selector provided)
|
|
116
|
+
* const { size, isRunning, executionCount } = queue.state;
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export function createQueuedSignal<
|
|
120
|
+
TValue,
|
|
121
|
+
TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<
|
|
122
|
+
QueuerState<TValue>,
|
|
123
|
+
'items'
|
|
124
|
+
>,
|
|
125
|
+
>(
|
|
126
|
+
fn: (item: TValue) => void,
|
|
127
|
+
options: QueuerOptions<TValue> = {},
|
|
128
|
+
selector: (state: QueuerState<TValue>) => TSelected = (state) =>
|
|
129
|
+
({ items: state.items }) as TSelected,
|
|
130
|
+
): [
|
|
131
|
+
() => Array<TValue>,
|
|
132
|
+
SolidQueuer<TValue, TSelected>['addItem'],
|
|
133
|
+
SolidQueuer<TValue, TSelected>,
|
|
134
|
+
] {
|
|
135
|
+
const queue = createQueuer(fn, options, selector)
|
|
136
|
+
|
|
137
|
+
return [() => queue.state().items, queue.addItem, queue]
|
|
138
|
+
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Queuer } from '@tanstack/pacer/queuer'
|
|
2
2
|
import { useStore } from '@tanstack/solid-store'
|
|
3
|
+
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
3
4
|
import type { Store } from '@tanstack/solid-store'
|
|
4
5
|
import type { Accessor } from 'solid-js'
|
|
5
6
|
import type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'
|
|
6
7
|
|
|
7
|
-
export interface SolidQueuer<TValue, TSelected = {}>
|
|
8
|
-
|
|
8
|
+
export interface SolidQueuer<TValue, TSelected = {}> extends Omit<
|
|
9
|
+
Queuer<TValue>,
|
|
10
|
+
'store'
|
|
11
|
+
> {
|
|
9
12
|
/**
|
|
10
13
|
* Reactive state that will be updated when the queuer state changes
|
|
11
14
|
*
|
|
@@ -100,10 +103,15 @@ export interface SolidQueuer<TValue, TSelected = {}>
|
|
|
100
103
|
*/
|
|
101
104
|
export function createQueuer<TValue, TSelected = {}>(
|
|
102
105
|
fn: (item: TValue) => void,
|
|
103
|
-
|
|
106
|
+
options: QueuerOptions<TValue> = {},
|
|
104
107
|
selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,
|
|
105
108
|
): SolidQueuer<TValue, TSelected> {
|
|
106
|
-
const
|
|
109
|
+
const mergedOptions = {
|
|
110
|
+
...useDefaultPacerOptions().queuer,
|
|
111
|
+
...options,
|
|
112
|
+
} as QueuerOptions<TValue>
|
|
113
|
+
|
|
114
|
+
const queuer = new Queuer(fn, mergedOptions)
|
|
107
115
|
|
|
108
116
|
const state = useStore(queuer.store, selector)
|
|
109
117
|
|
package/src/queuer/index.ts
CHANGED
|
@@ -46,13 +46,9 @@ import type {
|
|
|
46
46
|
* the reactive system track the selected state values.
|
|
47
47
|
*
|
|
48
48
|
* Available rate limiter state properties:
|
|
49
|
-
* - `
|
|
50
|
-
* - `
|
|
51
|
-
* - `
|
|
52
|
-
* - `nextWindowStart`: Unix timestamp when the next window will start
|
|
53
|
-
* - `msUntilNextWindow`: Milliseconds until the next window starts
|
|
54
|
-
* - `isAtLimit`: Whether the call limit for the current window has been reached
|
|
55
|
-
* - `status`: Current status ('disabled' | 'idle' | 'at-limit')
|
|
49
|
+
* - `executionCount`: Number of function executions that have been completed
|
|
50
|
+
* - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations
|
|
51
|
+
* - `rejectionCount`: Number of function executions that have been rejected due to rate limiting
|
|
56
52
|
*
|
|
57
53
|
* @example
|
|
58
54
|
* ```tsx
|
|
@@ -63,21 +59,39 @@ import type {
|
|
|
63
59
|
* windowType: 'sliding'
|
|
64
60
|
* });
|
|
65
61
|
*
|
|
66
|
-
* // Opt-in to reactive updates when
|
|
62
|
+
* // Opt-in to reactive updates when execution count changes (optimized for tracking successful updates)
|
|
67
63
|
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
|
|
68
64
|
* rawValue,
|
|
69
|
-
* { limit: 5, window: 60000 },
|
|
70
|
-
* (state) => ({
|
|
65
|
+
* { limit: 5, window: 60000, windowType: 'sliding' },
|
|
66
|
+
* (state) => ({ executionCount: state.executionCount })
|
|
71
67
|
* );
|
|
72
68
|
*
|
|
73
|
-
* //
|
|
74
|
-
*
|
|
69
|
+
* // Opt-in to reactive updates when rejection count changes (optimized for tracking rate limit violations)
|
|
70
|
+
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
|
|
71
|
+
* rawValue,
|
|
72
|
+
* { limit: 5, window: 60000, windowType: 'sliding' },
|
|
73
|
+
* (state) => ({ rejectionCount: state.rejectionCount })
|
|
74
|
+
* );
|
|
75
75
|
*
|
|
76
|
-
* //
|
|
77
|
-
*
|
|
76
|
+
* // Opt-in to reactive updates when execution times change (optimized for window calculations)
|
|
77
|
+
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
|
|
78
|
+
* rawValue,
|
|
79
|
+
* { limit: 5, window: 60000, windowType: 'sliding' },
|
|
80
|
+
* (state) => ({ executionTimes: state.executionTimes })
|
|
81
|
+
* );
|
|
82
|
+
*
|
|
83
|
+
* // With rejection callback and fixed window
|
|
84
|
+
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
|
|
85
|
+
* limit: 3,
|
|
86
|
+
* window: 5000,
|
|
87
|
+
* windowType: 'fixed',
|
|
88
|
+
* onReject: (rateLimiter) => {
|
|
89
|
+
* console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
|
|
90
|
+
* }
|
|
91
|
+
* });
|
|
78
92
|
*
|
|
79
|
-
* //
|
|
80
|
-
*
|
|
93
|
+
* // Access the selected rate limiter state (will be empty object {} unless selector provided)
|
|
94
|
+
* const { executionCount, rejectionCount } = rateLimiter.state;
|
|
81
95
|
* ```
|
|
82
96
|
*/
|
|
83
97
|
export function createRateLimitedValue<TValue, TSelected = {}>(
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RateLimiter } from '@tanstack/pacer/rate-limiter'
|
|
2
2
|
import { useStore } from '@tanstack/solid-store'
|
|
3
|
+
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
3
4
|
import type { Store } from '@tanstack/solid-store'
|
|
4
5
|
import type { Accessor } from 'solid-js'
|
|
5
6
|
import type { AnyFunction } from '@tanstack/pacer/types'
|
|
@@ -8,8 +9,10 @@ import type {
|
|
|
8
9
|
RateLimiterState,
|
|
9
10
|
} from '@tanstack/pacer/rate-limiter'
|
|
10
11
|
|
|
11
|
-
export interface SolidRateLimiter<
|
|
12
|
-
|
|
12
|
+
export interface SolidRateLimiter<
|
|
13
|
+
TFn extends AnyFunction,
|
|
14
|
+
TSelected = {},
|
|
15
|
+
> extends Omit<RateLimiter<TFn>, 'store'> {
|
|
13
16
|
/**
|
|
14
17
|
* Reactive state that will be updated when the rate limiter state changes
|
|
15
18
|
*
|
|
@@ -101,10 +104,15 @@ export interface SolidRateLimiter<TFn extends AnyFunction, TSelected = {}>
|
|
|
101
104
|
*/
|
|
102
105
|
export function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(
|
|
103
106
|
fn: TFn,
|
|
104
|
-
|
|
107
|
+
options: RateLimiterOptions<TFn>,
|
|
105
108
|
selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,
|
|
106
109
|
): SolidRateLimiter<TFn, TSelected> {
|
|
107
|
-
const
|
|
110
|
+
const mergedOptions = {
|
|
111
|
+
...useDefaultPacerOptions().rateLimiter,
|
|
112
|
+
...options,
|
|
113
|
+
} as RateLimiterOptions<TFn>
|
|
114
|
+
|
|
115
|
+
const rateLimiter = new RateLimiter<TFn>(fn, mergedOptions)
|
|
108
116
|
|
|
109
117
|
const state = useStore(rateLimiter.store, selector)
|
|
110
118
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Throttler } from '@tanstack/pacer/throttler'
|
|
2
2
|
import { createEffect, onCleanup } from 'solid-js'
|
|
3
3
|
import { useStore } from '@tanstack/solid-store'
|
|
4
|
+
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
4
5
|
import type { Store } from '@tanstack/solid-store'
|
|
5
6
|
import type { Accessor } from 'solid-js'
|
|
6
7
|
import type { AnyFunction } from '@tanstack/pacer/types'
|
|
@@ -9,8 +10,10 @@ import type {
|
|
|
9
10
|
ThrottlerState,
|
|
10
11
|
} from '@tanstack/pacer/throttler'
|
|
11
12
|
|
|
12
|
-
export interface SolidThrottler<
|
|
13
|
-
|
|
13
|
+
export interface SolidThrottler<
|
|
14
|
+
TFn extends AnyFunction,
|
|
15
|
+
TSelected = {},
|
|
16
|
+
> extends Omit<Throttler<TFn>, 'store'> {
|
|
14
17
|
/**
|
|
15
18
|
* Reactive state that will be updated when the throttler state changes
|
|
16
19
|
*
|
|
@@ -98,10 +101,15 @@ export interface SolidThrottler<TFn extends AnyFunction, TSelected = {}>
|
|
|
98
101
|
*/
|
|
99
102
|
export function createThrottler<TFn extends AnyFunction, TSelected = {}>(
|
|
100
103
|
fn: TFn,
|
|
101
|
-
|
|
104
|
+
options: ThrottlerOptions<TFn>,
|
|
102
105
|
selector: (state: ThrottlerState<TFn>) => TSelected = () => ({}) as TSelected,
|
|
103
106
|
): SolidThrottler<TFn, TSelected> {
|
|
104
|
-
const
|
|
107
|
+
const mergedOptions = {
|
|
108
|
+
...useDefaultPacerOptions().throttler,
|
|
109
|
+
...options,
|
|
110
|
+
} as ThrottlerOptions<TFn>
|
|
111
|
+
|
|
112
|
+
const asyncThrottler = new Throttler<TFn>(fn, mergedOptions)
|
|
105
113
|
|
|
106
114
|
const state = useStore(asyncThrottler.store, selector)
|
|
107
115
|
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const asyncBatcher = require("@tanstack/pacer/async-batcher");
|
|
4
|
-
const solidStore = require("@tanstack/solid-store");
|
|
5
|
-
function createAsyncBatcher(fn, initialOptions = {}, selector = () => ({})) {
|
|
6
|
-
const asyncBatcher$1 = new asyncBatcher.AsyncBatcher(fn, initialOptions);
|
|
7
|
-
const state = solidStore.useStore(asyncBatcher$1.store, selector);
|
|
8
|
-
return {
|
|
9
|
-
...asyncBatcher$1,
|
|
10
|
-
state
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
exports.createAsyncBatcher = createAsyncBatcher;
|
|
14
|
-
//# sourceMappingURL=createAsyncBatcher.cjs.map
|