@tanstack/solid-pacer 0.21.1 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -6
- package/dist/async-batcher/createAsyncBatcher.d.ts +5 -10
- package/dist/async-batcher/createAsyncBatcher.js +2 -5
- package/dist/async-debouncer/createAsyncDebouncer.d.ts +8 -12
- package/dist/async-debouncer/createAsyncDebouncer.js +5 -7
- package/dist/async-queuer/createAsyncQueuer.d.ts +9 -12
- package/dist/async-queuer/createAsyncQueuer.js +4 -5
- package/dist/async-rate-limiter/createAsyncRateLimiter.d.ts +10 -13
- package/dist/async-rate-limiter/createAsyncRateLimiter.js +7 -8
- package/dist/async-throttler/createAsyncThrottler.d.ts +8 -14
- package/dist/async-throttler/createAsyncThrottler.js +5 -9
- package/dist/batcher/createBatcher.d.ts +11 -15
- package/dist/batcher/createBatcher.js +6 -8
- package/dist/debouncer/createDebouncedSignal.d.ts +2 -5
- package/dist/debouncer/createDebouncedSignal.js +1 -2
- package/dist/debouncer/createDebouncedValue.d.ts +2 -5
- package/dist/debouncer/createDebouncedValue.js +1 -2
- package/dist/debouncer/createDebouncer.d.ts +4 -7
- package/dist/debouncer/createDebouncer.js +1 -2
- package/dist/provider/PacerProvider.d.ts +6 -9
- package/dist/provider/PacerProvider.js +1 -2
- package/dist/queuer/createQueuedSignal.d.ts +2 -5
- package/dist/queuer/createQueuedSignal.js +1 -2
- package/dist/queuer/createQueuer.d.ts +4 -7
- package/dist/queuer/createQueuer.js +1 -2
- package/dist/rate-limiter/createRateLimitedSignal.d.ts +12 -14
- package/dist/rate-limiter/createRateLimitedSignal.js +11 -11
- package/dist/rate-limiter/createRateLimitedValue.d.ts +2 -5
- package/dist/rate-limiter/createRateLimitedValue.js +1 -2
- package/dist/rate-limiter/createRateLimiter.d.ts +8 -10
- package/dist/rate-limiter/createRateLimiter.js +5 -5
- package/dist/throttler/createThrottledSignal.d.ts +2 -7
- package/dist/throttler/createThrottledSignal.js +1 -4
- package/dist/throttler/createThrottledValue.d.ts +2 -7
- package/dist/throttler/createThrottledValue.js +1 -4
- package/dist/throttler/createThrottler.d.ts +4 -9
- package/dist/throttler/createThrottler.js +1 -4
- package/package.json +24 -68
- package/dist/async-batcher/createAsyncBatcher.cjs +0 -166
- package/dist/async-batcher/createAsyncBatcher.cjs.map +0 -1
- package/dist/async-batcher/createAsyncBatcher.d.cts +0 -178
- package/dist/async-batcher/createAsyncBatcher.js.map +0 -1
- package/dist/async-batcher/index.cjs +0 -11
- package/dist/async-batcher/index.d.cts +0 -3
- package/dist/async-debouncer/createAsyncDebouncer.cjs +0 -151
- package/dist/async-debouncer/createAsyncDebouncer.cjs.map +0 -1
- package/dist/async-debouncer/createAsyncDebouncer.d.cts +0 -164
- package/dist/async-debouncer/createAsyncDebouncer.js.map +0 -1
- package/dist/async-debouncer/index.cjs +0 -11
- package/dist/async-debouncer/index.d.cts +0 -3
- package/dist/async-queuer/createAsyncQueuer.cjs +0 -158
- package/dist/async-queuer/createAsyncQueuer.cjs.map +0 -1
- package/dist/async-queuer/createAsyncQueuer.d.cts +0 -170
- package/dist/async-queuer/createAsyncQueuer.js.map +0 -1
- package/dist/async-queuer/index.cjs +0 -11
- package/dist/async-queuer/index.d.cts +0 -3
- package/dist/async-rate-limiter/createAsyncRateLimiter.cjs +0 -193
- package/dist/async-rate-limiter/createAsyncRateLimiter.cjs.map +0 -1
- package/dist/async-rate-limiter/createAsyncRateLimiter.d.cts +0 -209
- package/dist/async-rate-limiter/createAsyncRateLimiter.js.map +0 -1
- package/dist/async-rate-limiter/index.cjs +0 -11
- package/dist/async-rate-limiter/index.d.cts +0 -3
- package/dist/async-throttler/createAsyncThrottler.cjs +0 -151
- package/dist/async-throttler/createAsyncThrottler.cjs.map +0 -1
- package/dist/async-throttler/createAsyncThrottler.d.cts +0 -164
- package/dist/async-throttler/createAsyncThrottler.js.map +0 -1
- package/dist/async-throttler/index.cjs +0 -11
- package/dist/async-throttler/index.d.cts +0 -3
- package/dist/batcher/createBatcher.cjs +0 -132
- package/dist/batcher/createBatcher.cjs.map +0 -1
- package/dist/batcher/createBatcher.d.cts +0 -147
- package/dist/batcher/createBatcher.js.map +0 -1
- package/dist/batcher/index.cjs +0 -11
- package/dist/batcher/index.d.cts +0 -3
- package/dist/debouncer/createDebouncedSignal.cjs +0 -88
- package/dist/debouncer/createDebouncedSignal.cjs.map +0 -1
- package/dist/debouncer/createDebouncedSignal.d.cts +0 -80
- package/dist/debouncer/createDebouncedSignal.js.map +0 -1
- package/dist/debouncer/createDebouncedValue.cjs +0 -77
- package/dist/debouncer/createDebouncedValue.cjs.map +0 -1
- package/dist/debouncer/createDebouncedValue.d.cts +0 -71
- package/dist/debouncer/createDebouncedValue.js.map +0 -1
- package/dist/debouncer/createDebouncer.cjs +0 -129
- package/dist/debouncer/createDebouncer.cjs.map +0 -1
- package/dist/debouncer/createDebouncer.d.cts +0 -145
- package/dist/debouncer/createDebouncer.js.map +0 -1
- package/dist/debouncer/index.cjs +0 -15
- package/dist/debouncer/index.d.cts +0 -5
- package/dist/index.cjs +0 -47
- package/dist/index.d.cts +0 -20
- package/dist/provider/PacerProvider.cjs +0 -27
- package/dist/provider/PacerProvider.cjs.map +0 -1
- package/dist/provider/PacerProvider.d.cts +0 -29
- package/dist/provider/PacerProvider.js.map +0 -1
- package/dist/provider/index.cjs +0 -6
- package/dist/provider/index.d.cts +0 -2
- package/dist/queuer/createQueuedSignal.cjs +0 -129
- package/dist/queuer/createQueuedSignal.cjs.map +0 -1
- package/dist/queuer/createQueuedSignal.d.cts +0 -122
- package/dist/queuer/createQueuedSignal.js.map +0 -1
- package/dist/queuer/createQueuer.cjs +0 -133
- package/dist/queuer/createQueuer.cjs.map +0 -1
- package/dist/queuer/createQueuer.d.cts +0 -148
- package/dist/queuer/createQueuer.js.map +0 -1
- package/dist/queuer/index.cjs +0 -13
- package/dist/queuer/index.d.cts +0 -4
- package/dist/rate-limiter/createRateLimitedSignal.cjs +0 -102
- package/dist/rate-limiter/createRateLimitedSignal.cjs.map +0 -1
- package/dist/rate-limiter/createRateLimitedSignal.d.cts +0 -94
- package/dist/rate-limiter/createRateLimitedSignal.js.map +0 -1
- package/dist/rate-limiter/createRateLimitedValue.cjs +0 -102
- package/dist/rate-limiter/createRateLimitedValue.cjs.map +0 -1
- package/dist/rate-limiter/createRateLimitedValue.d.cts +0 -96
- package/dist/rate-limiter/createRateLimitedValue.js.map +0 -1
- package/dist/rate-limiter/createRateLimiter.cjs +0 -157
- package/dist/rate-limiter/createRateLimiter.cjs.map +0 -1
- package/dist/rate-limiter/createRateLimiter.d.cts +0 -174
- package/dist/rate-limiter/createRateLimiter.js.map +0 -1
- package/dist/rate-limiter/index.cjs +0 -15
- package/dist/rate-limiter/index.d.cts +0 -5
- package/dist/throttler/createThrottledSignal.cjs +0 -79
- package/dist/throttler/createThrottledSignal.cjs.map +0 -1
- package/dist/throttler/createThrottledSignal.d.cts +0 -71
- package/dist/throttler/createThrottledSignal.js.map +0 -1
- package/dist/throttler/createThrottledValue.cjs +0 -74
- package/dist/throttler/createThrottledValue.cjs.map +0 -1
- package/dist/throttler/createThrottledValue.d.cts +0 -68
- package/dist/throttler/createThrottledValue.js.map +0 -1
- package/dist/throttler/createThrottler.cjs +0 -132
- package/dist/throttler/createThrottler.cjs.map +0 -1
- package/dist/throttler/createThrottler.d.cts +0 -148
- package/dist/throttler/createThrottler.js.map +0 -1
- package/dist/throttler/index.cjs +0 -15
- package/dist/throttler/index.d.cts +0 -5
- package/dist/types/index.cjs +0 -9
- package/dist/types/index.d.cts +0 -1
- package/dist/utils/index.cjs +0 -9
- package/dist/utils/index.d.cts +0 -1
- package/src/async-batcher/createAsyncBatcher.ts +0 -234
- package/src/async-batcher/index.ts +0 -3
- package/src/async-debouncer/createAsyncDebouncer.ts +0 -225
- package/src/async-debouncer/index.ts +0 -4
- package/src/async-queuer/createAsyncQueuer.ts +0 -226
- package/src/async-queuer/index.ts +0 -3
- package/src/async-rate-limiter/createAsyncRateLimiter.ts +0 -269
- package/src/async-rate-limiter/index.ts +0 -4
- package/src/async-throttler/createAsyncThrottler.ts +0 -225
- package/src/async-throttler/index.ts +0 -4
- package/src/batcher/createBatcher.ts +0 -199
- package/src/batcher/index.ts +0 -3
- package/src/debouncer/createDebouncedSignal.ts +0 -92
- package/src/debouncer/createDebouncedValue.ts +0 -85
- package/src/debouncer/createDebouncer.ts +0 -201
- package/src/debouncer/index.ts +0 -6
- package/src/index.ts +0 -46
- package/src/provider/PacerProvider.tsx +0 -63
- package/src/provider/index.ts +0 -1
- package/src/queuer/createQueuedSignal.ts +0 -138
- package/src/queuer/createQueuer.ts +0 -199
- package/src/queuer/index.ts +0 -4
- package/src/rate-limiter/createRateLimitedSignal.ts +0 -117
- package/src/rate-limiter/createRateLimitedValue.ts +0 -110
- package/src/rate-limiter/createRateLimiter.ts +0 -226
- package/src/rate-limiter/index.ts +0 -5
- package/src/throttler/createThrottledSignal.ts +0 -81
- package/src/throttler/createThrottledValue.ts +0 -82
- package/src/throttler/createThrottler.ts +0 -204
- package/src/throttler/index.ts +0 -6
- package/src/types/index.ts +0 -1
- package/src/utils/index.ts +0 -1
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { Store } from "@tanstack/solid-store";
|
|
2
|
-
import { Accessor, JSX } from "solid-js";
|
|
3
|
-
import { AnyFunction } from "@tanstack/pacer/types";
|
|
4
|
-
import { RateLimiter, RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
5
|
-
|
|
6
|
-
//#region src/rate-limiter/createRateLimiter.d.ts
|
|
7
|
-
interface SolidRateLimiterOptions<TFn extends AnyFunction, TSelected = {}> extends RateLimiterOptions<TFn> {
|
|
8
|
-
/**
|
|
9
|
-
* Optional callback invoked when the owning component unmounts. Receives the rate limiter instance.
|
|
10
|
-
* When provided, replaces the default cleanup; use it to call reset(), add logging, etc.
|
|
11
|
-
*/
|
|
12
|
-
onUnmount?: (rateLimiter: SolidRateLimiter<TFn, TSelected>) => void;
|
|
13
|
-
}
|
|
14
|
-
interface SolidRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Omit<RateLimiter<TFn>, 'store'> {
|
|
15
|
-
/**
|
|
16
|
-
* A Solid component that allows you to subscribe to the rate limiter state.
|
|
17
|
-
*
|
|
18
|
-
* This is useful for tracking specific parts of the rate limiter state
|
|
19
|
-
* deep in your component tree without needing to pass a selector to the hook.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>
|
|
23
|
-
* {(state) => (
|
|
24
|
-
* <div>Rejections: {state().rejectionCount}</div>
|
|
25
|
-
* )}
|
|
26
|
-
* </rateLimiter.Subscribe>
|
|
27
|
-
*/
|
|
28
|
-
Subscribe: <TSelected>(props: {
|
|
29
|
-
selector: (state: RateLimiterState) => TSelected;
|
|
30
|
-
children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
|
|
31
|
-
}) => JSX.Element;
|
|
32
|
-
/**
|
|
33
|
-
* Reactive state that will be updated when the rate limiter state changes
|
|
34
|
-
*
|
|
35
|
-
* Use this instead of `rateLimiter.store.state`
|
|
36
|
-
*/
|
|
37
|
-
readonly state: Accessor<Readonly<TSelected>>;
|
|
38
|
-
/**
|
|
39
|
-
* @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.
|
|
40
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
41
|
-
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
42
|
-
*/
|
|
43
|
-
readonly store: Store<Readonly<RateLimiterState>>;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.
|
|
47
|
-
*
|
|
48
|
-
* This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that
|
|
49
|
-
* you can integrate with any state management solution (createSignal, etc).
|
|
50
|
-
*
|
|
51
|
-
* Rate limiting is a simple "hard limit" approach that allows executions until a maximum count is reached within
|
|
52
|
-
* a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,
|
|
53
|
-
* it does not attempt to space out or collapse executions intelligently.
|
|
54
|
-
*
|
|
55
|
-
* The rate limiter supports two types of windows:
|
|
56
|
-
* - 'fixed': A strict window that resets after the window period. All executions within the window count
|
|
57
|
-
* towards the limit, and the window resets completely after the period.
|
|
58
|
-
* - 'sliding': A rolling window that allows executions as old ones expire. This provides a more
|
|
59
|
-
* consistent rate of execution over time.
|
|
60
|
-
*
|
|
61
|
-
* For smoother execution patterns:
|
|
62
|
-
* - Use throttling when you want consistent spacing between executions (e.g. UI updates)
|
|
63
|
-
* - Use debouncing when you want to collapse rapid-fire events (e.g. search input)
|
|
64
|
-
* - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)
|
|
65
|
-
*
|
|
66
|
-
* ## State Management and Selector
|
|
67
|
-
*
|
|
68
|
-
* The hook uses TanStack Store for reactive state management. You can subscribe to state changes
|
|
69
|
-
* in two ways:
|
|
70
|
-
*
|
|
71
|
-
* **1. Using `rateLimiter.Subscribe` component (Recommended for component tree subscriptions)**
|
|
72
|
-
*
|
|
73
|
-
* Use the `Subscribe` component to subscribe to state changes deep in your component tree without
|
|
74
|
-
* needing to pass a selector to the hook. This is ideal when you want to subscribe to state
|
|
75
|
-
* in child components.
|
|
76
|
-
*
|
|
77
|
-
* **2. Using the `selector` parameter (For hook-level subscriptions)**
|
|
78
|
-
*
|
|
79
|
-
* The `selector` parameter allows you to specify which state changes will trigger reactive updates
|
|
80
|
-
* at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
|
|
81
|
-
* state changes occur.
|
|
82
|
-
*
|
|
83
|
-
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
84
|
-
* tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
|
|
85
|
-
* updates and gives you full control over when your component tracks state changes.
|
|
86
|
-
*
|
|
87
|
-
* Available state properties:
|
|
88
|
-
* - `executionCount`: Number of function executions that have been completed
|
|
89
|
-
* - `rejectionCount`: Number of function calls that were rejected due to rate limiting
|
|
90
|
-
* - `remainingInWindow`: Number of executions remaining in the current window
|
|
91
|
-
* - `nextWindowTime`: Timestamp when the next window begins
|
|
92
|
-
* - `currentWindowStart`: Timestamp when the current window started
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```tsx
|
|
96
|
-
* // Default behavior - no reactive state subscriptions
|
|
97
|
-
* const rateLimiter = createRateLimiter(apiCall, {
|
|
98
|
-
* limit: 5,
|
|
99
|
-
* window: 60000,
|
|
100
|
-
* windowType: 'sliding',
|
|
101
|
-
* });
|
|
102
|
-
*
|
|
103
|
-
* // Subscribe to state changes deep in component tree using Subscribe component
|
|
104
|
-
* <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>
|
|
105
|
-
* {(state) => (
|
|
106
|
-
* <div>Rejections: {state().rejectionCount}</div>
|
|
107
|
-
* )}
|
|
108
|
-
* </rateLimiter.Subscribe>
|
|
109
|
-
*
|
|
110
|
-
* // Opt-in to track execution count changes at hook level (optimized for tracking successful executions)
|
|
111
|
-
* const rateLimiter = createRateLimiter(
|
|
112
|
-
* apiCall,
|
|
113
|
-
* {
|
|
114
|
-
* limit: 5,
|
|
115
|
-
* window: 60000,
|
|
116
|
-
* windowType: 'sliding',
|
|
117
|
-
* },
|
|
118
|
-
* (state) => ({ executionCount: state.executionCount })
|
|
119
|
-
* );
|
|
120
|
-
*
|
|
121
|
-
* // Opt-in to track rejection count changes (optimized for tracking rate limit violations)
|
|
122
|
-
* const rateLimiter = createRateLimiter(
|
|
123
|
-
* apiCall,
|
|
124
|
-
* {
|
|
125
|
-
* limit: 5,
|
|
126
|
-
* window: 60000,
|
|
127
|
-
* windowType: 'sliding',
|
|
128
|
-
* },
|
|
129
|
-
* (state) => ({ rejectionCount: state.rejectionCount })
|
|
130
|
-
* );
|
|
131
|
-
*
|
|
132
|
-
* // Opt-in to track execution times changes (optimized for window calculations)
|
|
133
|
-
* const rateLimiter = createRateLimiter(
|
|
134
|
-
* apiCall,
|
|
135
|
-
* {
|
|
136
|
-
* limit: 5,
|
|
137
|
-
* window: 60000,
|
|
138
|
-
* windowType: 'sliding',
|
|
139
|
-
* },
|
|
140
|
-
* (state) => ({ executionTimes: state.executionTimes })
|
|
141
|
-
* );
|
|
142
|
-
*
|
|
143
|
-
* // Multiple state properties - track when any of these change
|
|
144
|
-
* const rateLimiter = createRateLimiter(
|
|
145
|
-
* apiCall,
|
|
146
|
-
* {
|
|
147
|
-
* limit: 5,
|
|
148
|
-
* window: 60000,
|
|
149
|
-
* windowType: 'sliding',
|
|
150
|
-
* },
|
|
151
|
-
* (state) => ({
|
|
152
|
-
* executionCount: state.executionCount,
|
|
153
|
-
* rejectionCount: state.rejectionCount
|
|
154
|
-
* })
|
|
155
|
-
* );
|
|
156
|
-
*
|
|
157
|
-
* // Monitor rate limit status
|
|
158
|
-
* const handleClick = () => {
|
|
159
|
-
* const remaining = rateLimiter.getRemainingInWindow();
|
|
160
|
-
* if (remaining > 0) {
|
|
161
|
-
* rateLimiter.maybeExecute(data);
|
|
162
|
-
* } else {
|
|
163
|
-
* showRateLimitWarning();
|
|
164
|
-
* }
|
|
165
|
-
* };
|
|
166
|
-
*
|
|
167
|
-
* // Access the selected state (will be empty object {} unless selector provided)
|
|
168
|
-
* const { executionCount, rejectionCount } = rateLimiter.state();
|
|
169
|
-
* ```
|
|
170
|
-
*/
|
|
171
|
-
declare function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: SolidRateLimiterOptions<TFn, TSelected>, selector?: (state: RateLimiterState) => TSelected): SolidRateLimiter<TFn, TSelected>;
|
|
172
|
-
//#endregion
|
|
173
|
-
export { SolidRateLimiter, SolidRateLimiterOptions, createRateLimiter };
|
|
174
|
-
//# sourceMappingURL=createRateLimiter.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createRateLimiter.js","names":[],"sources":["../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { shallow, useSelector } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\nexport interface SolidRateLimiterOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends RateLimiterOptions<TFn> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the rate limiter instance.\n * When provided, replaces the default cleanup; use it to call reset(), add logging, etc.\n */\n onUnmount?: (rateLimiter: SolidRateLimiter<TFn, TSelected>) => void\n}\n\nexport interface SolidRateLimiter<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<RateLimiter<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the rate limiter state.\n *\n * This is useful for tracking specific parts of the rate limiter state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>\n * {(state) => (\n * <div>Rejections: {state().rejectionCount}</div>\n * )}\n * </rateLimiter.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: RateLimiterState) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `rateLimiter.state` instead of `rateLimiter.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 `useSelector` hook internally.\n * Although, you can make the state reactive by using the `useSelector` in your own usage.\n */\n readonly store: Store<Readonly<RateLimiterState>>\n}\n\n/**\n * A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Rate limiting is a simple \"hard limit\" approach that allows executions until a maximum count is reached within\n * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,\n * it does not attempt to space out or collapse executions intelligently.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n * consistent rate of execution over time.\n *\n * For smoother execution patterns:\n * - Use throttling when you want consistent spacing between executions (e.g. UI updates)\n * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)\n * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `rateLimiter.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * 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 or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `rejectionCount`: Number of function calls that were rejected due to rate limiting\n * - `remainingInWindow`: Number of executions remaining in the current window\n * - `nextWindowTime`: Timestamp when the next window begins\n * - `currentWindowStart`: Timestamp when the current window started\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = createRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * });\n *\n * // Subscribe to state changes deep in component tree using Subscribe component\n * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>\n * {(state) => (\n * <div>Rejections: {state().rejectionCount}</div>\n * )}\n * </rateLimiter.Subscribe>\n *\n * // Opt-in to track execution count changes at hook level (optimized for tracking successful executions)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to track rejection count changes (optimized for tracking rate limit violations)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to track execution times changes (optimized for window calculations)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // Multiple state properties - track when any of these change\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({\n * executionCount: state.executionCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Monitor rate limit status\n * const handleClick = () => {\n * const remaining = rateLimiter.getRemainingInWindow();\n * if (remaining > 0) {\n * rateLimiter.maybeExecute(data);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { executionCount, rejectionCount } = rateLimiter.state();\n * ```\n */\nexport function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: SolidRateLimiterOptions<TFn, TSelected>,\n selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,\n): SolidRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().rateLimiter,\n ...options,\n } as SolidRateLimiterOptions<TFn, TSelected>\n const rateLimiter = new RateLimiter<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidRateLimiter<TFn, TSelected>\n\n rateLimiter.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: RateLimiterState) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(rateLimiter.store, props.selector, {\n compare: shallow,\n })\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useSelector(rateLimiter.store, selector, { compare: shallow })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(rateLimiter)\n }\n })\n })\n\n return {\n ...rateLimiter,\n state,\n } as SolidRateLimiter<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwLA,SAAgB,kBACd,IACA,SACA,kBAA0D,EAAE,GAC1B;CAClC,MAAM,gBAAgB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,cAAc,IAAI,YACtB,IACA,cACD;CAED,YAAY,YAAY,SAAS,UAAqB,OAGnD;EACD,MAAM,WAAW,YAAY,YAAY,OAAO,MAAM,UAAU,EAC9D,SAAS,SACV,CAAC;EAEF,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,QAAQ,YAAY,YAAY,OAAO,UAAU,EAAE,SAAS,SAAS,CAAC;CAE5E,mBAAmB;EACjB,gBAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,YAAY;IAEtC;GACF;CAEF,OAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_createRateLimiter = require('./createRateLimiter.cjs');
|
|
3
|
-
const require_createRateLimitedSignal = require('./createRateLimitedSignal.cjs');
|
|
4
|
-
const require_createRateLimitedValue = require('./createRateLimitedValue.cjs');
|
|
5
|
-
|
|
6
|
-
exports.createRateLimitedSignal = require_createRateLimitedSignal.createRateLimitedSignal;
|
|
7
|
-
exports.createRateLimitedValue = require_createRateLimitedValue.createRateLimitedValue;
|
|
8
|
-
exports.createRateLimiter = require_createRateLimiter.createRateLimiter;
|
|
9
|
-
var _tanstack_pacer_rate_limiter = require("@tanstack/pacer/rate-limiter");
|
|
10
|
-
Object.keys(_tanstack_pacer_rate_limiter).forEach(function (k) {
|
|
11
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function () { return _tanstack_pacer_rate_limiter[k]; }
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { SolidRateLimiter, SolidRateLimiterOptions, createRateLimiter } from "./createRateLimiter.cjs";
|
|
2
|
-
import { createRateLimitedSignal } from "./createRateLimitedSignal.cjs";
|
|
3
|
-
import { createRateLimitedValue } from "./createRateLimitedValue.cjs";
|
|
4
|
-
export * from "@tanstack/pacer/rate-limiter";
|
|
5
|
-
export { SolidRateLimiter, SolidRateLimiterOptions, createRateLimitedSignal, createRateLimitedValue, createRateLimiter };
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
const require_createThrottler = require('./createThrottler.cjs');
|
|
2
|
-
let solid_js = require("solid-js");
|
|
3
|
-
|
|
4
|
-
//#region src/throttler/createThrottledSignal.ts
|
|
5
|
-
/**
|
|
6
|
-
* A Solid hook that creates a throttled state value that updates at most once within a specified time window.
|
|
7
|
-
* This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.
|
|
8
|
-
*
|
|
9
|
-
* Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.
|
|
10
|
-
* This is useful for rate-limiting expensive updates or operations that depend on rapidly changing state.
|
|
11
|
-
*
|
|
12
|
-
* The hook returns a tuple containing:
|
|
13
|
-
* - The throttled state value accessor
|
|
14
|
-
* - A throttled setter function that respects the configured wait time
|
|
15
|
-
* - The throttler instance for additional control
|
|
16
|
-
*
|
|
17
|
-
* For more direct control over throttling without state management,
|
|
18
|
-
* consider using the lower-level createThrottler hook instead.
|
|
19
|
-
*
|
|
20
|
-
* ## State Management and Selector
|
|
21
|
-
*
|
|
22
|
-
* The hook uses TanStack Store for reactive state management via the underlying throttler instance.
|
|
23
|
-
* The `selector` parameter allows you to specify which throttler state changes will trigger reactive updates,
|
|
24
|
-
* optimizing performance by preventing unnecessary subscriptions 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 reactive updates and gives you
|
|
28
|
-
* full control over when your component subscribes to state changes. Only when you provide a selector will
|
|
29
|
-
* the reactive system track the selected state values.
|
|
30
|
-
*
|
|
31
|
-
* Available throttler state properties:
|
|
32
|
-
* - `canLeadingExecute`: Whether the throttler can execute on the leading edge
|
|
33
|
-
* - `canTrailingExecute`: Whether the throttler can execute on the trailing edge
|
|
34
|
-
* - `executionCount`: Number of function executions that have been completed
|
|
35
|
-
* - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution
|
|
36
|
-
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
37
|
-
* - `lastExecutionTime`: Unix timestamp of the last execution
|
|
38
|
-
* - `nextExecutionTime`: Unix timestamp of the next allowed execution
|
|
39
|
-
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```tsx
|
|
43
|
-
* // Default behavior - no reactive state subscriptions
|
|
44
|
-
* const [value, setValue, throttler] = createThrottledSignal(0, { wait: 1000 });
|
|
45
|
-
*
|
|
46
|
-
* // Opt-in to reactive updates when pending state changes (optimized for loading indicators)
|
|
47
|
-
* const [value, setValue, throttler] = createThrottledSignal(
|
|
48
|
-
* 0,
|
|
49
|
-
* { wait: 1000 },
|
|
50
|
-
* (state) => ({ isPending: state.isPending })
|
|
51
|
-
* );
|
|
52
|
-
*
|
|
53
|
-
* // With custom leading/trailing behavior
|
|
54
|
-
* const [value, setValue] = createThrottledSignal(0, {
|
|
55
|
-
* wait: 1000,
|
|
56
|
-
* leading: true, // Update immediately on first change
|
|
57
|
-
* trailing: false // Skip trailing edge updates
|
|
58
|
-
* });
|
|
59
|
-
*
|
|
60
|
-
* // Access throttler state via signals
|
|
61
|
-
* console.log('Executions:', throttler.state().executionCount);
|
|
62
|
-
* console.log('Is pending:', throttler.state().isPending);
|
|
63
|
-
* console.log('Last execution:', throttler.state().lastExecutionTime);
|
|
64
|
-
* console.log('Next execution:', throttler.state().nextExecutionTime);
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
function createThrottledSignal(value, initialOptions, selector) {
|
|
68
|
-
const [throttledValue, setThrottledValue] = (0, solid_js.createSignal)(value);
|
|
69
|
-
const throttler = require_createThrottler.createThrottler(setThrottledValue, initialOptions, selector);
|
|
70
|
-
return [
|
|
71
|
-
throttledValue,
|
|
72
|
-
throttler.maybeExecute,
|
|
73
|
-
throttler
|
|
74
|
-
];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
//#endregion
|
|
78
|
-
exports.createThrottledSignal = createThrottledSignal;
|
|
79
|
-
//# sourceMappingURL=createThrottledSignal.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createThrottledSignal.cjs","names":["createThrottler"],"sources":["../../src/throttler/createThrottledSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createThrottler } from './createThrottler'\nimport type { SolidThrottler, SolidThrottlerOptions } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { ThrottlerState } from '@tanstack/pacer/throttler'\n\n/**\n * A Solid hook that creates a throttled state value that updates at most once within a specified time window.\n * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.\n *\n * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.\n * This is useful for rate-limiting expensive updates or operations that depend on rapidly changing state.\n *\n * The hook returns a tuple containing:\n * - The throttled state value accessor\n * - A throttled setter function that respects the configured wait time\n * - The throttler instance for additional control\n *\n * For more direct control over throttling without state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler 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 throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Unix timestamp of the last execution\n * - `nextExecutionTime`: Unix timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [value, setValue, throttler] = createThrottledSignal(0, { wait: 1000 });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [value, setValue, throttler] = createThrottledSignal(\n * 0,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // With custom leading/trailing behavior\n * const [value, setValue] = createThrottledSignal(0, {\n * wait: 1000,\n * leading: true, // Update immediately on first change\n * trailing: false // Skip trailing edge updates\n * });\n *\n * // Access throttler state via signals\n * console.log('Executions:', throttler.state().executionCount);\n * console.log('Is pending:', throttler.state().isPending);\n * console.log('Last execution:', throttler.state().lastExecutionTime);\n * console.log('Next execution:', throttler.state().nextExecutionTime);\n * ```\n */\nexport function createThrottledSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: SolidThrottlerOptions<Setter<TValue>, TSelected>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidThrottler<Setter<TValue>, TSelected>,\n] {\n const [throttledValue, setThrottledValue] = createSignal<TValue>(value)\n const throttler = createThrottler(setThrottledValue, initialOptions, selector)\n return [throttledValue, throttler.maybeExecute as Setter<TValue>, throttler]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,sBACd,OACA,gBACA,UAKA;CACA,MAAM,CAAC,gBAAgB,gDAA0C,MAAM;CACvE,MAAM,YAAYA,wCAAgB,mBAAmB,gBAAgB,SAAS;CAC9E,OAAO;EAAC;EAAgB,UAAU;EAAgC;EAAU"}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { SolidThrottler, SolidThrottlerOptions } from "./createThrottler.cjs";
|
|
2
|
-
import { Accessor, Setter } from "solid-js";
|
|
3
|
-
import { ThrottlerState } from "@tanstack/pacer/throttler";
|
|
4
|
-
|
|
5
|
-
//#region src/throttler/createThrottledSignal.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* A Solid hook that creates a throttled state value that updates at most once within a specified time window.
|
|
8
|
-
* This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.
|
|
9
|
-
*
|
|
10
|
-
* Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.
|
|
11
|
-
* This is useful for rate-limiting expensive updates or operations that depend on rapidly changing state.
|
|
12
|
-
*
|
|
13
|
-
* The hook returns a tuple containing:
|
|
14
|
-
* - The throttled state value accessor
|
|
15
|
-
* - A throttled setter function that respects the configured wait time
|
|
16
|
-
* - The throttler instance for additional control
|
|
17
|
-
*
|
|
18
|
-
* For more direct control over throttling without state management,
|
|
19
|
-
* consider using the lower-level createThrottler hook instead.
|
|
20
|
-
*
|
|
21
|
-
* ## State Management and Selector
|
|
22
|
-
*
|
|
23
|
-
* The hook uses TanStack Store for reactive state management via the underlying throttler instance.
|
|
24
|
-
* The `selector` parameter allows you to specify which throttler state changes will trigger reactive updates,
|
|
25
|
-
* optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
|
|
26
|
-
*
|
|
27
|
-
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
28
|
-
* tracking by providing a selector function. This prevents unnecessary reactive updates and gives you
|
|
29
|
-
* full control over when your component subscribes to state changes. Only when you provide a selector will
|
|
30
|
-
* the reactive system track the selected state values.
|
|
31
|
-
*
|
|
32
|
-
* Available throttler state properties:
|
|
33
|
-
* - `canLeadingExecute`: Whether the throttler can execute on the leading edge
|
|
34
|
-
* - `canTrailingExecute`: Whether the throttler can execute on the trailing edge
|
|
35
|
-
* - `executionCount`: Number of function executions that have been completed
|
|
36
|
-
* - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution
|
|
37
|
-
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
38
|
-
* - `lastExecutionTime`: Unix timestamp of the last execution
|
|
39
|
-
* - `nextExecutionTime`: Unix timestamp of the next allowed execution
|
|
40
|
-
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```tsx
|
|
44
|
-
* // Default behavior - no reactive state subscriptions
|
|
45
|
-
* const [value, setValue, throttler] = createThrottledSignal(0, { wait: 1000 });
|
|
46
|
-
*
|
|
47
|
-
* // Opt-in to reactive updates when pending state changes (optimized for loading indicators)
|
|
48
|
-
* const [value, setValue, throttler] = createThrottledSignal(
|
|
49
|
-
* 0,
|
|
50
|
-
* { wait: 1000 },
|
|
51
|
-
* (state) => ({ isPending: state.isPending })
|
|
52
|
-
* );
|
|
53
|
-
*
|
|
54
|
-
* // With custom leading/trailing behavior
|
|
55
|
-
* const [value, setValue] = createThrottledSignal(0, {
|
|
56
|
-
* wait: 1000,
|
|
57
|
-
* leading: true, // Update immediately on first change
|
|
58
|
-
* trailing: false // Skip trailing edge updates
|
|
59
|
-
* });
|
|
60
|
-
*
|
|
61
|
-
* // Access throttler state via signals
|
|
62
|
-
* console.log('Executions:', throttler.state().executionCount);
|
|
63
|
-
* console.log('Is pending:', throttler.state().isPending);
|
|
64
|
-
* console.log('Last execution:', throttler.state().lastExecutionTime);
|
|
65
|
-
* console.log('Next execution:', throttler.state().nextExecutionTime);
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
declare function createThrottledSignal<TValue, TSelected = {}>(value: TValue, initialOptions: SolidThrottlerOptions<Setter<TValue>, TSelected>, selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected): [Accessor<TValue>, Setter<TValue>, SolidThrottler<Setter<TValue>, TSelected>];
|
|
69
|
-
//#endregion
|
|
70
|
-
export { createThrottledSignal };
|
|
71
|
-
//# sourceMappingURL=createThrottledSignal.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createThrottledSignal.js","names":[],"sources":["../../src/throttler/createThrottledSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createThrottler } from './createThrottler'\nimport type { SolidThrottler, SolidThrottlerOptions } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { ThrottlerState } from '@tanstack/pacer/throttler'\n\n/**\n * A Solid hook that creates a throttled state value that updates at most once within a specified time window.\n * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.\n *\n * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.\n * This is useful for rate-limiting expensive updates or operations that depend on rapidly changing state.\n *\n * The hook returns a tuple containing:\n * - The throttled state value accessor\n * - A throttled setter function that respects the configured wait time\n * - The throttler instance for additional control\n *\n * For more direct control over throttling without state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler 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 throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Unix timestamp of the last execution\n * - `nextExecutionTime`: Unix timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [value, setValue, throttler] = createThrottledSignal(0, { wait: 1000 });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [value, setValue, throttler] = createThrottledSignal(\n * 0,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // With custom leading/trailing behavior\n * const [value, setValue] = createThrottledSignal(0, {\n * wait: 1000,\n * leading: true, // Update immediately on first change\n * trailing: false // Skip trailing edge updates\n * });\n *\n * // Access throttler state via signals\n * console.log('Executions:', throttler.state().executionCount);\n * console.log('Is pending:', throttler.state().isPending);\n * console.log('Last execution:', throttler.state().lastExecutionTime);\n * console.log('Next execution:', throttler.state().nextExecutionTime);\n * ```\n */\nexport function createThrottledSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: SolidThrottlerOptions<Setter<TValue>, TSelected>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidThrottler<Setter<TValue>, TSelected>,\n] {\n const [throttledValue, setThrottledValue] = createSignal<TValue>(value)\n const throttler = createThrottler(setThrottledValue, initialOptions, selector)\n return [throttledValue, throttler.maybeExecute as Setter<TValue>, throttler]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,sBACd,OACA,gBACA,UAKA;CACA,MAAM,CAAC,gBAAgB,qBAAqB,aAAqB,MAAM;CACvE,MAAM,YAAY,gBAAgB,mBAAmB,gBAAgB,SAAS;CAC9E,OAAO;EAAC;EAAgB,UAAU;EAAgC;EAAU"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
const require_createThrottledSignal = require('./createThrottledSignal.cjs');
|
|
2
|
-
let solid_js = require("solid-js");
|
|
3
|
-
|
|
4
|
-
//#region src/throttler/createThrottledValue.ts
|
|
5
|
-
/**
|
|
6
|
-
* A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window.
|
|
7
|
-
* This hook uses Solid's createSignal internally to manage the throttled state.
|
|
8
|
-
*
|
|
9
|
-
* Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.
|
|
10
|
-
* This is useful for rate-limiting expensive updates or API calls that depend on rapidly changing values.
|
|
11
|
-
*
|
|
12
|
-
* The hook returns a tuple containing:
|
|
13
|
-
* - An accessor function that provides the throttled value
|
|
14
|
-
* - The throttler instance with control methods
|
|
15
|
-
*
|
|
16
|
-
* The throttled value will update according to the leading/trailing edge behavior specified in the options.
|
|
17
|
-
*
|
|
18
|
-
* For more direct control over throttling behavior without Solid state management,
|
|
19
|
-
* consider using the lower-level createThrottler hook instead.
|
|
20
|
-
*
|
|
21
|
-
* ## State Management and Selector
|
|
22
|
-
*
|
|
23
|
-
* The hook uses TanStack Store for reactive state management via the underlying throttler instance.
|
|
24
|
-
* The `selector` parameter allows you to specify which throttler state changes will trigger reactive updates,
|
|
25
|
-
* optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
|
|
26
|
-
*
|
|
27
|
-
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
28
|
-
* tracking by providing a selector function. This prevents unnecessary reactive updates and gives you
|
|
29
|
-
* full control over when your component subscribes to state changes. Only when you provide a selector will
|
|
30
|
-
* the reactive system track the selected state values.
|
|
31
|
-
*
|
|
32
|
-
* Available throttler state properties:
|
|
33
|
-
* - `canLeadingExecute`: Whether the throttler can execute on the leading edge
|
|
34
|
-
* - `canTrailingExecute`: Whether the throttler can execute on the trailing edge
|
|
35
|
-
* - `executionCount`: Number of function executions that have been completed
|
|
36
|
-
* - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution
|
|
37
|
-
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
38
|
-
* - `lastExecutionTime`: Unix timestamp of the last execution
|
|
39
|
-
* - `nextExecutionTime`: Unix timestamp of the next allowed execution
|
|
40
|
-
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```tsx
|
|
44
|
-
* // Default behavior - no reactive state subscriptions
|
|
45
|
-
* const [throttledValue, throttler] = createThrottledValue(rawValue, { wait: 1000 });
|
|
46
|
-
*
|
|
47
|
-
* // Opt-in to reactive updates when pending state changes (optimized for loading indicators)
|
|
48
|
-
* const [throttledValue, throttler] = createThrottledValue(
|
|
49
|
-
* rawValue,
|
|
50
|
-
* { wait: 1000 },
|
|
51
|
-
* (state) => ({ isPending: state.isPending })
|
|
52
|
-
* );
|
|
53
|
-
*
|
|
54
|
-
* // Use the throttled value
|
|
55
|
-
* console.log(throttledValue()); // Access the current throttled value
|
|
56
|
-
*
|
|
57
|
-
* // Access throttler state via signals
|
|
58
|
-
* console.log('Is pending:', throttler.state().isPending);
|
|
59
|
-
*
|
|
60
|
-
* // Control the throttler
|
|
61
|
-
* throttler.cancel(); // Cancel any pending updates
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
function createThrottledValue(value, initialOptions, selector) {
|
|
65
|
-
const [throttledValue, setThrottledValue, throttler] = require_createThrottledSignal.createThrottledSignal(value(), initialOptions, selector);
|
|
66
|
-
(0, solid_js.createEffect)(() => {
|
|
67
|
-
setThrottledValue(value());
|
|
68
|
-
});
|
|
69
|
-
return [throttledValue, throttler];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
//#endregion
|
|
73
|
-
exports.createThrottledValue = createThrottledValue;
|
|
74
|
-
//# sourceMappingURL=createThrottledValue.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createThrottledValue.cjs","names":["createThrottledSignal"],"sources":["../../src/throttler/createThrottledValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createThrottledSignal } from './createThrottledSignal'\nimport type { SolidThrottler, SolidThrottlerOptions } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { ThrottlerState } from '@tanstack/pacer/throttler'\n\n/**\n * A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window.\n * This hook uses Solid's createSignal internally to manage the throttled state.\n *\n * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.\n * This is useful for rate-limiting expensive updates or API calls that depend on rapidly changing values.\n *\n * The hook returns a tuple containing:\n * - An accessor function that provides the throttled value\n * - The throttler instance with control methods\n *\n * The throttled value will update according to the leading/trailing edge behavior specified in the options.\n *\n * For more direct control over throttling behavior without Solid state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler 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 throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Unix timestamp of the last execution\n * - `nextExecutionTime`: Unix timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [throttledValue, throttler] = createThrottledValue(rawValue, { wait: 1000 });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [throttledValue, throttler] = createThrottledValue(\n * rawValue,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Use the throttled value\n * console.log(throttledValue()); // Access the current throttled value\n *\n * // Access throttler state via signals\n * console.log('Is pending:', throttler.state().isPending);\n *\n * // Control the throttler\n * throttler.cancel(); // Cancel any pending updates\n * ```\n */\nexport function createThrottledValue<TValue, TSelected = {}>(\n value: Accessor<TValue>,\n initialOptions: SolidThrottlerOptions<Setter<TValue>, TSelected>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): [Accessor<TValue>, SolidThrottler<Setter<TValue>, TSelected>] {\n const [throttledValue, setThrottledValue, throttler] = createThrottledSignal(\n value(),\n initialOptions,\n selector,\n )\n\n createEffect(() => {\n setThrottledValue(value() as any)\n })\n\n return [throttledValue, throttler]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAgB,qBACd,OACA,gBACA,UAC+D;CAC/D,MAAM,CAAC,gBAAgB,mBAAmB,aAAaA,oDACrD,OAAO,EACP,gBACA,SACD;CAED,iCAAmB;EACjB,kBAAkB,OAAO,CAAQ;GACjC;CAEF,OAAO,CAAC,gBAAgB,UAAU"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { SolidThrottler, SolidThrottlerOptions } from "./createThrottler.cjs";
|
|
2
|
-
import { Accessor, Setter } from "solid-js";
|
|
3
|
-
import { ThrottlerState } from "@tanstack/pacer/throttler";
|
|
4
|
-
|
|
5
|
-
//#region src/throttler/createThrottledValue.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window.
|
|
8
|
-
* This hook uses Solid's createSignal internally to manage the throttled state.
|
|
9
|
-
*
|
|
10
|
-
* Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.
|
|
11
|
-
* This is useful for rate-limiting expensive updates or API calls that depend on rapidly changing values.
|
|
12
|
-
*
|
|
13
|
-
* The hook returns a tuple containing:
|
|
14
|
-
* - An accessor function that provides the throttled value
|
|
15
|
-
* - The throttler instance with control methods
|
|
16
|
-
*
|
|
17
|
-
* The throttled value will update according to the leading/trailing edge behavior specified in the options.
|
|
18
|
-
*
|
|
19
|
-
* For more direct control over throttling behavior without Solid state management,
|
|
20
|
-
* consider using the lower-level createThrottler hook instead.
|
|
21
|
-
*
|
|
22
|
-
* ## State Management and Selector
|
|
23
|
-
*
|
|
24
|
-
* The hook uses TanStack Store for reactive state management via the underlying throttler instance.
|
|
25
|
-
* The `selector` parameter allows you to specify which throttler state changes will trigger reactive updates,
|
|
26
|
-
* optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
|
|
27
|
-
*
|
|
28
|
-
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
29
|
-
* tracking by providing a selector function. This prevents unnecessary reactive updates and gives you
|
|
30
|
-
* full control over when your component subscribes to state changes. Only when you provide a selector will
|
|
31
|
-
* the reactive system track the selected state values.
|
|
32
|
-
*
|
|
33
|
-
* Available throttler state properties:
|
|
34
|
-
* - `canLeadingExecute`: Whether the throttler can execute on the leading edge
|
|
35
|
-
* - `canTrailingExecute`: Whether the throttler can execute on the trailing edge
|
|
36
|
-
* - `executionCount`: Number of function executions that have been completed
|
|
37
|
-
* - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution
|
|
38
|
-
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
39
|
-
* - `lastExecutionTime`: Unix timestamp of the last execution
|
|
40
|
-
* - `nextExecutionTime`: Unix timestamp of the next allowed execution
|
|
41
|
-
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```tsx
|
|
45
|
-
* // Default behavior - no reactive state subscriptions
|
|
46
|
-
* const [throttledValue, throttler] = createThrottledValue(rawValue, { wait: 1000 });
|
|
47
|
-
*
|
|
48
|
-
* // Opt-in to reactive updates when pending state changes (optimized for loading indicators)
|
|
49
|
-
* const [throttledValue, throttler] = createThrottledValue(
|
|
50
|
-
* rawValue,
|
|
51
|
-
* { wait: 1000 },
|
|
52
|
-
* (state) => ({ isPending: state.isPending })
|
|
53
|
-
* );
|
|
54
|
-
*
|
|
55
|
-
* // Use the throttled value
|
|
56
|
-
* console.log(throttledValue()); // Access the current throttled value
|
|
57
|
-
*
|
|
58
|
-
* // Access throttler state via signals
|
|
59
|
-
* console.log('Is pending:', throttler.state().isPending);
|
|
60
|
-
*
|
|
61
|
-
* // Control the throttler
|
|
62
|
-
* throttler.cancel(); // Cancel any pending updates
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
declare function createThrottledValue<TValue, TSelected = {}>(value: Accessor<TValue>, initialOptions: SolidThrottlerOptions<Setter<TValue>, TSelected>, selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected): [Accessor<TValue>, SolidThrottler<Setter<TValue>, TSelected>];
|
|
66
|
-
//#endregion
|
|
67
|
-
export { createThrottledValue };
|
|
68
|
-
//# sourceMappingURL=createThrottledValue.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createThrottledValue.js","names":[],"sources":["../../src/throttler/createThrottledValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createThrottledSignal } from './createThrottledSignal'\nimport type { SolidThrottler, SolidThrottlerOptions } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { ThrottlerState } from '@tanstack/pacer/throttler'\n\n/**\n * A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window.\n * This hook uses Solid's createSignal internally to manage the throttled state.\n *\n * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.\n * This is useful for rate-limiting expensive updates or API calls that depend on rapidly changing values.\n *\n * The hook returns a tuple containing:\n * - An accessor function that provides the throttled value\n * - The throttler instance with control methods\n *\n * The throttled value will update according to the leading/trailing edge behavior specified in the options.\n *\n * For more direct control over throttling behavior without Solid state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler 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 throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Unix timestamp of the last execution\n * - `nextExecutionTime`: Unix timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [throttledValue, throttler] = createThrottledValue(rawValue, { wait: 1000 });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [throttledValue, throttler] = createThrottledValue(\n * rawValue,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Use the throttled value\n * console.log(throttledValue()); // Access the current throttled value\n *\n * // Access throttler state via signals\n * console.log('Is pending:', throttler.state().isPending);\n *\n * // Control the throttler\n * throttler.cancel(); // Cancel any pending updates\n * ```\n */\nexport function createThrottledValue<TValue, TSelected = {}>(\n value: Accessor<TValue>,\n initialOptions: SolidThrottlerOptions<Setter<TValue>, TSelected>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): [Accessor<TValue>, SolidThrottler<Setter<TValue>, TSelected>] {\n const [throttledValue, setThrottledValue, throttler] = createThrottledSignal(\n value(),\n initialOptions,\n selector,\n )\n\n createEffect(() => {\n setThrottledValue(value() as any)\n })\n\n return [throttledValue, throttler]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAgB,qBACd,OACA,gBACA,UAC+D;CAC/D,MAAM,CAAC,gBAAgB,mBAAmB,aAAa,sBACrD,OAAO,EACP,gBACA,SACD;CAED,mBAAmB;EACjB,kBAAkB,OAAO,CAAQ;GACjC;CAEF,OAAO,CAAC,gBAAgB,UAAU"}
|