@tanstack/solid-pacer 0.17.0 → 0.18.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/dist/async-batcher/createAsyncBatcher.cjs +26 -12
- package/dist/async-batcher/createAsyncBatcher.cjs.map +1 -1
- package/dist/async-batcher/createAsyncBatcher.d.cts +36 -9
- package/dist/async-batcher/createAsyncBatcher.d.ts +36 -9
- package/dist/async-batcher/createAsyncBatcher.js +22 -8
- package/dist/async-batcher/createAsyncBatcher.js.map +1 -1
- package/dist/async-batcher/index.cjs +3 -3
- package/dist/async-debouncer/createAsyncDebouncer.cjs +26 -12
- package/dist/async-debouncer/createAsyncDebouncer.cjs.map +1 -1
- package/dist/async-debouncer/createAsyncDebouncer.d.cts +36 -9
- package/dist/async-debouncer/createAsyncDebouncer.d.ts +36 -9
- package/dist/async-debouncer/createAsyncDebouncer.js +22 -8
- package/dist/async-debouncer/createAsyncDebouncer.js.map +1 -1
- package/dist/async-debouncer/index.cjs +3 -3
- package/dist/async-queuer/createAsyncQueuer.cjs +26 -12
- package/dist/async-queuer/createAsyncQueuer.cjs.map +1 -1
- package/dist/async-queuer/createAsyncQueuer.d.cts +36 -9
- package/dist/async-queuer/createAsyncQueuer.d.ts +36 -9
- package/dist/async-queuer/createAsyncQueuer.js +22 -8
- package/dist/async-queuer/createAsyncQueuer.js.map +1 -1
- package/dist/async-queuer/index.cjs +3 -3
- package/dist/async-rate-limiter/createAsyncRateLimiter.cjs +89 -30
- package/dist/async-rate-limiter/createAsyncRateLimiter.cjs.map +1 -1
- package/dist/async-rate-limiter/createAsyncRateLimiter.d.cts +99 -27
- package/dist/async-rate-limiter/createAsyncRateLimiter.d.ts +99 -27
- package/dist/async-rate-limiter/createAsyncRateLimiter.js +85 -26
- package/dist/async-rate-limiter/createAsyncRateLimiter.js.map +1 -1
- package/dist/async-rate-limiter/index.cjs +3 -3
- package/dist/async-throttler/createAsyncThrottler.cjs +26 -12
- package/dist/async-throttler/createAsyncThrottler.cjs.map +1 -1
- package/dist/async-throttler/createAsyncThrottler.d.cts +36 -9
- package/dist/async-throttler/createAsyncThrottler.d.ts +36 -9
- package/dist/async-throttler/createAsyncThrottler.js +22 -8
- package/dist/async-throttler/createAsyncThrottler.js.map +1 -1
- package/dist/async-throttler/index.cjs +3 -3
- package/dist/batcher/createBatcher.cjs +26 -12
- package/dist/batcher/createBatcher.cjs.map +1 -1
- package/dist/batcher/createBatcher.d.cts +36 -9
- package/dist/batcher/createBatcher.d.ts +36 -9
- package/dist/batcher/createBatcher.js +22 -8
- package/dist/batcher/createBatcher.js.map +1 -1
- package/dist/batcher/index.cjs +3 -3
- package/dist/debouncer/createDebouncer.cjs +27 -13
- package/dist/debouncer/createDebouncer.cjs.map +1 -1
- package/dist/debouncer/createDebouncer.d.cts +37 -10
- package/dist/debouncer/createDebouncer.d.ts +37 -10
- package/dist/debouncer/createDebouncer.js +23 -9
- package/dist/debouncer/createDebouncer.js.map +1 -1
- package/dist/debouncer/index.cjs +3 -3
- package/dist/index.cjs +3 -3
- package/dist/queuer/createQueuedSignal.cjs +8 -8
- package/dist/queuer/createQueuedSignal.cjs.map +1 -1
- package/dist/queuer/createQueuedSignal.d.cts +8 -8
- package/dist/queuer/createQueuedSignal.d.ts +8 -8
- package/dist/queuer/createQueuedSignal.js +8 -8
- package/dist/queuer/createQueuedSignal.js.map +1 -1
- package/dist/queuer/createQueuer.cjs +26 -12
- package/dist/queuer/createQueuer.cjs.map +1 -1
- package/dist/queuer/createQueuer.d.cts +36 -9
- package/dist/queuer/createQueuer.d.ts +36 -9
- package/dist/queuer/createQueuer.js +22 -8
- package/dist/queuer/createQueuer.js.map +1 -1
- package/dist/queuer/index.cjs +3 -3
- package/dist/rate-limiter/createRateLimiter.cjs +78 -23
- package/dist/rate-limiter/createRateLimiter.cjs.map +1 -1
- package/dist/rate-limiter/createRateLimiter.d.cts +88 -20
- package/dist/rate-limiter/createRateLimiter.d.ts +88 -20
- package/dist/rate-limiter/createRateLimiter.js +74 -19
- package/dist/rate-limiter/createRateLimiter.js.map +1 -1
- package/dist/rate-limiter/index.cjs +3 -3
- package/dist/throttler/createThrottledSignal.cjs +1 -1
- package/dist/throttler/createThrottledSignal.cjs.map +1 -1
- package/dist/throttler/createThrottledSignal.d.cts +1 -1
- package/dist/throttler/createThrottledSignal.d.ts +1 -1
- package/dist/throttler/createThrottledSignal.js +1 -1
- package/dist/throttler/createThrottledSignal.js.map +1 -1
- package/dist/throttler/createThrottledValue.cjs +1 -1
- package/dist/throttler/createThrottledValue.cjs.map +1 -1
- package/dist/throttler/createThrottledValue.d.cts +1 -1
- package/dist/throttler/createThrottledValue.d.ts +1 -1
- package/dist/throttler/createThrottledValue.js +1 -1
- package/dist/throttler/createThrottledValue.js.map +1 -1
- package/dist/throttler/createThrottler.cjs +34 -13
- package/dist/throttler/createThrottler.cjs.map +1 -1
- package/dist/throttler/createThrottler.d.cts +44 -10
- package/dist/throttler/createThrottler.d.ts +44 -10
- package/dist/throttler/createThrottler.js +30 -9
- package/dist/throttler/createThrottler.js.map +1 -1
- package/dist/throttler/index.cjs +3 -3
- package/dist/types/index.cjs +3 -3
- package/dist/utils/index.cjs +3 -3
- package/package.json +2 -2
- package/src/async-batcher/createAsyncBatcher.ts +51 -10
- package/src/async-debouncer/createAsyncDebouncer.ts +51 -10
- package/src/async-queuer/createAsyncQueuer.ts +51 -10
- package/src/async-rate-limiter/createAsyncRateLimiter.ts +114 -28
- package/src/async-throttler/createAsyncThrottler.ts +51 -10
- package/src/batcher/createBatcher.ts +51 -10
- package/src/debouncer/createDebouncer.ts +52 -11
- package/src/queuer/createQueuedSignal.ts +8 -8
- package/src/queuer/createQueuer.ts +51 -10
- package/src/rate-limiter/createRateLimiter.ts +103 -21
- package/src/throttler/createThrottledSignal.ts +1 -1
- package/src/throttler/createThrottledValue.ts +1 -1
- package/src/throttler/createThrottler.ts +59 -11
|
@@ -40,14 +40,24 @@ import { AsyncRateLimiter } from "@tanstack/pacer/async-rate-limiter";
|
|
|
40
40
|
*
|
|
41
41
|
* ## State Management and Selector
|
|
42
42
|
*
|
|
43
|
-
* The hook uses TanStack Store for reactive state management.
|
|
44
|
-
*
|
|
45
|
-
*
|
|
43
|
+
* The hook uses TanStack Store for reactive state management. You can subscribe to state changes
|
|
44
|
+
* in two ways:
|
|
45
|
+
*
|
|
46
|
+
* **1. Using `rateLimiter.Subscribe` component (Recommended for component tree subscriptions)**
|
|
47
|
+
*
|
|
48
|
+
* Use the `Subscribe` component to subscribe to state changes deep in your component tree without
|
|
49
|
+
* needing to pass a selector to the hook. This is ideal when you want to subscribe to state
|
|
50
|
+
* in child components.
|
|
51
|
+
*
|
|
52
|
+
* **2. Using the `selector` parameter (For hook-level subscriptions)**
|
|
53
|
+
*
|
|
54
|
+
* The `selector` parameter allows you to specify which state changes will trigger reactive updates
|
|
55
|
+
* at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
|
|
56
|
+
* state changes occur.
|
|
46
57
|
*
|
|
47
58
|
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
48
|
-
* tracking by providing a selector function. This prevents unnecessary
|
|
49
|
-
* full control over when your component
|
|
50
|
-
* component re-render when the selected state values change.
|
|
59
|
+
* tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
|
|
60
|
+
* updates and gives you full control over when your component tracks state changes.
|
|
51
61
|
*
|
|
52
62
|
* Available state properties:
|
|
53
63
|
* - `currentWindowStart`: Timestamp when the current window started
|
|
@@ -63,7 +73,7 @@ import { AsyncRateLimiter } from "@tanstack/pacer/async-rate-limiter";
|
|
|
63
73
|
* @example
|
|
64
74
|
* ```tsx
|
|
65
75
|
* // Default behavior - no reactive state subscriptions
|
|
66
|
-
* const
|
|
76
|
+
* const asyncRateLimiter = createAsyncRateLimiter(
|
|
67
77
|
* async (id: string) => {
|
|
68
78
|
* const data = await api.fetchData(id);
|
|
69
79
|
* return data; // Return value is preserved
|
|
@@ -71,36 +81,81 @@ import { AsyncRateLimiter } from "@tanstack/pacer/async-rate-limiter";
|
|
|
71
81
|
* { limit: 5, window: 1000 } // 5 calls per second
|
|
72
82
|
* );
|
|
73
83
|
*
|
|
74
|
-
* //
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
84
|
+
* // Subscribe to state changes deep in component tree using Subscribe component
|
|
85
|
+
* <asyncRateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount, isExecuting: state.isExecuting })}>
|
|
86
|
+
* {(state) => (
|
|
87
|
+
* <div>Rejected: {state().rejectionCount}, {state().isExecuting ? 'Executing' : 'Idle'}</div>
|
|
88
|
+
* )}
|
|
89
|
+
* </asyncRateLimiter.Subscribe>
|
|
90
|
+
*
|
|
91
|
+
* // Opt-in to track execution state changes at hook level (optimized for loading indicators)
|
|
92
|
+
* const asyncRateLimiter = createAsyncRateLimiter(
|
|
93
|
+
* async (id: string) => {
|
|
94
|
+
* const data = await api.fetchData(id);
|
|
95
|
+
* return data;
|
|
96
|
+
* },
|
|
97
|
+
* { limit: 5, window: 1000 },
|
|
98
|
+
* (state) => ({ isExecuting: state.isExecuting })
|
|
99
|
+
* );
|
|
100
|
+
*
|
|
101
|
+
* // Opt-in to track results when available (optimized for data display)
|
|
102
|
+
* const asyncRateLimiter = createAsyncRateLimiter(
|
|
103
|
+
* async (id: string) => {
|
|
104
|
+
* const data = await api.fetchData(id);
|
|
105
|
+
* return data;
|
|
79
106
|
* },
|
|
80
|
-
* { limit:
|
|
107
|
+
* { limit: 5, window: 1000 },
|
|
81
108
|
* (state) => ({
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* rejectionCount: state.rejectionCount
|
|
109
|
+
* lastResult: state.lastResult,
|
|
110
|
+
* successCount: state.successCount
|
|
85
111
|
* })
|
|
86
112
|
* );
|
|
87
113
|
*
|
|
88
|
-
* // Opt-in to
|
|
89
|
-
* const
|
|
90
|
-
* async (
|
|
91
|
-
* const
|
|
92
|
-
* return
|
|
114
|
+
* // Opt-in to track error/rejection state changes (optimized for error handling)
|
|
115
|
+
* const asyncRateLimiter = createAsyncRateLimiter(
|
|
116
|
+
* async (id: string) => {
|
|
117
|
+
* const data = await api.fetchData(id);
|
|
118
|
+
* return data;
|
|
93
119
|
* },
|
|
94
120
|
* {
|
|
95
|
-
* limit:
|
|
96
|
-
* window:
|
|
97
|
-
*
|
|
121
|
+
* limit: 5,
|
|
122
|
+
* window: 1000,
|
|
123
|
+
* onError: (error) => console.error('API call failed:', error),
|
|
124
|
+
* onReject: (rateLimiter) => console.log('Rate limit exceeded')
|
|
125
|
+
* },
|
|
126
|
+
* (state) => ({
|
|
127
|
+
* errorCount: state.errorCount,
|
|
128
|
+
* rejectionCount: state.rejectionCount
|
|
129
|
+
* })
|
|
130
|
+
* );
|
|
131
|
+
*
|
|
132
|
+
* // Opt-in to track execution metrics changes (optimized for stats display)
|
|
133
|
+
* const asyncRateLimiter = createAsyncRateLimiter(
|
|
134
|
+
* async (id: string) => {
|
|
135
|
+
* const data = await api.fetchData(id);
|
|
136
|
+
* return data;
|
|
137
|
+
* },
|
|
138
|
+
* { limit: 5, window: 1000 },
|
|
139
|
+
* (state) => ({
|
|
140
|
+
* successCount: state.successCount,
|
|
141
|
+
* errorCount: state.errorCount,
|
|
142
|
+
* settleCount: state.settleCount,
|
|
143
|
+
* rejectionCount: state.rejectionCount
|
|
144
|
+
* })
|
|
145
|
+
* );
|
|
146
|
+
*
|
|
147
|
+
* // Opt-in to track execution times changes (optimized for window calculations)
|
|
148
|
+
* const asyncRateLimiter = createAsyncRateLimiter(
|
|
149
|
+
* async (id: string) => {
|
|
150
|
+
* const data = await api.fetchData(id);
|
|
151
|
+
* return data;
|
|
98
152
|
* },
|
|
99
|
-
*
|
|
153
|
+
* { limit: 5, window: 1000 },
|
|
154
|
+
* (state) => ({ executionTimes: state.executionTimes })
|
|
100
155
|
* );
|
|
101
156
|
*
|
|
102
157
|
* // Access the selected state (will be empty object {} unless selector provided)
|
|
103
|
-
* const {
|
|
158
|
+
* const { isExecuting, lastResult, rejectionCount } = asyncRateLimiter.state();
|
|
104
159
|
* ```
|
|
105
160
|
*/
|
|
106
161
|
function createAsyncRateLimiter(fn, options, selector = () => ({})) {
|
|
@@ -108,6 +163,10 @@ function createAsyncRateLimiter(fn, options, selector = () => ({})) {
|
|
|
108
163
|
...useDefaultPacerOptions().asyncRateLimiter,
|
|
109
164
|
...options
|
|
110
165
|
});
|
|
166
|
+
asyncRateLimiter.Subscribe = function Subscribe(props) {
|
|
167
|
+
const selected = useStore(asyncRateLimiter.store, props.selector);
|
|
168
|
+
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
169
|
+
};
|
|
111
170
|
const state = useStore(asyncRateLimiter.store, selector);
|
|
112
171
|
return {
|
|
113
172
|
...asyncRateLimiter,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAsyncRateLimiter.js","names":[],"sources":["../../src/async-rate-limiter/createAsyncRateLimiter.ts"],"sourcesContent":["import { AsyncRateLimiter } from '@tanstack/pacer/async-rate-limiter'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncRateLimiterOptions,\n AsyncRateLimiterState,\n} from '@tanstack/pacer/async-rate-limiter'\n\nexport interface SolidAsyncRateLimiter<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncRateLimiter<TFn>, 'store'> {\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 `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<AsyncRateLimiterState<TFn>>>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncRateLimiter` instance to limit how many times an async function can execute within a time window.\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 approach that allows a function to execute up to a limit within a time window,\n * then blocks all subsequent calls until the window passes. This can lead to \"bursty\" behavior where\n * all executions happen immediately, followed by a complete block.\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 * Unlike the non-async RateLimiter, this async version supports returning values from the rate-limited function,\n * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call\n * instead of setting the result on a state variable from within the rate-limited function.\n *\n * For smoother execution patterns, consider using:\n * - Throttling: Ensures consistent spacing between executions (e.g. max once per 200ms)\n * - Debouncing: Waits for a pause in calls before executing (e.g. after 500ms of no calls)\n *\n * Rate limiting is best used for hard API limits or resource constraints. For UI updates or\n * smoothing out frequent events, throttling or debouncing usually provide better user experience.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and rate limiter instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncRateLimiter instance\n * - Rate limit rejections (when limit is exceeded) are handled separately from execution errors via the `onReject` handler\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 * - `currentWindowStart`: Timestamp when the current window started\n * - `executionCount`: Number of function executions that have been completed\n * - `hasError`: Whether the last execution resulted in an error\n * - `isExecuting`: Whether an async function execution is currently in progress\n * - `lastError`: The error from the most recent failed execution (if any)\n * - `lastResult`: The result from the most recent successful execution\n * - `nextWindowTime`: Timestamp when the next window begins\n * - `rejectionCount`: Number of function calls that were rejected due to rate limiting\n * - `remainingInWindow`: Number of executions remaining in the current window\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const { maybeExecute } = createAsyncRateLimiter(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data; // Return value is preserved\n * },\n * { limit: 5, window: 1000 } // 5 calls per second\n * );\n *\n * // Opt-in to re-render when rate limit and execution state changes (optimized for UI feedback)\n * const rateLimiter = createAsyncRateLimiter(\n * async (query) => {\n * const result = await searchAPI(query);\n * return result;\n * },\n * { limit: 10, window: 60000 },\n * (state) => ({\n * remainingInWindow: state.remainingInWindow,\n * isExecuting: state.isExecuting,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Opt-in to re-render when error state changes (optimized for error handling)\n * const rateLimiter = createAsyncRateLimiter(\n * async (query) => {\n * const result = await searchAPI(query);\n * return result;\n * },\n * {\n * limit: 10,\n * window: 60000, // 10 calls per minute\n * onReject: (info) => console.log(`Rate limit exceeded: ${info.nextValidTime - Date.now()}ms until next window`)\n * },\n * (state) => ({ hasError: state.hasError, lastError: state.lastError })\n * );\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { remainingInWindow, isExecuting } = rateLimiter.state();\n * ```\n */\nexport function createAsyncRateLimiter<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AsyncRateLimiterOptions<TFn>,\n selector: (state: AsyncRateLimiterState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncRateLimiter,\n ...options,\n } as AsyncRateLimiterOptions<TFn>\n\n const asyncRateLimiter = new AsyncRateLimiter<TFn>(fn, mergedOptions)\n\n const state = useStore(asyncRateLimiter.store, selector)\n\n return {\n ...asyncRateLimiter,\n state,\n } as SolidAsyncRateLimiter<TFn, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiIA,SAAgB,uBAId,IACA,SACA,kBACG,EAAE,GACkC;CAMvC,MAAM,mBAAmB,IAAI,iBAAsB,IAL7B;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ,CAEoE;CAErE,MAAM,QAAQ,SAAS,iBAAiB,OAAO,SAAS;AAExD,QAAO;EACL,GAAG;EACH;EACD"}
|
|
1
|
+
{"version":3,"file":"createAsyncRateLimiter.js","names":[],"sources":["../../src/async-rate-limiter/createAsyncRateLimiter.ts"],"sourcesContent":["import { AsyncRateLimiter } from '@tanstack/pacer/async-rate-limiter'\nimport { useStore } 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 { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncRateLimiterOptions,\n AsyncRateLimiterState,\n} from '@tanstack/pacer/async-rate-limiter'\n\nexport interface SolidAsyncRateLimiter<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncRateLimiter<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, isExecuting: state.isExecuting })}>\n * {(state) => (\n * <div>Rejected: {state().rejectionCount}, {state().isExecuting ? 'Executing' : 'Idle'}</div>\n * )}\n * </rateLimiter.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: AsyncRateLimiterState<TFn>) => 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 `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<AsyncRateLimiterState<TFn>>>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncRateLimiter` instance to limit how many times an async function can execute within a time window.\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 approach that allows a function to execute up to a limit within a time window,\n * then blocks all subsequent calls until the window passes. This can lead to \"bursty\" behavior where\n * all executions happen immediately, followed by a complete block.\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 * Unlike the non-async RateLimiter, this async version supports returning values from the rate-limited function,\n * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call\n * instead of setting the result on a state variable from within the rate-limited function.\n *\n * For smoother execution patterns, consider using:\n * - Throttling: Ensures consistent spacing between executions (e.g. max once per 200ms)\n * - Debouncing: Waits for a pause in calls before executing (e.g. after 500ms of no calls)\n *\n * Rate limiting is best used for hard API limits or resource constraints. For UI updates or\n * smoothing out frequent events, throttling or debouncing usually provide better user experience.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and rate limiter instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncRateLimiter instance\n * - Rate limit rejections (when limit is exceeded) are handled separately from execution errors via the `onReject` handler\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 * - `currentWindowStart`: Timestamp when the current window started\n * - `executionCount`: Number of function executions that have been completed\n * - `hasError`: Whether the last execution resulted in an error\n * - `isExecuting`: Whether an async function execution is currently in progress\n * - `lastError`: The error from the most recent failed execution (if any)\n * - `lastResult`: The result from the most recent successful execution\n * - `nextWindowTime`: Timestamp when the next window begins\n * - `rejectionCount`: Number of function calls that were rejected due to rate limiting\n * - `remainingInWindow`: Number of executions remaining in the current window\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const asyncRateLimiter = createAsyncRateLimiter(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data; // Return value is preserved\n * },\n * { limit: 5, window: 1000 } // 5 calls per second\n * );\n *\n * // Subscribe to state changes deep in component tree using Subscribe component\n * <asyncRateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount, isExecuting: state.isExecuting })}>\n * {(state) => (\n * <div>Rejected: {state().rejectionCount}, {state().isExecuting ? 'Executing' : 'Idle'}</div>\n * )}\n * </asyncRateLimiter.Subscribe>\n *\n * // Opt-in to track execution state changes at hook level (optimized for loading indicators)\n * const asyncRateLimiter = createAsyncRateLimiter(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data;\n * },\n * { limit: 5, window: 1000 },\n * (state) => ({ isExecuting: state.isExecuting })\n * );\n *\n * // Opt-in to track results when available (optimized for data display)\n * const asyncRateLimiter = createAsyncRateLimiter(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data;\n * },\n * { limit: 5, window: 1000 },\n * (state) => ({\n * lastResult: state.lastResult,\n * successCount: state.successCount\n * })\n * );\n *\n * // Opt-in to track error/rejection state changes (optimized for error handling)\n * const asyncRateLimiter = createAsyncRateLimiter(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data;\n * },\n * {\n * limit: 5,\n * window: 1000,\n * onError: (error) => console.error('API call failed:', error),\n * onReject: (rateLimiter) => console.log('Rate limit exceeded')\n * },\n * (state) => ({\n * errorCount: state.errorCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Opt-in to track execution metrics changes (optimized for stats display)\n * const asyncRateLimiter = createAsyncRateLimiter(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data;\n * },\n * { limit: 5, window: 1000 },\n * (state) => ({\n * successCount: state.successCount,\n * errorCount: state.errorCount,\n * settleCount: state.settleCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Opt-in to track execution times changes (optimized for window calculations)\n * const asyncRateLimiter = createAsyncRateLimiter(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data;\n * },\n * { limit: 5, window: 1000 },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isExecuting, lastResult, rejectionCount } = asyncRateLimiter.state();\n * ```\n */\nexport function createAsyncRateLimiter<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AsyncRateLimiterOptions<TFn>,\n selector: (state: AsyncRateLimiterState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncRateLimiter,\n ...options,\n } as AsyncRateLimiterOptions<TFn>\n\n const asyncRateLimiter = new AsyncRateLimiter<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidAsyncRateLimiter<TFn, TSelected>\n\n asyncRateLimiter.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: AsyncRateLimiterState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useStore(asyncRateLimiter.store, props.selector)\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useStore(asyncRateLimiter.store, selector)\n\n return {\n ...asyncRateLimiter,\n state,\n } as SolidAsyncRateLimiter<TFn, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyMA,SAAgB,uBAId,IACA,SACA,kBACG,EAAE,GACkC;CAMvC,MAAM,mBAAmB,IAAI,iBAC3B,IANoB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ,CAKA;AAED,kBAAiB,YAAY,SAAS,UAAqB,OAGxD;EACD,MAAM,WAAW,SAAS,iBAAiB,OAAO,MAAM,SAAS;AAEjE,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,QAAQ,SAAS,iBAAiB,OAAO,SAAS;AAExD,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const require_createAsyncRateLimiter = require('./createAsyncRateLimiter.cjs');
|
|
2
2
|
|
|
3
3
|
exports.createAsyncRateLimiter = require_createAsyncRateLimiter.createAsyncRateLimiter;
|
|
4
|
-
var
|
|
5
|
-
Object.keys(
|
|
4
|
+
var _tanstack_pacer_async_rate_limiter = require("@tanstack/pacer/async-rate-limiter");
|
|
5
|
+
Object.keys(_tanstack_pacer_async_rate_limiter).forEach(function (k) {
|
|
6
6
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: function () { return
|
|
8
|
+
get: function () { return _tanstack_pacer_async_rate_limiter[k]; }
|
|
9
9
|
});
|
|
10
10
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_PacerProvider = require('../provider/PacerProvider.cjs');
|
|
2
|
-
let
|
|
3
|
-
let
|
|
2
|
+
let _tanstack_solid_store = require("@tanstack/solid-store");
|
|
3
|
+
let _tanstack_pacer_async_throttler = require("@tanstack/pacer/async-throttler");
|
|
4
4
|
|
|
5
5
|
//#region src/async-throttler/createAsyncThrottler.ts
|
|
6
6
|
/**
|
|
@@ -26,14 +26,24 @@ let __tanstack_pacer_async_throttler = require("@tanstack/pacer/async-throttler"
|
|
|
26
26
|
*
|
|
27
27
|
* ## State Management and Selector
|
|
28
28
|
*
|
|
29
|
-
* The hook uses TanStack Store for reactive state management.
|
|
30
|
-
*
|
|
31
|
-
*
|
|
29
|
+
* The hook uses TanStack Store for reactive state management. You can subscribe to state changes
|
|
30
|
+
* in two ways:
|
|
31
|
+
*
|
|
32
|
+
* **1. Using `throttler.Subscribe` component (Recommended for component tree subscriptions)**
|
|
33
|
+
*
|
|
34
|
+
* Use the `Subscribe` component to subscribe to state changes deep in your component tree without
|
|
35
|
+
* needing to pass a selector to the hook. This is ideal when you want to subscribe to state
|
|
36
|
+
* in child components.
|
|
37
|
+
*
|
|
38
|
+
* **2. Using the `selector` parameter (For hook-level subscriptions)**
|
|
39
|
+
*
|
|
40
|
+
* The `selector` parameter allows you to specify which state changes will trigger reactive updates
|
|
41
|
+
* at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
|
|
42
|
+
* state changes occur.
|
|
32
43
|
*
|
|
33
44
|
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
34
|
-
* tracking by providing a selector function. This prevents unnecessary
|
|
35
|
-
* full control over when your component
|
|
36
|
-
* component re-render when the selected state values change.
|
|
45
|
+
* tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
|
|
46
|
+
* updates and gives you full control over when your component tracks state changes.
|
|
37
47
|
*
|
|
38
48
|
* Available state properties:
|
|
39
49
|
* - `canLeadingExecute`: Whether the throttler can execute on the leading edge
|
|
@@ -60,7 +70,7 @@ let __tanstack_pacer_async_throttler = require("@tanstack/pacer/async-throttler"
|
|
|
60
70
|
* { wait: 1000 }
|
|
61
71
|
* );
|
|
62
72
|
*
|
|
63
|
-
* // Opt-in to
|
|
73
|
+
* // Opt-in to track isPending or isExecuting changes (optimized for loading states)
|
|
64
74
|
* const throttler = createAsyncThrottler(
|
|
65
75
|
* async (query) => {
|
|
66
76
|
* const result = await searchAPI(query);
|
|
@@ -70,7 +80,7 @@ let __tanstack_pacer_async_throttler = require("@tanstack/pacer/async-throttler"
|
|
|
70
80
|
* (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })
|
|
71
81
|
* );
|
|
72
82
|
*
|
|
73
|
-
* // Opt-in to
|
|
83
|
+
* // Opt-in to track error state changes (optimized for error handling)
|
|
74
84
|
* const throttler = createAsyncThrottler(
|
|
75
85
|
* async (query) => {
|
|
76
86
|
* const result = await searchAPI(query);
|
|
@@ -92,11 +102,15 @@ let __tanstack_pacer_async_throttler = require("@tanstack/pacer/async-throttler"
|
|
|
92
102
|
* ```
|
|
93
103
|
*/
|
|
94
104
|
function createAsyncThrottler(fn, options, selector = () => ({})) {
|
|
95
|
-
const asyncThrottler = new
|
|
105
|
+
const asyncThrottler = new _tanstack_pacer_async_throttler.AsyncThrottler(fn, {
|
|
96
106
|
...require_PacerProvider.useDefaultPacerOptions().asyncThrottler,
|
|
97
107
|
...options
|
|
98
108
|
});
|
|
99
|
-
|
|
109
|
+
asyncThrottler.Subscribe = function Subscribe(props) {
|
|
110
|
+
const selected = (0, _tanstack_solid_store.useStore)(asyncThrottler.store, props.selector);
|
|
111
|
+
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
112
|
+
};
|
|
113
|
+
const state = (0, _tanstack_solid_store.useStore)(asyncThrottler.store, selector);
|
|
100
114
|
return {
|
|
101
115
|
...asyncThrottler,
|
|
102
116
|
state
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAsyncThrottler.cjs","names":["AsyncThrottler","useDefaultPacerOptions"],"sources":["../../src/async-throttler/createAsyncThrottler.ts"],"sourcesContent":["import { AsyncThrottler } from '@tanstack/pacer/async-throttler'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncThrottlerOptions,\n AsyncThrottlerState,\n} from '@tanstack/pacer/async-throttler'\n\nexport interface SolidAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncThrottler<TFn>, 'store'> {\n /**\n * Reactive state that will be updated when the throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<AsyncThrottlerState<TFn>>>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncThrottler` instance to limit how often an async function can execute.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Async throttling ensures an async function executes at most once within a specified time window,\n * regardless of how many times it is called. This is useful for rate-limiting expensive API calls,\n * database operations, or other async tasks.\n *\n * Unlike the non-async Throttler, this async version supports returning values from the throttled function,\n * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call\n * instead of setting the result on a state variable from within the throttled function.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and throttler instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncThrottler instance\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
|
|
1
|
+
{"version":3,"file":"createAsyncThrottler.cjs","names":["AsyncThrottler","useDefaultPacerOptions"],"sources":["../../src/async-throttler/createAsyncThrottler.ts"],"sourcesContent":["import { AsyncThrottler } from '@tanstack/pacer/async-throttler'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncThrottlerOptions,\n AsyncThrottlerState,\n} from '@tanstack/pacer/async-throttler'\n\nexport interface SolidAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncThrottler<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the throttler state.\n *\n * This is useful for tracking specific parts of the throttler state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <throttler.Subscribe selector={(state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })}>\n * {(state) => (\n * <div>{state().isPending ? 'Pending...' : state().isExecuting ? 'Executing...' : 'Ready'}</div>\n * )}\n * </throttler.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: AsyncThrottlerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<AsyncThrottlerState<TFn>>>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncThrottler` instance to limit how often an async function can execute.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Async throttling ensures an async function executes at most once within a specified time window,\n * regardless of how many times it is called. This is useful for rate-limiting expensive API calls,\n * database operations, or other async tasks.\n *\n * Unlike the non-async Throttler, this async version supports returning values from the throttled function,\n * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call\n * instead of setting the result on a state variable from within the throttled function.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and throttler instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncThrottler instance\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `throttler.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 * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `hasError`: Whether the last execution resulted in an error\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `isExecuting`: Whether an async function execution is currently in progress\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastError`: The error from the most recent failed execution (if any)\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `lastResult`: The result from the most recent successful execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const { maybeExecute } = createAsyncThrottler(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data;\n * },\n * { wait: 1000 }\n * );\n *\n * // Opt-in to track isPending or isExecuting changes (optimized for loading states)\n * const throttler = createAsyncThrottler(\n * async (query) => {\n * const result = await searchAPI(query);\n * return result;\n * },\n * { wait: 2000 },\n * (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })\n * );\n *\n * // Opt-in to track error state changes (optimized for error handling)\n * const throttler = createAsyncThrottler(\n * async (query) => {\n * const result = await searchAPI(query);\n * return result;\n * },\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false, // Skip trailing edge updates\n * onError: (error) => {\n * console.error('API call failed:', error);\n * }\n * },\n * (state) => ({ hasError: state.hasError, lastError: state.lastError })\n * );\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending, isExecuting } = throttler.state();\n * ```\n */\nexport function createAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AsyncThrottlerOptions<TFn>,\n selector: (state: AsyncThrottlerState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncThrottler,\n ...options,\n } as AsyncThrottlerOptions<TFn>\n\n const asyncThrottler = new AsyncThrottler(\n fn,\n mergedOptions,\n ) as unknown as SolidAsyncThrottler<TFn, TSelected>\n\n asyncThrottler.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: AsyncThrottlerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useStore(asyncThrottler.store, props.selector)\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useStore(asyncThrottler.store, selector)\n\n return {\n ...asyncThrottler,\n state,\n } as SolidAsyncThrottler<TFn, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgJA,SAAgB,qBAId,IACA,SACA,kBACG,EAAE,GACgC;CAMrC,MAAM,iBAAiB,IAAIA,+CACzB,IANoB;EACpB,GAAGC,8CAAwB,CAAC;EAC5B,GAAG;EACJ,CAKA;AAED,gBAAe,YAAY,SAAS,UAAqB,OAGtD;EACD,MAAM,+CAAoB,eAAe,OAAO,MAAM,SAAS;AAE/D,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,4CAAiB,eAAe,OAAO,SAAS;AAEtD,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
import { Store } from "@tanstack/solid-store";
|
|
2
|
-
import { Accessor } from "solid-js";
|
|
2
|
+
import { Accessor, JSX } from "solid-js";
|
|
3
3
|
import { AnyAsyncFunction } from "@tanstack/pacer/types";
|
|
4
4
|
import { AsyncThrottler, AsyncThrottlerOptions, AsyncThrottlerState } from "@tanstack/pacer/async-throttler";
|
|
5
5
|
|
|
6
6
|
//#region src/async-throttler/createAsyncThrottler.d.ts
|
|
7
7
|
interface SolidAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncThrottler<TFn>, 'store'> {
|
|
8
|
+
/**
|
|
9
|
+
* A Solid component that allows you to subscribe to the throttler state.
|
|
10
|
+
*
|
|
11
|
+
* This is useful for tracking specific parts of the throttler state
|
|
12
|
+
* deep in your component tree without needing to pass a selector to the hook.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* <throttler.Subscribe selector={(state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })}>
|
|
16
|
+
* {(state) => (
|
|
17
|
+
* <div>{state().isPending ? 'Pending...' : state().isExecuting ? 'Executing...' : 'Ready'}</div>
|
|
18
|
+
* )}
|
|
19
|
+
* </throttler.Subscribe>
|
|
20
|
+
*/
|
|
21
|
+
Subscribe: <TSelected>(props: {
|
|
22
|
+
selector: (state: AsyncThrottlerState<TFn>) => TSelected;
|
|
23
|
+
children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
|
|
24
|
+
}) => JSX.Element;
|
|
8
25
|
/**
|
|
9
26
|
* Reactive state that will be updated when the throttler state changes
|
|
10
27
|
*
|
|
@@ -41,14 +58,24 @@ interface SolidAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}> exte
|
|
|
41
58
|
*
|
|
42
59
|
* ## State Management and Selector
|
|
43
60
|
*
|
|
44
|
-
* The hook uses TanStack Store for reactive state management.
|
|
45
|
-
*
|
|
46
|
-
*
|
|
61
|
+
* The hook uses TanStack Store for reactive state management. You can subscribe to state changes
|
|
62
|
+
* in two ways:
|
|
63
|
+
*
|
|
64
|
+
* **1. Using `throttler.Subscribe` component (Recommended for component tree subscriptions)**
|
|
65
|
+
*
|
|
66
|
+
* Use the `Subscribe` component to subscribe to state changes deep in your component tree without
|
|
67
|
+
* needing to pass a selector to the hook. This is ideal when you want to subscribe to state
|
|
68
|
+
* in child components.
|
|
69
|
+
*
|
|
70
|
+
* **2. Using the `selector` parameter (For hook-level subscriptions)**
|
|
71
|
+
*
|
|
72
|
+
* The `selector` parameter allows you to specify which state changes will trigger reactive updates
|
|
73
|
+
* at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
|
|
74
|
+
* state changes occur.
|
|
47
75
|
*
|
|
48
76
|
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
49
|
-
* tracking by providing a selector function. This prevents unnecessary
|
|
50
|
-
* full control over when your component
|
|
51
|
-
* component re-render when the selected state values change.
|
|
77
|
+
* tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
|
|
78
|
+
* updates and gives you full control over when your component tracks state changes.
|
|
52
79
|
*
|
|
53
80
|
* Available state properties:
|
|
54
81
|
* - `canLeadingExecute`: Whether the throttler can execute on the leading edge
|
|
@@ -75,7 +102,7 @@ interface SolidAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}> exte
|
|
|
75
102
|
* { wait: 1000 }
|
|
76
103
|
* );
|
|
77
104
|
*
|
|
78
|
-
* // Opt-in to
|
|
105
|
+
* // Opt-in to track isPending or isExecuting changes (optimized for loading states)
|
|
79
106
|
* const throttler = createAsyncThrottler(
|
|
80
107
|
* async (query) => {
|
|
81
108
|
* const result = await searchAPI(query);
|
|
@@ -85,7 +112,7 @@ interface SolidAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}> exte
|
|
|
85
112
|
* (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })
|
|
86
113
|
* );
|
|
87
114
|
*
|
|
88
|
-
* // Opt-in to
|
|
115
|
+
* // Opt-in to track error state changes (optimized for error handling)
|
|
89
116
|
* const throttler = createAsyncThrottler(
|
|
90
117
|
* async (query) => {
|
|
91
118
|
* const result = await searchAPI(query);
|
|
@@ -1,10 +1,27 @@
|
|
|
1
|
-
import { Accessor } from "solid-js";
|
|
1
|
+
import { Accessor, JSX } from "solid-js";
|
|
2
2
|
import { Store } from "@tanstack/solid-store";
|
|
3
3
|
import { AsyncThrottler, AsyncThrottlerOptions, AsyncThrottlerState } from "@tanstack/pacer/async-throttler";
|
|
4
4
|
import { AnyAsyncFunction } from "@tanstack/pacer/types";
|
|
5
5
|
|
|
6
6
|
//#region src/async-throttler/createAsyncThrottler.d.ts
|
|
7
7
|
interface SolidAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncThrottler<TFn>, 'store'> {
|
|
8
|
+
/**
|
|
9
|
+
* A Solid component that allows you to subscribe to the throttler state.
|
|
10
|
+
*
|
|
11
|
+
* This is useful for tracking specific parts of the throttler state
|
|
12
|
+
* deep in your component tree without needing to pass a selector to the hook.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* <throttler.Subscribe selector={(state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })}>
|
|
16
|
+
* {(state) => (
|
|
17
|
+
* <div>{state().isPending ? 'Pending...' : state().isExecuting ? 'Executing...' : 'Ready'}</div>
|
|
18
|
+
* )}
|
|
19
|
+
* </throttler.Subscribe>
|
|
20
|
+
*/
|
|
21
|
+
Subscribe: <TSelected>(props: {
|
|
22
|
+
selector: (state: AsyncThrottlerState<TFn>) => TSelected;
|
|
23
|
+
children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
|
|
24
|
+
}) => JSX.Element;
|
|
8
25
|
/**
|
|
9
26
|
* Reactive state that will be updated when the throttler state changes
|
|
10
27
|
*
|
|
@@ -41,14 +58,24 @@ interface SolidAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}> exte
|
|
|
41
58
|
*
|
|
42
59
|
* ## State Management and Selector
|
|
43
60
|
*
|
|
44
|
-
* The hook uses TanStack Store for reactive state management.
|
|
45
|
-
*
|
|
46
|
-
*
|
|
61
|
+
* The hook uses TanStack Store for reactive state management. You can subscribe to state changes
|
|
62
|
+
* in two ways:
|
|
63
|
+
*
|
|
64
|
+
* **1. Using `throttler.Subscribe` component (Recommended for component tree subscriptions)**
|
|
65
|
+
*
|
|
66
|
+
* Use the `Subscribe` component to subscribe to state changes deep in your component tree without
|
|
67
|
+
* needing to pass a selector to the hook. This is ideal when you want to subscribe to state
|
|
68
|
+
* in child components.
|
|
69
|
+
*
|
|
70
|
+
* **2. Using the `selector` parameter (For hook-level subscriptions)**
|
|
71
|
+
*
|
|
72
|
+
* The `selector` parameter allows you to specify which state changes will trigger reactive updates
|
|
73
|
+
* at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
|
|
74
|
+
* state changes occur.
|
|
47
75
|
*
|
|
48
76
|
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
49
|
-
* tracking by providing a selector function. This prevents unnecessary
|
|
50
|
-
* full control over when your component
|
|
51
|
-
* component re-render when the selected state values change.
|
|
77
|
+
* tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
|
|
78
|
+
* updates and gives you full control over when your component tracks state changes.
|
|
52
79
|
*
|
|
53
80
|
* Available state properties:
|
|
54
81
|
* - `canLeadingExecute`: Whether the throttler can execute on the leading edge
|
|
@@ -75,7 +102,7 @@ interface SolidAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}> exte
|
|
|
75
102
|
* { wait: 1000 }
|
|
76
103
|
* );
|
|
77
104
|
*
|
|
78
|
-
* // Opt-in to
|
|
105
|
+
* // Opt-in to track isPending or isExecuting changes (optimized for loading states)
|
|
79
106
|
* const throttler = createAsyncThrottler(
|
|
80
107
|
* async (query) => {
|
|
81
108
|
* const result = await searchAPI(query);
|
|
@@ -85,7 +112,7 @@ interface SolidAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}> exte
|
|
|
85
112
|
* (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })
|
|
86
113
|
* );
|
|
87
114
|
*
|
|
88
|
-
* // Opt-in to
|
|
115
|
+
* // Opt-in to track error state changes (optimized for error handling)
|
|
89
116
|
* const throttler = createAsyncThrottler(
|
|
90
117
|
* async (query) => {
|
|
91
118
|
* const result = await searchAPI(query);
|
|
@@ -26,14 +26,24 @@ import { AsyncThrottler } from "@tanstack/pacer/async-throttler";
|
|
|
26
26
|
*
|
|
27
27
|
* ## State Management and Selector
|
|
28
28
|
*
|
|
29
|
-
* The hook uses TanStack Store for reactive state management.
|
|
30
|
-
*
|
|
31
|
-
*
|
|
29
|
+
* The hook uses TanStack Store for reactive state management. You can subscribe to state changes
|
|
30
|
+
* in two ways:
|
|
31
|
+
*
|
|
32
|
+
* **1. Using `throttler.Subscribe` component (Recommended for component tree subscriptions)**
|
|
33
|
+
*
|
|
34
|
+
* Use the `Subscribe` component to subscribe to state changes deep in your component tree without
|
|
35
|
+
* needing to pass a selector to the hook. This is ideal when you want to subscribe to state
|
|
36
|
+
* in child components.
|
|
37
|
+
*
|
|
38
|
+
* **2. Using the `selector` parameter (For hook-level subscriptions)**
|
|
39
|
+
*
|
|
40
|
+
* The `selector` parameter allows you to specify which state changes will trigger reactive updates
|
|
41
|
+
* at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
|
|
42
|
+
* state changes occur.
|
|
32
43
|
*
|
|
33
44
|
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
34
|
-
* tracking by providing a selector function. This prevents unnecessary
|
|
35
|
-
* full control over when your component
|
|
36
|
-
* component re-render when the selected state values change.
|
|
45
|
+
* tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
|
|
46
|
+
* updates and gives you full control over when your component tracks state changes.
|
|
37
47
|
*
|
|
38
48
|
* Available state properties:
|
|
39
49
|
* - `canLeadingExecute`: Whether the throttler can execute on the leading edge
|
|
@@ -60,7 +70,7 @@ import { AsyncThrottler } from "@tanstack/pacer/async-throttler";
|
|
|
60
70
|
* { wait: 1000 }
|
|
61
71
|
* );
|
|
62
72
|
*
|
|
63
|
-
* // Opt-in to
|
|
73
|
+
* // Opt-in to track isPending or isExecuting changes (optimized for loading states)
|
|
64
74
|
* const throttler = createAsyncThrottler(
|
|
65
75
|
* async (query) => {
|
|
66
76
|
* const result = await searchAPI(query);
|
|
@@ -70,7 +80,7 @@ import { AsyncThrottler } from "@tanstack/pacer/async-throttler";
|
|
|
70
80
|
* (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })
|
|
71
81
|
* );
|
|
72
82
|
*
|
|
73
|
-
* // Opt-in to
|
|
83
|
+
* // Opt-in to track error state changes (optimized for error handling)
|
|
74
84
|
* const throttler = createAsyncThrottler(
|
|
75
85
|
* async (query) => {
|
|
76
86
|
* const result = await searchAPI(query);
|
|
@@ -96,6 +106,10 @@ function createAsyncThrottler(fn, options, selector = () => ({})) {
|
|
|
96
106
|
...useDefaultPacerOptions().asyncThrottler,
|
|
97
107
|
...options
|
|
98
108
|
});
|
|
109
|
+
asyncThrottler.Subscribe = function Subscribe(props) {
|
|
110
|
+
const selected = useStore(asyncThrottler.store, props.selector);
|
|
111
|
+
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
112
|
+
};
|
|
99
113
|
const state = useStore(asyncThrottler.store, selector);
|
|
100
114
|
return {
|
|
101
115
|
...asyncThrottler,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAsyncThrottler.js","names":[],"sources":["../../src/async-throttler/createAsyncThrottler.ts"],"sourcesContent":["import { AsyncThrottler } from '@tanstack/pacer/async-throttler'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncThrottlerOptions,\n AsyncThrottlerState,\n} from '@tanstack/pacer/async-throttler'\n\nexport interface SolidAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncThrottler<TFn>, 'store'> {\n /**\n * Reactive state that will be updated when the throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<AsyncThrottlerState<TFn>>>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncThrottler` instance to limit how often an async function can execute.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Async throttling ensures an async function executes at most once within a specified time window,\n * regardless of how many times it is called. This is useful for rate-limiting expensive API calls,\n * database operations, or other async tasks.\n *\n * Unlike the non-async Throttler, this async version supports returning values from the throttled function,\n * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call\n * instead of setting the result on a state variable from within the throttled function.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and throttler instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncThrottler instance\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
|
|
1
|
+
{"version":3,"file":"createAsyncThrottler.js","names":[],"sources":["../../src/async-throttler/createAsyncThrottler.ts"],"sourcesContent":["import { AsyncThrottler } from '@tanstack/pacer/async-throttler'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncThrottlerOptions,\n AsyncThrottlerState,\n} from '@tanstack/pacer/async-throttler'\n\nexport interface SolidAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncThrottler<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the throttler state.\n *\n * This is useful for tracking specific parts of the throttler state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <throttler.Subscribe selector={(state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })}>\n * {(state) => (\n * <div>{state().isPending ? 'Pending...' : state().isExecuting ? 'Executing...' : 'Ready'}</div>\n * )}\n * </throttler.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: AsyncThrottlerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<AsyncThrottlerState<TFn>>>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncThrottler` instance to limit how often an async function can execute.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Async throttling ensures an async function executes at most once within a specified time window,\n * regardless of how many times it is called. This is useful for rate-limiting expensive API calls,\n * database operations, or other async tasks.\n *\n * Unlike the non-async Throttler, this async version supports returning values from the throttled function,\n * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call\n * instead of setting the result on a state variable from within the throttled function.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and throttler instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncThrottler instance\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `throttler.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 * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `hasError`: Whether the last execution resulted in an error\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `isExecuting`: Whether an async function execution is currently in progress\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastError`: The error from the most recent failed execution (if any)\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `lastResult`: The result from the most recent successful execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const { maybeExecute } = createAsyncThrottler(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data;\n * },\n * { wait: 1000 }\n * );\n *\n * // Opt-in to track isPending or isExecuting changes (optimized for loading states)\n * const throttler = createAsyncThrottler(\n * async (query) => {\n * const result = await searchAPI(query);\n * return result;\n * },\n * { wait: 2000 },\n * (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })\n * );\n *\n * // Opt-in to track error state changes (optimized for error handling)\n * const throttler = createAsyncThrottler(\n * async (query) => {\n * const result = await searchAPI(query);\n * return result;\n * },\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false, // Skip trailing edge updates\n * onError: (error) => {\n * console.error('API call failed:', error);\n * }\n * },\n * (state) => ({ hasError: state.hasError, lastError: state.lastError })\n * );\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending, isExecuting } = throttler.state();\n * ```\n */\nexport function createAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AsyncThrottlerOptions<TFn>,\n selector: (state: AsyncThrottlerState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncThrottler,\n ...options,\n } as AsyncThrottlerOptions<TFn>\n\n const asyncThrottler = new AsyncThrottler(\n fn,\n mergedOptions,\n ) as unknown as SolidAsyncThrottler<TFn, TSelected>\n\n asyncThrottler.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: AsyncThrottlerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useStore(asyncThrottler.store, props.selector)\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useStore(asyncThrottler.store, selector)\n\n return {\n ...asyncThrottler,\n state,\n } as SolidAsyncThrottler<TFn, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgJA,SAAgB,qBAId,IACA,SACA,kBACG,EAAE,GACgC;CAMrC,MAAM,iBAAiB,IAAI,eACzB,IANoB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ,CAKA;AAED,gBAAe,YAAY,SAAS,UAAqB,OAGtD;EACD,MAAM,WAAW,SAAS,eAAe,OAAO,MAAM,SAAS;AAE/D,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,QAAQ,SAAS,eAAe,OAAO,SAAS;AAEtD,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const require_createAsyncThrottler = require('./createAsyncThrottler.cjs');
|
|
2
2
|
|
|
3
3
|
exports.createAsyncThrottler = require_createAsyncThrottler.createAsyncThrottler;
|
|
4
|
-
var
|
|
5
|
-
Object.keys(
|
|
4
|
+
var _tanstack_pacer_async_throttler = require("@tanstack/pacer/async-throttler");
|
|
5
|
+
Object.keys(_tanstack_pacer_async_throttler).forEach(function (k) {
|
|
6
6
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: function () { return
|
|
8
|
+
get: function () { return _tanstack_pacer_async_throttler[k]; }
|
|
9
9
|
});
|
|
10
10
|
});
|