@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
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
const require_PacerProvider = require('../provider/PacerProvider.cjs');
|
|
2
|
+
let __tanstack_solid_store = require("@tanstack/solid-store");
|
|
3
|
+
let __tanstack_pacer_queuer = require("@tanstack/pacer/queuer");
|
|
4
|
+
|
|
5
|
+
//#region src/queuer/createQueuer.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Synchronous processing of items using the provided `fn` function
|
|
11
|
+
* - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior
|
|
12
|
+
* - Priority queueing via `getPriority` or item `priority` property
|
|
13
|
+
* - Item expiration and removal of stale items
|
|
14
|
+
* - Configurable wait time between processing items
|
|
15
|
+
* - Pause/resume processing
|
|
16
|
+
* - Callbacks for queue state changes, execution, rejection, and expiration
|
|
17
|
+
* - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity
|
|
18
|
+
*
|
|
19
|
+
* The queue processes items synchronously in order, with optional delays between each item. When started, it will process one item per tick, with an optional wait time between ticks. You can pause and resume processing with `stop()` and `start()`.
|
|
20
|
+
*
|
|
21
|
+
* By default, the queue uses FIFO behavior, but you can configure LIFO or double-ended queueing by specifying the position when adding or removing items.
|
|
22
|
+
*
|
|
23
|
+
* ## State Management and Selector
|
|
24
|
+
*
|
|
25
|
+
* The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
|
|
26
|
+
* to specify which state changes will trigger a re-render, optimizing performance by preventing
|
|
27
|
+
* unnecessary re-renders when irrelevant state changes occur.
|
|
28
|
+
*
|
|
29
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
30
|
+
* tracking by providing a selector function. This prevents unnecessary re-renders and gives you
|
|
31
|
+
* full control over when your component updates. Only when you provide a selector will the
|
|
32
|
+
* component re-render when the selected state values change.
|
|
33
|
+
*
|
|
34
|
+
* Available state properties:
|
|
35
|
+
* - `executionCount`: Number of items that have been processed
|
|
36
|
+
* - `isRunning`: Whether the queuer is currently running (not stopped)
|
|
37
|
+
* - `items`: Array of items currently queued for processing
|
|
38
|
+
* - `rejectionCount`: Number of items that were rejected (expired or failed validation)
|
|
39
|
+
*
|
|
40
|
+
* Example usage:
|
|
41
|
+
* ```tsx
|
|
42
|
+
* // Default behavior - no reactive state subscriptions
|
|
43
|
+
* const queue = createQueuer(
|
|
44
|
+
* (item) => {
|
|
45
|
+
* // process item synchronously
|
|
46
|
+
* console.log('Processing', item);
|
|
47
|
+
* },
|
|
48
|
+
* {
|
|
49
|
+
* started: true, // Start processing immediately
|
|
50
|
+
* wait: 1000, // Process one item every second
|
|
51
|
+
* getPriority: (item) => item.priority // Process higher priority items first
|
|
52
|
+
* }
|
|
53
|
+
* );
|
|
54
|
+
*
|
|
55
|
+
* // Opt-in to re-render when items or isRunning changes (optimized for UI updates)
|
|
56
|
+
* const queue = createQueuer(
|
|
57
|
+
* (item) => console.log('Processing', item),
|
|
58
|
+
* { started: true, wait: 1000 },
|
|
59
|
+
* (state) => ({ items: state.items, isRunning: state.isRunning })
|
|
60
|
+
* );
|
|
61
|
+
*
|
|
62
|
+
* // Opt-in to re-render when execution metrics change (optimized for tracking progress)
|
|
63
|
+
* const queue = createQueuer(
|
|
64
|
+
* (item) => console.log('Processing', item),
|
|
65
|
+
* { started: true, wait: 1000 },
|
|
66
|
+
* (state) => ({
|
|
67
|
+
* executionCount: state.executionCount,
|
|
68
|
+
* rejectionCount: state.rejectionCount
|
|
69
|
+
* })
|
|
70
|
+
* );
|
|
71
|
+
*
|
|
72
|
+
* // Add items to process - they'll be handled automatically
|
|
73
|
+
* queue.addItem('task1');
|
|
74
|
+
* queue.addItem('task2');
|
|
75
|
+
*
|
|
76
|
+
* // Control the scheduler
|
|
77
|
+
* queue.stop(); // Pause processing
|
|
78
|
+
* queue.start(); // Resume processing
|
|
79
|
+
*
|
|
80
|
+
* // Access the selected state (will be empty object {} unless selector provided)
|
|
81
|
+
* const { items, isRunning } = queue.state();
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
function createQueuer(fn, options = {}, selector = () => ({})) {
|
|
85
|
+
const queuer = new __tanstack_pacer_queuer.Queuer(fn, {
|
|
86
|
+
...require_PacerProvider.useDefaultPacerOptions().queuer,
|
|
87
|
+
...options
|
|
88
|
+
});
|
|
89
|
+
const state = (0, __tanstack_solid_store.useStore)(queuer.store, selector);
|
|
90
|
+
return {
|
|
91
|
+
...queuer,
|
|
92
|
+
state
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
exports.createQueuer = createQueuer;
|
|
98
|
+
//# sourceMappingURL=createQueuer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createQueuer.cjs","names":["Queuer","useDefaultPacerOptions"],"sources":["../../src/queuer/createQueuer.ts"],"sourcesContent":["import { Queuer } from '@tanstack/pacer/queuer'\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 { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface SolidQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * Reactive state that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.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<QueuerState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Synchronous processing of items using the provided `fn` function\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Priority queueing via `getPriority` or item `priority` property\n * - Item expiration and removal of stale items\n * - Configurable wait time between processing items\n * - Pause/resume processing\n * - Callbacks for queue state changes, execution, rejection, and expiration\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The queue processes items synchronously in order, with optional delays between each item. When started, it will process one item per tick, with an optional wait time between ticks. You can pause and resume processing with `stop()` and `start()`.\n *\n * By default, the queue uses FIFO behavior, but you can configure LIFO or double-ended queueing by specifying the position when adding or removing items.\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 items that have been processed\n * - `isRunning`: Whether the queuer is currently running (not stopped)\n * - `items`: Array of items currently queued for processing\n * - `rejectionCount`: Number of items that were rejected (expired or failed validation)\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const queue = createQueuer(\n * (item) => {\n * // process item synchronously\n * console.log('Processing', item);\n * },\n * {\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * getPriority: (item) => item.priority // Process higher priority items first\n * }\n * );\n *\n * // Opt-in to re-render when items or isRunning changes (optimized for UI updates)\n * const queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\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 queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Add items to process - they'll be handled automatically\n * queue.addItem('task1');\n * queue.addItem('task2');\n *\n * // Control the scheduler\n * queue.stop(); // Pause processing\n * queue.start(); // Resume processing\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isRunning } = queue.state();\n * ```\n */\nexport function createQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: QueuerOptions<TValue> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): SolidQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().queuer,\n ...options,\n } as QueuerOptions<TValue>\n\n const queuer = new Queuer(fn, mergedOptions)\n\n const state = useStore(queuer.store, selector)\n\n return {\n ...queuer,\n state,\n } as SolidQueuer<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuGA,SAAgB,aACd,IACA,UAAiC,EAAE,EACnC,kBAA6D,EAAE,GAC/B;CAMhC,MAAM,SAAS,IAAIA,+BAAO,IALJ;EACpB,GAAGC,8CAAwB,CAAC;EAC5B,GAAG;EACJ,CAE2C;CAE5C,MAAM,6CAAiB,OAAO,OAAO,SAAS;AAE9C,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 { Queuer, QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
|
|
4
|
+
|
|
5
|
+
//#region src/queuer/createQueuer.d.ts
|
|
6
|
+
interface SolidQueuer<TValue, TSelected = {}> extends Omit<Queuer<TValue>, 'store'> {
|
|
7
|
+
/**
|
|
8
|
+
* Reactive state that will be updated when the queuer state changes
|
|
9
|
+
*
|
|
10
|
+
* Use this instead of `queuer.store.state`
|
|
11
|
+
*/
|
|
12
|
+
readonly state: Accessor<Readonly<TSelected>>;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use `queuer.state` instead of `queuer.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<QueuerState<TValue>>>;
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.
|
|
@@ -93,4 +95,7 @@ export interface SolidQueuer<TValue, TSelected = {}> extends Omit<Queuer<TValue>
|
|
|
93
95
|
* const { items, isRunning } = queue.state();
|
|
94
96
|
* ```
|
|
95
97
|
*/
|
|
96
|
-
|
|
98
|
+
declare function createQueuer<TValue, TSelected = {}>(fn: (item: TValue) => void, options?: QueuerOptions<TValue>, selector?: (state: QueuerState<TValue>) => TSelected): SolidQueuer<TValue, TSelected>;
|
|
99
|
+
//#endregion
|
|
100
|
+
export { SolidQueuer, createQueuer };
|
|
101
|
+
//# sourceMappingURL=createQueuer.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 { Queuer, QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
|
|
4
|
+
|
|
5
|
+
//#region src/queuer/createQueuer.d.ts
|
|
6
|
+
interface SolidQueuer<TValue, TSelected = {}> extends Omit<Queuer<TValue>, 'store'> {
|
|
7
|
+
/**
|
|
8
|
+
* Reactive state that will be updated when the queuer state changes
|
|
9
|
+
*
|
|
10
|
+
* Use this instead of `queuer.store.state`
|
|
11
|
+
*/
|
|
12
|
+
readonly state: Accessor<Readonly<TSelected>>;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use `queuer.state` instead of `queuer.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<QueuerState<TValue>>>;
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.
|
|
@@ -93,4 +95,7 @@ export interface SolidQueuer<TValue, TSelected = {}> extends Omit<Queuer<TValue>
|
|
|
93
95
|
* const { items, isRunning } = queue.state();
|
|
94
96
|
* ```
|
|
95
97
|
*/
|
|
96
|
-
|
|
98
|
+
declare function createQueuer<TValue, TSelected = {}>(fn: (item: TValue) => void, options?: QueuerOptions<TValue>, selector?: (state: QueuerState<TValue>) => TSelected): SolidQueuer<TValue, TSelected>;
|
|
99
|
+
//#endregion
|
|
100
|
+
export { SolidQueuer, createQueuer };
|
|
101
|
+
//# sourceMappingURL=createQueuer.d.ts.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { useDefaultPacerOptions } from "../provider/PacerProvider.js";
|
|
2
|
+
import { useStore } from "@tanstack/solid-store";
|
|
3
|
+
import { Queuer } from "@tanstack/pacer/queuer";
|
|
4
|
+
|
|
5
|
+
//#region src/queuer/createQueuer.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Synchronous processing of items using the provided `fn` function
|
|
11
|
+
* - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior
|
|
12
|
+
* - Priority queueing via `getPriority` or item `priority` property
|
|
13
|
+
* - Item expiration and removal of stale items
|
|
14
|
+
* - Configurable wait time between processing items
|
|
15
|
+
* - Pause/resume processing
|
|
16
|
+
* - Callbacks for queue state changes, execution, rejection, and expiration
|
|
17
|
+
* - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity
|
|
18
|
+
*
|
|
19
|
+
* The queue processes items synchronously in order, with optional delays between each item. When started, it will process one item per tick, with an optional wait time between ticks. You can pause and resume processing with `stop()` and `start()`.
|
|
20
|
+
*
|
|
21
|
+
* By default, the queue uses FIFO behavior, but you can configure LIFO or double-ended queueing by specifying the position when adding or removing items.
|
|
22
|
+
*
|
|
23
|
+
* ## State Management and Selector
|
|
24
|
+
*
|
|
25
|
+
* The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
|
|
26
|
+
* to specify which state changes will trigger a re-render, optimizing performance by preventing
|
|
27
|
+
* unnecessary re-renders when irrelevant state changes occur.
|
|
28
|
+
*
|
|
29
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
30
|
+
* tracking by providing a selector function. This prevents unnecessary re-renders and gives you
|
|
31
|
+
* full control over when your component updates. Only when you provide a selector will the
|
|
32
|
+
* component re-render when the selected state values change.
|
|
33
|
+
*
|
|
34
|
+
* Available state properties:
|
|
35
|
+
* - `executionCount`: Number of items that have been processed
|
|
36
|
+
* - `isRunning`: Whether the queuer is currently running (not stopped)
|
|
37
|
+
* - `items`: Array of items currently queued for processing
|
|
38
|
+
* - `rejectionCount`: Number of items that were rejected (expired or failed validation)
|
|
39
|
+
*
|
|
40
|
+
* Example usage:
|
|
41
|
+
* ```tsx
|
|
42
|
+
* // Default behavior - no reactive state subscriptions
|
|
43
|
+
* const queue = createQueuer(
|
|
44
|
+
* (item) => {
|
|
45
|
+
* // process item synchronously
|
|
46
|
+
* console.log('Processing', item);
|
|
47
|
+
* },
|
|
48
|
+
* {
|
|
49
|
+
* started: true, // Start processing immediately
|
|
50
|
+
* wait: 1000, // Process one item every second
|
|
51
|
+
* getPriority: (item) => item.priority // Process higher priority items first
|
|
52
|
+
* }
|
|
53
|
+
* );
|
|
54
|
+
*
|
|
55
|
+
* // Opt-in to re-render when items or isRunning changes (optimized for UI updates)
|
|
56
|
+
* const queue = createQueuer(
|
|
57
|
+
* (item) => console.log('Processing', item),
|
|
58
|
+
* { started: true, wait: 1000 },
|
|
59
|
+
* (state) => ({ items: state.items, isRunning: state.isRunning })
|
|
60
|
+
* );
|
|
61
|
+
*
|
|
62
|
+
* // Opt-in to re-render when execution metrics change (optimized for tracking progress)
|
|
63
|
+
* const queue = createQueuer(
|
|
64
|
+
* (item) => console.log('Processing', item),
|
|
65
|
+
* { started: true, wait: 1000 },
|
|
66
|
+
* (state) => ({
|
|
67
|
+
* executionCount: state.executionCount,
|
|
68
|
+
* rejectionCount: state.rejectionCount
|
|
69
|
+
* })
|
|
70
|
+
* );
|
|
71
|
+
*
|
|
72
|
+
* // Add items to process - they'll be handled automatically
|
|
73
|
+
* queue.addItem('task1');
|
|
74
|
+
* queue.addItem('task2');
|
|
75
|
+
*
|
|
76
|
+
* // Control the scheduler
|
|
77
|
+
* queue.stop(); // Pause processing
|
|
78
|
+
* queue.start(); // Resume processing
|
|
79
|
+
*
|
|
80
|
+
* // Access the selected state (will be empty object {} unless selector provided)
|
|
81
|
+
* const { items, isRunning } = queue.state();
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
function createQueuer(fn, options = {}, selector = () => ({})) {
|
|
85
|
+
const queuer = new Queuer(fn, {
|
|
86
|
+
...useDefaultPacerOptions().queuer,
|
|
87
|
+
...options
|
|
88
|
+
});
|
|
89
|
+
const state = useStore(queuer.store, selector);
|
|
90
|
+
return {
|
|
91
|
+
...queuer,
|
|
92
|
+
state
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
export { createQueuer };
|
|
98
|
+
//# sourceMappingURL=createQueuer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createQueuer.js","names":[],"sources":["../../src/queuer/createQueuer.ts"],"sourcesContent":["import { Queuer } from '@tanstack/pacer/queuer'\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 { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface SolidQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * Reactive state that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.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<QueuerState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Synchronous processing of items using the provided `fn` function\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Priority queueing via `getPriority` or item `priority` property\n * - Item expiration and removal of stale items\n * - Configurable wait time between processing items\n * - Pause/resume processing\n * - Callbacks for queue state changes, execution, rejection, and expiration\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The queue processes items synchronously in order, with optional delays between each item. When started, it will process one item per tick, with an optional wait time between ticks. You can pause and resume processing with `stop()` and `start()`.\n *\n * By default, the queue uses FIFO behavior, but you can configure LIFO or double-ended queueing by specifying the position when adding or removing items.\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 items that have been processed\n * - `isRunning`: Whether the queuer is currently running (not stopped)\n * - `items`: Array of items currently queued for processing\n * - `rejectionCount`: Number of items that were rejected (expired or failed validation)\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const queue = createQueuer(\n * (item) => {\n * // process item synchronously\n * console.log('Processing', item);\n * },\n * {\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * getPriority: (item) => item.priority // Process higher priority items first\n * }\n * );\n *\n * // Opt-in to re-render when items or isRunning changes (optimized for UI updates)\n * const queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\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 queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Add items to process - they'll be handled automatically\n * queue.addItem('task1');\n * queue.addItem('task2');\n *\n * // Control the scheduler\n * queue.stop(); // Pause processing\n * queue.start(); // Resume processing\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isRunning } = queue.state();\n * ```\n */\nexport function createQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: QueuerOptions<TValue> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): SolidQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().queuer,\n ...options,\n } as QueuerOptions<TValue>\n\n const queuer = new Queuer(fn, mergedOptions)\n\n const state = useStore(queuer.store, selector)\n\n return {\n ...queuer,\n state,\n } as SolidQueuer<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuGA,SAAgB,aACd,IACA,UAAiC,EAAE,EACnC,kBAA6D,EAAE,GAC/B;CAMhC,MAAM,SAAS,IAAI,OAAO,IALJ;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ,CAE2C;CAE5C,MAAM,QAAQ,SAAS,OAAO,OAAO,SAAS;AAE9C,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const require_createQueuer = require('./createQueuer.cjs');
|
|
2
|
+
const require_createQueuedSignal = require('./createQueuedSignal.cjs');
|
|
3
|
+
|
|
4
|
+
exports.createQueuedSignal = require_createQueuedSignal.createQueuedSignal;
|
|
5
|
+
exports.createQueuer = require_createQueuer.createQueuer;
|
|
6
|
+
var __tanstack_pacer_queuer = require("@tanstack/pacer/queuer");
|
|
7
|
+
Object.keys(__tanstack_pacer_queuer).forEach(function (k) {
|
|
8
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return __tanstack_pacer_queuer[k]; }
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const require_createRateLimiter = require('./createRateLimiter.cjs');
|
|
2
|
+
let solid_js = require("solid-js");
|
|
3
|
+
|
|
4
|
+
//#region src/rate-limiter/createRateLimitedSignal.ts
|
|
5
|
+
/**
|
|
6
|
+
* A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.
|
|
7
|
+
* This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.
|
|
8
|
+
*
|
|
9
|
+
* Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks
|
|
10
|
+
* subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out
|
|
11
|
+
* or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.
|
|
12
|
+
*
|
|
13
|
+
* The rate limiter supports two types of windows:
|
|
14
|
+
* - 'fixed': A strict window that resets after the window period. All updates within the window count
|
|
15
|
+
* towards the limit, and the window resets completely after the period.
|
|
16
|
+
* - 'sliding': A rolling window that allows updates as old ones expire. This provides a more
|
|
17
|
+
* consistent rate of updates over time.
|
|
18
|
+
*
|
|
19
|
+
* For smoother update patterns, consider:
|
|
20
|
+
* - createThrottledSignal: When you want consistent spacing between updates (e.g. UI changes)
|
|
21
|
+
* - createDebouncedSignal: When you want to collapse rapid updates into a single update (e.g. search input)
|
|
22
|
+
*
|
|
23
|
+
* Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.
|
|
24
|
+
*
|
|
25
|
+
* The hook returns a tuple containing:
|
|
26
|
+
* - The rate-limited state value accessor
|
|
27
|
+
* - A rate-limited setter function that respects the configured limits
|
|
28
|
+
* - The rateLimiter instance for additional control
|
|
29
|
+
*
|
|
30
|
+
* For more direct control over rate limiting without state management,
|
|
31
|
+
* consider using the lower-level createRateLimiter hook instead.
|
|
32
|
+
*
|
|
33
|
+
* ## State Management and Selector
|
|
34
|
+
*
|
|
35
|
+
* The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.
|
|
36
|
+
* The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,
|
|
37
|
+
* optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
|
|
38
|
+
*
|
|
39
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
40
|
+
* tracking by providing a selector function. This prevents unnecessary reactive updates and gives you
|
|
41
|
+
* full control over when your component subscribes to state changes. Only when you provide a selector will
|
|
42
|
+
* the reactive system track the selected state values.
|
|
43
|
+
*
|
|
44
|
+
* Available rate limiter state properties:
|
|
45
|
+
* - `callsInWindow`: Number of calls made in the current window
|
|
46
|
+
* - `remainingInWindow`: Number of calls remaining in the current window
|
|
47
|
+
* - `windowStart`: Unix timestamp when the current window started
|
|
48
|
+
* - `nextWindowStart`: Unix timestamp when the next window will start
|
|
49
|
+
* - `msUntilNextWindow`: Milliseconds until the next window starts
|
|
50
|
+
* - `isAtLimit`: Whether the call limit for the current window has been reached
|
|
51
|
+
* - `status`: Current status ('disabled' | 'idle' | 'at-limit')
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* // Default behavior - no reactive state subscriptions
|
|
56
|
+
* const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {
|
|
57
|
+
* limit: 5,
|
|
58
|
+
* window: 60000,
|
|
59
|
+
* windowType: 'sliding'
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* // Opt-in to reactive updates when limit state changes (optimized for UI feedback)
|
|
63
|
+
* const [value, setValue, rateLimiter] = createRateLimitedSignal(
|
|
64
|
+
* 0,
|
|
65
|
+
* { limit: 5, window: 60000 },
|
|
66
|
+
* (state) => ({ isAtLimit: state.isAtLimit, remainingInWindow: state.remainingInWindow })
|
|
67
|
+
* );
|
|
68
|
+
*
|
|
69
|
+
* // With rejection callback and fixed window
|
|
70
|
+
* const [value, setValue] = createRateLimitedSignal(0, {
|
|
71
|
+
* limit: 3,
|
|
72
|
+
* window: 5000,
|
|
73
|
+
* windowType: 'fixed',
|
|
74
|
+
* onReject: (rateLimiter) => {
|
|
75
|
+
* alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
|
|
76
|
+
* }
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* // Access rateLimiter state via signals
|
|
80
|
+
* const handleSubmit = () => {
|
|
81
|
+
* const remaining = rateLimiter.state().remainingInWindow;
|
|
82
|
+
* if (remaining > 0) {
|
|
83
|
+
* setValue(newValue);
|
|
84
|
+
* } else {
|
|
85
|
+
* showRateLimitWarning();
|
|
86
|
+
* }
|
|
87
|
+
* };
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
function createRateLimitedSignal(value, initialOptions, selector) {
|
|
91
|
+
const [rateLimitedValue, setRateLimitedValue] = (0, solid_js.createSignal)(value);
|
|
92
|
+
const rateLimiter = require_createRateLimiter.createRateLimiter(setRateLimitedValue, initialOptions, selector);
|
|
93
|
+
return [
|
|
94
|
+
rateLimitedValue,
|
|
95
|
+
rateLimiter.maybeExecute,
|
|
96
|
+
rateLimiter
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
exports.createRateLimitedSignal = createRateLimitedSignal;
|
|
102
|
+
//# sourceMappingURL=createRateLimitedSignal.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRateLimitedSignal.cjs","names":["createRateLimiter"],"sources":["../../src/rate-limiter/createRateLimitedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createRateLimiter } from './createRateLimiter'\nimport type { SolidRateLimiter } from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\n/**\n * A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.\n * This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\n *\n * For smoother update patterns, consider:\n * - createThrottledSignal: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedSignal: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns a tuple containing:\n * - The rate-limited state value accessor\n * - A rate-limited setter function that respects the configured limits\n * - The rateLimiter instance for additional control\n *\n * For more direct control over rate limiting without state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.\n * The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available rate limiter state properties:\n * - `callsInWindow`: Number of calls made in the current window\n * - `remainingInWindow`: Number of calls remaining in the current window\n * - `windowStart`: Unix timestamp when the current window started\n * - `nextWindowStart`: Unix timestamp when the next window will start\n * - `msUntilNextWindow`: Milliseconds until the next window starts\n * - `isAtLimit`: Whether the call limit for the current window has been reached\n * - `status`: Current status ('disabled' | 'idle' | 'at-limit')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to reactive updates when limit state changes (optimized for UI feedback)\n * const [value, setValue, rateLimiter] = createRateLimitedSignal(\n * 0,\n * { limit: 5, window: 60000 },\n * (state) => ({ isAtLimit: state.isAtLimit, remainingInWindow: state.remainingInWindow })\n * );\n *\n * // With rejection callback and fixed window\n * const [value, setValue] = createRateLimitedSignal(0, {\n * limit: 3,\n * window: 5000,\n * windowType: 'fixed',\n * onReject: (rateLimiter) => {\n * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access rateLimiter state via signals\n * const handleSubmit = () => {\n * const remaining = rateLimiter.state().remainingInWindow;\n * if (remaining > 0) {\n * setValue(newValue);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n * ```\n */\nexport function createRateLimitedSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidRateLimiter<Setter<TValue>, TSelected>,\n] {\n const [rateLimitedValue, setRateLimitedValue] = createSignal<TValue>(value)\n\n const rateLimiter = createRateLimiter(\n setRateLimitedValue,\n initialOptions,\n selector,\n )\n\n return [\n rateLimitedValue,\n rateLimiter.maybeExecute as Setter<TValue>,\n rateLimiter,\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8FA,SAAgB,wBACd,OACA,gBACA,UAKA;CACA,MAAM,CAAC,kBAAkB,kDAA4C,MAAM;CAE3E,MAAM,cAAcA,4CAClB,qBACA,gBACA,SACD;AAED,QAAO;EACL;EACA,YAAY;EACZ;EACD"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { SolidRateLimiter } from
|
|
2
|
-
import { Accessor, Setter } from
|
|
3
|
-
import { RateLimiterOptions, RateLimiterState } from
|
|
1
|
+
import { SolidRateLimiter } from "./createRateLimiter.cjs";
|
|
2
|
+
import { Accessor, Setter } from "solid-js";
|
|
3
|
+
import { RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
4
|
+
|
|
5
|
+
//#region src/rate-limiter/createRateLimitedSignal.d.ts
|
|
6
|
+
|
|
4
7
|
/**
|
|
5
8
|
* A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.
|
|
6
9
|
* This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.
|
|
@@ -86,8 +89,7 @@ import { RateLimiterOptions, RateLimiterState } from '@tanstack/pacer/rate-limit
|
|
|
86
89
|
* };
|
|
87
90
|
* ```
|
|
88
91
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
];
|
|
92
|
+
declare function createRateLimitedSignal<TValue, TSelected = {}>(value: TValue, initialOptions: RateLimiterOptions<Setter<TValue>>, selector?: (state: RateLimiterState) => TSelected): [Accessor<TValue>, Setter<TValue>, SolidRateLimiter<Setter<TValue>, TSelected>];
|
|
93
|
+
//#endregion
|
|
94
|
+
export { createRateLimitedSignal };
|
|
95
|
+
//# sourceMappingURL=createRateLimitedSignal.d.cts.map
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { SolidRateLimiter } from
|
|
2
|
-
import { Accessor, Setter } from
|
|
3
|
-
import { RateLimiterOptions, RateLimiterState } from
|
|
1
|
+
import { SolidRateLimiter } from "./createRateLimiter.js";
|
|
2
|
+
import { Accessor, Setter } from "solid-js";
|
|
3
|
+
import { RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
4
|
+
|
|
5
|
+
//#region src/rate-limiter/createRateLimitedSignal.d.ts
|
|
6
|
+
|
|
4
7
|
/**
|
|
5
8
|
* A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.
|
|
6
9
|
* This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.
|
|
@@ -86,8 +89,7 @@ import { RateLimiterOptions, RateLimiterState } from '@tanstack/pacer/rate-limit
|
|
|
86
89
|
* };
|
|
87
90
|
* ```
|
|
88
91
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
];
|
|
92
|
+
declare function createRateLimitedSignal<TValue, TSelected = {}>(value: TValue, initialOptions: RateLimiterOptions<Setter<TValue>>, selector?: (state: RateLimiterState) => TSelected): [Accessor<TValue>, Setter<TValue>, SolidRateLimiter<Setter<TValue>, TSelected>];
|
|
93
|
+
//#endregion
|
|
94
|
+
export { createRateLimitedSignal };
|
|
95
|
+
//# sourceMappingURL=createRateLimitedSignal.d.ts.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createRateLimiter } from "./createRateLimiter.js";
|
|
2
|
+
import { createSignal } from "solid-js";
|
|
3
|
+
|
|
4
|
+
//#region src/rate-limiter/createRateLimitedSignal.ts
|
|
5
|
+
/**
|
|
6
|
+
* A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.
|
|
7
|
+
* This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.
|
|
8
|
+
*
|
|
9
|
+
* Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks
|
|
10
|
+
* subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out
|
|
11
|
+
* or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.
|
|
12
|
+
*
|
|
13
|
+
* The rate limiter supports two types of windows:
|
|
14
|
+
* - 'fixed': A strict window that resets after the window period. All updates within the window count
|
|
15
|
+
* towards the limit, and the window resets completely after the period.
|
|
16
|
+
* - 'sliding': A rolling window that allows updates as old ones expire. This provides a more
|
|
17
|
+
* consistent rate of updates over time.
|
|
18
|
+
*
|
|
19
|
+
* For smoother update patterns, consider:
|
|
20
|
+
* - createThrottledSignal: When you want consistent spacing between updates (e.g. UI changes)
|
|
21
|
+
* - createDebouncedSignal: When you want to collapse rapid updates into a single update (e.g. search input)
|
|
22
|
+
*
|
|
23
|
+
* Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.
|
|
24
|
+
*
|
|
25
|
+
* The hook returns a tuple containing:
|
|
26
|
+
* - The rate-limited state value accessor
|
|
27
|
+
* - A rate-limited setter function that respects the configured limits
|
|
28
|
+
* - The rateLimiter instance for additional control
|
|
29
|
+
*
|
|
30
|
+
* For more direct control over rate limiting without state management,
|
|
31
|
+
* consider using the lower-level createRateLimiter hook instead.
|
|
32
|
+
*
|
|
33
|
+
* ## State Management and Selector
|
|
34
|
+
*
|
|
35
|
+
* The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.
|
|
36
|
+
* The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,
|
|
37
|
+
* optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
|
|
38
|
+
*
|
|
39
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
40
|
+
* tracking by providing a selector function. This prevents unnecessary reactive updates and gives you
|
|
41
|
+
* full control over when your component subscribes to state changes. Only when you provide a selector will
|
|
42
|
+
* the reactive system track the selected state values.
|
|
43
|
+
*
|
|
44
|
+
* Available rate limiter state properties:
|
|
45
|
+
* - `callsInWindow`: Number of calls made in the current window
|
|
46
|
+
* - `remainingInWindow`: Number of calls remaining in the current window
|
|
47
|
+
* - `windowStart`: Unix timestamp when the current window started
|
|
48
|
+
* - `nextWindowStart`: Unix timestamp when the next window will start
|
|
49
|
+
* - `msUntilNextWindow`: Milliseconds until the next window starts
|
|
50
|
+
* - `isAtLimit`: Whether the call limit for the current window has been reached
|
|
51
|
+
* - `status`: Current status ('disabled' | 'idle' | 'at-limit')
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* // Default behavior - no reactive state subscriptions
|
|
56
|
+
* const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {
|
|
57
|
+
* limit: 5,
|
|
58
|
+
* window: 60000,
|
|
59
|
+
* windowType: 'sliding'
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* // Opt-in to reactive updates when limit state changes (optimized for UI feedback)
|
|
63
|
+
* const [value, setValue, rateLimiter] = createRateLimitedSignal(
|
|
64
|
+
* 0,
|
|
65
|
+
* { limit: 5, window: 60000 },
|
|
66
|
+
* (state) => ({ isAtLimit: state.isAtLimit, remainingInWindow: state.remainingInWindow })
|
|
67
|
+
* );
|
|
68
|
+
*
|
|
69
|
+
* // With rejection callback and fixed window
|
|
70
|
+
* const [value, setValue] = createRateLimitedSignal(0, {
|
|
71
|
+
* limit: 3,
|
|
72
|
+
* window: 5000,
|
|
73
|
+
* windowType: 'fixed',
|
|
74
|
+
* onReject: (rateLimiter) => {
|
|
75
|
+
* alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
|
|
76
|
+
* }
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* // Access rateLimiter state via signals
|
|
80
|
+
* const handleSubmit = () => {
|
|
81
|
+
* const remaining = rateLimiter.state().remainingInWindow;
|
|
82
|
+
* if (remaining > 0) {
|
|
83
|
+
* setValue(newValue);
|
|
84
|
+
* } else {
|
|
85
|
+
* showRateLimitWarning();
|
|
86
|
+
* }
|
|
87
|
+
* };
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
function createRateLimitedSignal(value, initialOptions, selector) {
|
|
91
|
+
const [rateLimitedValue, setRateLimitedValue] = createSignal(value);
|
|
92
|
+
const rateLimiter = createRateLimiter(setRateLimitedValue, initialOptions, selector);
|
|
93
|
+
return [
|
|
94
|
+
rateLimitedValue,
|
|
95
|
+
rateLimiter.maybeExecute,
|
|
96
|
+
rateLimiter
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
export { createRateLimitedSignal };
|
|
102
|
+
//# sourceMappingURL=createRateLimitedSignal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRateLimitedSignal.js","names":[],"sources":["../../src/rate-limiter/createRateLimitedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createRateLimiter } from './createRateLimiter'\nimport type { SolidRateLimiter } from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\n/**\n * A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.\n * This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\n *\n * For smoother update patterns, consider:\n * - createThrottledSignal: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedSignal: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns a tuple containing:\n * - The rate-limited state value accessor\n * - A rate-limited setter function that respects the configured limits\n * - The rateLimiter instance for additional control\n *\n * For more direct control over rate limiting without state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.\n * The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available rate limiter state properties:\n * - `callsInWindow`: Number of calls made in the current window\n * - `remainingInWindow`: Number of calls remaining in the current window\n * - `windowStart`: Unix timestamp when the current window started\n * - `nextWindowStart`: Unix timestamp when the next window will start\n * - `msUntilNextWindow`: Milliseconds until the next window starts\n * - `isAtLimit`: Whether the call limit for the current window has been reached\n * - `status`: Current status ('disabled' | 'idle' | 'at-limit')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to reactive updates when limit state changes (optimized for UI feedback)\n * const [value, setValue, rateLimiter] = createRateLimitedSignal(\n * 0,\n * { limit: 5, window: 60000 },\n * (state) => ({ isAtLimit: state.isAtLimit, remainingInWindow: state.remainingInWindow })\n * );\n *\n * // With rejection callback and fixed window\n * const [value, setValue] = createRateLimitedSignal(0, {\n * limit: 3,\n * window: 5000,\n * windowType: 'fixed',\n * onReject: (rateLimiter) => {\n * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access rateLimiter state via signals\n * const handleSubmit = () => {\n * const remaining = rateLimiter.state().remainingInWindow;\n * if (remaining > 0) {\n * setValue(newValue);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n * ```\n */\nexport function createRateLimitedSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidRateLimiter<Setter<TValue>, TSelected>,\n] {\n const [rateLimitedValue, setRateLimitedValue] = createSignal<TValue>(value)\n\n const rateLimiter = createRateLimiter(\n setRateLimitedValue,\n initialOptions,\n selector,\n )\n\n return [\n rateLimitedValue,\n rateLimiter.maybeExecute as Setter<TValue>,\n rateLimiter,\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8FA,SAAgB,wBACd,OACA,gBACA,UAKA;CACA,MAAM,CAAC,kBAAkB,uBAAuB,aAAqB,MAAM;CAE3E,MAAM,cAAc,kBAClB,qBACA,gBACA,SACD;AAED,QAAO;EACL;EACA,YAAY;EACZ;EACD"}
|