@tanstack/solid-pacer 0.22.0 → 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.
Files changed (170) hide show
  1. package/README.md +4 -4
  2. package/dist/async-batcher/createAsyncBatcher.d.ts +5 -9
  3. package/dist/async-batcher/createAsyncBatcher.js +2 -5
  4. package/dist/async-debouncer/createAsyncDebouncer.d.ts +8 -11
  5. package/dist/async-debouncer/createAsyncDebouncer.js +5 -7
  6. package/dist/async-queuer/createAsyncQueuer.d.ts +9 -11
  7. package/dist/async-queuer/createAsyncQueuer.js +4 -5
  8. package/dist/async-rate-limiter/createAsyncRateLimiter.d.ts +10 -12
  9. package/dist/async-rate-limiter/createAsyncRateLimiter.js +7 -8
  10. package/dist/async-throttler/createAsyncThrottler.d.ts +8 -13
  11. package/dist/async-throttler/createAsyncThrottler.js +5 -9
  12. package/dist/batcher/createBatcher.d.ts +11 -14
  13. package/dist/batcher/createBatcher.js +6 -8
  14. package/dist/debouncer/createDebouncedSignal.d.ts +2 -4
  15. package/dist/debouncer/createDebouncedSignal.js +1 -2
  16. package/dist/debouncer/createDebouncedValue.d.ts +2 -4
  17. package/dist/debouncer/createDebouncedValue.js +1 -2
  18. package/dist/debouncer/createDebouncer.d.ts +4 -6
  19. package/dist/debouncer/createDebouncer.js +1 -2
  20. package/dist/provider/PacerProvider.d.ts +6 -8
  21. package/dist/provider/PacerProvider.js +1 -2
  22. package/dist/queuer/createQueuedSignal.d.ts +2 -4
  23. package/dist/queuer/createQueuedSignal.js +1 -2
  24. package/dist/queuer/createQueuer.d.ts +4 -6
  25. package/dist/queuer/createQueuer.js +1 -2
  26. package/dist/rate-limiter/createRateLimitedSignal.d.ts +12 -13
  27. package/dist/rate-limiter/createRateLimitedSignal.js +11 -11
  28. package/dist/rate-limiter/createRateLimitedValue.d.ts +2 -4
  29. package/dist/rate-limiter/createRateLimitedValue.js +1 -2
  30. package/dist/rate-limiter/createRateLimiter.d.ts +8 -9
  31. package/dist/rate-limiter/createRateLimiter.js +5 -5
  32. package/dist/throttler/createThrottledSignal.d.ts +2 -6
  33. package/dist/throttler/createThrottledSignal.js +1 -4
  34. package/dist/throttler/createThrottledValue.d.ts +2 -6
  35. package/dist/throttler/createThrottledValue.js +1 -4
  36. package/dist/throttler/createThrottler.d.ts +4 -8
  37. package/dist/throttler/createThrottler.js +1 -4
  38. package/package.json +23 -67
  39. package/dist/async-batcher/createAsyncBatcher.cjs +0 -166
  40. package/dist/async-batcher/createAsyncBatcher.cjs.map +0 -1
  41. package/dist/async-batcher/createAsyncBatcher.d.cts +0 -177
  42. package/dist/async-batcher/createAsyncBatcher.js.map +0 -1
  43. package/dist/async-batcher/index.cjs +0 -11
  44. package/dist/async-batcher/index.d.cts +0 -3
  45. package/dist/async-debouncer/createAsyncDebouncer.cjs +0 -151
  46. package/dist/async-debouncer/createAsyncDebouncer.cjs.map +0 -1
  47. package/dist/async-debouncer/createAsyncDebouncer.d.cts +0 -163
  48. package/dist/async-debouncer/createAsyncDebouncer.js.map +0 -1
  49. package/dist/async-debouncer/index.cjs +0 -11
  50. package/dist/async-debouncer/index.d.cts +0 -3
  51. package/dist/async-queuer/createAsyncQueuer.cjs +0 -158
  52. package/dist/async-queuer/createAsyncQueuer.cjs.map +0 -1
  53. package/dist/async-queuer/createAsyncQueuer.d.cts +0 -169
  54. package/dist/async-queuer/createAsyncQueuer.js.map +0 -1
  55. package/dist/async-queuer/index.cjs +0 -11
  56. package/dist/async-queuer/index.d.cts +0 -3
  57. package/dist/async-rate-limiter/createAsyncRateLimiter.cjs +0 -193
  58. package/dist/async-rate-limiter/createAsyncRateLimiter.cjs.map +0 -1
  59. package/dist/async-rate-limiter/createAsyncRateLimiter.d.cts +0 -208
  60. package/dist/async-rate-limiter/createAsyncRateLimiter.js.map +0 -1
  61. package/dist/async-rate-limiter/index.cjs +0 -11
  62. package/dist/async-rate-limiter/index.d.cts +0 -3
  63. package/dist/async-throttler/createAsyncThrottler.cjs +0 -151
  64. package/dist/async-throttler/createAsyncThrottler.cjs.map +0 -1
  65. package/dist/async-throttler/createAsyncThrottler.d.cts +0 -163
  66. package/dist/async-throttler/createAsyncThrottler.js.map +0 -1
  67. package/dist/async-throttler/index.cjs +0 -11
  68. package/dist/async-throttler/index.d.cts +0 -3
  69. package/dist/batcher/createBatcher.cjs +0 -132
  70. package/dist/batcher/createBatcher.cjs.map +0 -1
  71. package/dist/batcher/createBatcher.d.cts +0 -146
  72. package/dist/batcher/createBatcher.js.map +0 -1
  73. package/dist/batcher/index.cjs +0 -11
  74. package/dist/batcher/index.d.cts +0 -3
  75. package/dist/debouncer/createDebouncedSignal.cjs +0 -88
  76. package/dist/debouncer/createDebouncedSignal.cjs.map +0 -1
  77. package/dist/debouncer/createDebouncedSignal.d.cts +0 -79
  78. package/dist/debouncer/createDebouncedSignal.js.map +0 -1
  79. package/dist/debouncer/createDebouncedValue.cjs +0 -77
  80. package/dist/debouncer/createDebouncedValue.cjs.map +0 -1
  81. package/dist/debouncer/createDebouncedValue.d.cts +0 -70
  82. package/dist/debouncer/createDebouncedValue.js.map +0 -1
  83. package/dist/debouncer/createDebouncer.cjs +0 -129
  84. package/dist/debouncer/createDebouncer.cjs.map +0 -1
  85. package/dist/debouncer/createDebouncer.d.cts +0 -144
  86. package/dist/debouncer/createDebouncer.js.map +0 -1
  87. package/dist/debouncer/index.cjs +0 -15
  88. package/dist/debouncer/index.d.cts +0 -5
  89. package/dist/index.cjs +0 -47
  90. package/dist/index.d.cts +0 -20
  91. package/dist/provider/PacerProvider.cjs +0 -27
  92. package/dist/provider/PacerProvider.cjs.map +0 -1
  93. package/dist/provider/PacerProvider.d.cts +0 -28
  94. package/dist/provider/PacerProvider.js.map +0 -1
  95. package/dist/provider/index.cjs +0 -6
  96. package/dist/provider/index.d.cts +0 -2
  97. package/dist/queuer/createQueuedSignal.cjs +0 -129
  98. package/dist/queuer/createQueuedSignal.cjs.map +0 -1
  99. package/dist/queuer/createQueuedSignal.d.cts +0 -121
  100. package/dist/queuer/createQueuedSignal.js.map +0 -1
  101. package/dist/queuer/createQueuer.cjs +0 -133
  102. package/dist/queuer/createQueuer.cjs.map +0 -1
  103. package/dist/queuer/createQueuer.d.cts +0 -147
  104. package/dist/queuer/createQueuer.js.map +0 -1
  105. package/dist/queuer/index.cjs +0 -13
  106. package/dist/queuer/index.d.cts +0 -4
  107. package/dist/rate-limiter/createRateLimitedSignal.cjs +0 -102
  108. package/dist/rate-limiter/createRateLimitedSignal.cjs.map +0 -1
  109. package/dist/rate-limiter/createRateLimitedSignal.d.cts +0 -93
  110. package/dist/rate-limiter/createRateLimitedSignal.js.map +0 -1
  111. package/dist/rate-limiter/createRateLimitedValue.cjs +0 -102
  112. package/dist/rate-limiter/createRateLimitedValue.cjs.map +0 -1
  113. package/dist/rate-limiter/createRateLimitedValue.d.cts +0 -95
  114. package/dist/rate-limiter/createRateLimitedValue.js.map +0 -1
  115. package/dist/rate-limiter/createRateLimiter.cjs +0 -157
  116. package/dist/rate-limiter/createRateLimiter.cjs.map +0 -1
  117. package/dist/rate-limiter/createRateLimiter.d.cts +0 -173
  118. package/dist/rate-limiter/createRateLimiter.js.map +0 -1
  119. package/dist/rate-limiter/index.cjs +0 -15
  120. package/dist/rate-limiter/index.d.cts +0 -5
  121. package/dist/throttler/createThrottledSignal.cjs +0 -79
  122. package/dist/throttler/createThrottledSignal.cjs.map +0 -1
  123. package/dist/throttler/createThrottledSignal.d.cts +0 -70
  124. package/dist/throttler/createThrottledSignal.js.map +0 -1
  125. package/dist/throttler/createThrottledValue.cjs +0 -74
  126. package/dist/throttler/createThrottledValue.cjs.map +0 -1
  127. package/dist/throttler/createThrottledValue.d.cts +0 -67
  128. package/dist/throttler/createThrottledValue.js.map +0 -1
  129. package/dist/throttler/createThrottler.cjs +0 -132
  130. package/dist/throttler/createThrottler.cjs.map +0 -1
  131. package/dist/throttler/createThrottler.d.cts +0 -147
  132. package/dist/throttler/createThrottler.js.map +0 -1
  133. package/dist/throttler/index.cjs +0 -15
  134. package/dist/throttler/index.d.cts +0 -5
  135. package/dist/types/index.cjs +0 -8
  136. package/dist/types/index.d.cts +0 -1
  137. package/dist/utils/index.cjs +0 -8
  138. package/dist/utils/index.d.cts +0 -1
  139. package/src/async-batcher/createAsyncBatcher.ts +0 -234
  140. package/src/async-batcher/index.ts +0 -3
  141. package/src/async-debouncer/createAsyncDebouncer.ts +0 -225
  142. package/src/async-debouncer/index.ts +0 -4
  143. package/src/async-queuer/createAsyncQueuer.ts +0 -226
  144. package/src/async-queuer/index.ts +0 -3
  145. package/src/async-rate-limiter/createAsyncRateLimiter.ts +0 -269
  146. package/src/async-rate-limiter/index.ts +0 -4
  147. package/src/async-throttler/createAsyncThrottler.ts +0 -225
  148. package/src/async-throttler/index.ts +0 -4
  149. package/src/batcher/createBatcher.ts +0 -199
  150. package/src/batcher/index.ts +0 -3
  151. package/src/debouncer/createDebouncedSignal.ts +0 -92
  152. package/src/debouncer/createDebouncedValue.ts +0 -85
  153. package/src/debouncer/createDebouncer.ts +0 -201
  154. package/src/debouncer/index.ts +0 -6
  155. package/src/index.ts +0 -46
  156. package/src/provider/PacerProvider.tsx +0 -63
  157. package/src/provider/index.ts +0 -1
  158. package/src/queuer/createQueuedSignal.ts +0 -138
  159. package/src/queuer/createQueuer.ts +0 -199
  160. package/src/queuer/index.ts +0 -4
  161. package/src/rate-limiter/createRateLimitedSignal.ts +0 -117
  162. package/src/rate-limiter/createRateLimitedValue.ts +0 -110
  163. package/src/rate-limiter/createRateLimiter.ts +0 -226
  164. package/src/rate-limiter/index.ts +0 -5
  165. package/src/throttler/createThrottledSignal.ts +0 -81
  166. package/src/throttler/createThrottledValue.ts +0 -82
  167. package/src/throttler/createThrottler.ts +0 -204
  168. package/src/throttler/index.ts +0 -6
  169. package/src/types/index.ts +0 -1
  170. package/src/utils/index.ts +0 -1
@@ -1,193 +0,0 @@
1
- const require_PacerProvider = require('../provider/PacerProvider.cjs');
2
- let solid_js = require("solid-js");
3
- let _tanstack_solid_store = require("@tanstack/solid-store");
4
- let _tanstack_pacer_async_rate_limiter = require("@tanstack/pacer/async-rate-limiter");
5
-
6
- //#region src/async-rate-limiter/createAsyncRateLimiter.ts
7
- /**
8
- * A low-level Solid hook that creates an `AsyncRateLimiter` instance to limit how many times an async function can execute within a time window.
9
- *
10
- * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that
11
- * you can integrate with any state management solution (createSignal, etc).
12
- *
13
- * Rate limiting is a simple approach that allows a function to execute up to a limit within a time window,
14
- * then blocks all subsequent calls until the window passes. This can lead to "bursty" behavior where
15
- * all executions happen immediately, followed by a complete block.
16
- *
17
- * The rate limiter supports two types of windows:
18
- * - 'fixed': A strict window that resets after the window period. All executions within the window count
19
- * towards the limit, and the window resets completely after the period.
20
- * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more
21
- * consistent rate of execution over time.
22
- *
23
- * Unlike the non-async RateLimiter, this async version supports returning values from the rate-limited function,
24
- * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call
25
- * instead of setting the result on a state variable from within the rate-limited function.
26
- *
27
- * For smoother execution patterns, consider using:
28
- * - Throttling: Ensures consistent spacing between executions (e.g. max once per 200ms)
29
- * - Debouncing: Waits for a pause in calls before executing (e.g. after 500ms of no calls)
30
- *
31
- * Rate limiting is best used for hard API limits or resource constraints. For UI updates or
32
- * smoothing out frequent events, throttling or debouncing usually provide better user experience.
33
- *
34
- * Error Handling:
35
- * - If an `onError` handler is provided, it will be called with the error and rate limiter instance
36
- * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
37
- * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
38
- * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown
39
- * - The error state can be checked using the underlying AsyncRateLimiter instance
40
- * - Rate limit rejections (when limit is exceeded) are handled separately from execution errors via the `onReject` handler
41
- *
42
- * ## State Management and Selector
43
- *
44
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
45
- * in two ways:
46
- *
47
- * **1. Using `rateLimiter.Subscribe` component (Recommended for component tree subscriptions)**
48
- *
49
- * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
50
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
51
- * in child components.
52
- *
53
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
54
- *
55
- * The `selector` parameter allows you to specify which state changes will trigger reactive updates
56
- * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
57
- * state changes occur.
58
- *
59
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
60
- * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
61
- * updates and gives you full control over when your component tracks state changes.
62
- *
63
- * Available state properties:
64
- * - `currentWindowStart`: Timestamp when the current window started
65
- * - `executionCount`: Number of function executions that have been completed
66
- * - `hasError`: Whether the last execution resulted in an error
67
- * - `isExecuting`: Whether an async function execution is currently in progress
68
- * - `lastError`: The error from the most recent failed execution (if any)
69
- * - `lastResult`: The result from the most recent successful execution
70
- * - `nextWindowTime`: Timestamp when the next window begins
71
- * - `rejectionCount`: Number of function calls that were rejected due to rate limiting
72
- * - `remainingInWindow`: Number of executions remaining in the current window
73
- *
74
- * ## Unmount behavior
75
- *
76
- * By default, the primitive aborts any in-flight execution when the owning component unmounts.
77
- * Abort only cancels underlying operations (e.g. fetch) when the abort signal from `getAbortSignal()` is passed to them.
78
- * Use the `onUnmount` option to customize this.
79
- *
80
- * @example
81
- * ```tsx
82
- * // Default behavior - no reactive state subscriptions
83
- * const asyncRateLimiter = createAsyncRateLimiter(
84
- * async (id: string) => {
85
- * const data = await api.fetchData(id);
86
- * return data; // Return value is preserved
87
- * },
88
- * { limit: 5, window: 1000 } // 5 calls per second
89
- * );
90
- *
91
- * // Subscribe to state changes deep in component tree using Subscribe component
92
- * <asyncRateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount, isExecuting: state.isExecuting })}>
93
- * {(state) => (
94
- * <div>Rejected: {state().rejectionCount}, {state().isExecuting ? 'Executing' : 'Idle'}</div>
95
- * )}
96
- * </asyncRateLimiter.Subscribe>
97
- *
98
- * // Opt-in to track execution state changes at hook level (optimized for loading indicators)
99
- * const asyncRateLimiter = createAsyncRateLimiter(
100
- * async (id: string) => {
101
- * const data = await api.fetchData(id);
102
- * return data;
103
- * },
104
- * { limit: 5, window: 1000 },
105
- * (state) => ({ isExecuting: state.isExecuting })
106
- * );
107
- *
108
- * // Opt-in to track results when available (optimized for data display)
109
- * const asyncRateLimiter = createAsyncRateLimiter(
110
- * async (id: string) => {
111
- * const data = await api.fetchData(id);
112
- * return data;
113
- * },
114
- * { limit: 5, window: 1000 },
115
- * (state) => ({
116
- * lastResult: state.lastResult,
117
- * successCount: state.successCount
118
- * })
119
- * );
120
- *
121
- * // Opt-in to track error/rejection state changes (optimized for error handling)
122
- * const asyncRateLimiter = createAsyncRateLimiter(
123
- * async (id: string) => {
124
- * const data = await api.fetchData(id);
125
- * return data;
126
- * },
127
- * {
128
- * limit: 5,
129
- * window: 1000,
130
- * onError: (error) => console.error('API call failed:', error),
131
- * onReject: (rateLimiter) => console.log('Rate limit exceeded')
132
- * },
133
- * (state) => ({
134
- * errorCount: state.errorCount,
135
- * rejectionCount: state.rejectionCount
136
- * })
137
- * );
138
- *
139
- * // Opt-in to track execution metrics changes (optimized for stats display)
140
- * const asyncRateLimiter = createAsyncRateLimiter(
141
- * async (id: string) => {
142
- * const data = await api.fetchData(id);
143
- * return data;
144
- * },
145
- * { limit: 5, window: 1000 },
146
- * (state) => ({
147
- * successCount: state.successCount,
148
- * errorCount: state.errorCount,
149
- * settleCount: state.settleCount,
150
- * rejectionCount: state.rejectionCount
151
- * })
152
- * );
153
- *
154
- * // Opt-in to track execution times changes (optimized for window calculations)
155
- * const asyncRateLimiter = createAsyncRateLimiter(
156
- * async (id: string) => {
157
- * const data = await api.fetchData(id);
158
- * return data;
159
- * },
160
- * { limit: 5, window: 1000 },
161
- * (state) => ({ executionTimes: state.executionTimes })
162
- * );
163
- *
164
- * // Access the selected state (will be empty object {} unless selector provided)
165
- * const { isExecuting, lastResult, rejectionCount } = asyncRateLimiter.state();
166
- * ```
167
- */
168
- function createAsyncRateLimiter(fn, options, selector = () => ({})) {
169
- const mergedOptions = {
170
- ...require_PacerProvider.useDefaultPacerOptions().asyncRateLimiter,
171
- ...options
172
- };
173
- const asyncRateLimiter = new _tanstack_pacer_async_rate_limiter.AsyncRateLimiter(fn, mergedOptions);
174
- asyncRateLimiter.Subscribe = function Subscribe(props) {
175
- const selected = (0, _tanstack_solid_store.useSelector)(asyncRateLimiter.store, props.selector, { compare: _tanstack_solid_store.shallow });
176
- return typeof props.children === "function" ? props.children(selected) : props.children;
177
- };
178
- const state = (0, _tanstack_solid_store.useSelector)(asyncRateLimiter.store, selector, { compare: _tanstack_solid_store.shallow });
179
- (0, solid_js.createEffect)(() => {
180
- (0, solid_js.onCleanup)(() => {
181
- if (mergedOptions.onUnmount) mergedOptions.onUnmount(asyncRateLimiter);
182
- else asyncRateLimiter.abort();
183
- });
184
- });
185
- return {
186
- ...asyncRateLimiter,
187
- state
188
- };
189
- }
190
-
191
- //#endregion
192
- exports.createAsyncRateLimiter = createAsyncRateLimiter;
193
- //# sourceMappingURL=createAsyncRateLimiter.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createAsyncRateLimiter.cjs","names":["useDefaultPacerOptions","AsyncRateLimiter","useSelector","shallow"],"sources":["../../src/async-rate-limiter/createAsyncRateLimiter.ts"],"sourcesContent":["import { AsyncRateLimiter } from '@tanstack/pacer/async-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 { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncRateLimiterOptions,\n AsyncRateLimiterState,\n} from '@tanstack/pacer/async-rate-limiter'\n\nexport interface SolidAsyncRateLimiterOptions<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends AsyncRateLimiterOptions<TFn> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the rate limiter instance.\n * When provided, replaces the default cleanup (abort); use it to call reset(), add logging, etc.\n */\n onUnmount?: (rateLimiter: SolidAsyncRateLimiter<TFn, TSelected>) => void\n}\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 `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<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 * ## Unmount behavior\n *\n * By default, the primitive aborts any in-flight execution when the owning component unmounts.\n * Abort only cancels underlying operations (e.g. fetch) when the abort signal from `getAbortSignal()` is passed to them.\n * Use the `onUnmount` option to customize this.\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: SolidAsyncRateLimiterOptions<TFn, TSelected>,\n selector: (state: AsyncRateLimiterState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncRateLimiter,\n ...options,\n } as SolidAsyncRateLimiterOptions<TFn, TSelected>\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 = useSelector(asyncRateLimiter.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(asyncRateLimiter.store, selector, {\n compare: shallow,\n })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(asyncRateLimiter)\n } else {\n asyncRateLimiter.abort()\n }\n })\n })\n\n return {\n ...asyncRateLimiter,\n state,\n } as SolidAsyncRateLimiter<TFn, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2NA,SAAgB,uBAId,IACA,SACA,kBACG,CAAC,IACmC;CACvC,MAAM,gBAAgB;EACpB,GAAGA,6CAAuB,CAAC,CAAC;EAC5B,GAAG;CACL;CACA,MAAM,mBAAmB,IAAIC,oDAC3B,IACA,aACF;CAEA,iBAAiB,YAAY,SAAS,UAAqB,OAGxD;EACD,MAAM,eAAWC,mCAAY,iBAAiB,OAAO,MAAM,UAAU,EACnE,SAASC,8BACX,CAAC;EAED,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,QAAQ,IACvB,MAAM;CACZ;CAEA,MAAM,YAAQD,mCAAY,iBAAiB,OAAO,UAAU,EAC1D,SAASC,8BACX,CAAC;CAED,iCAAmB;EACjB,8BAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,gBAAgB;QAExC,iBAAiB,MAAM;EAE3B,CAAC;CACH,CAAC;CAED,OAAO;EACL,GAAG;EACH;CACF;AACF"}
@@ -1,208 +0,0 @@
1
- import { Store } from "@tanstack/solid-store";
2
- import { Accessor, JSX } from "solid-js";
3
- import { AnyAsyncFunction } from "@tanstack/pacer/types";
4
- import { AsyncRateLimiter, AsyncRateLimiterOptions, AsyncRateLimiterState } from "@tanstack/pacer/async-rate-limiter";
5
- //#region src/async-rate-limiter/createAsyncRateLimiter.d.ts
6
- interface SolidAsyncRateLimiterOptions<TFn extends AnyAsyncFunction, TSelected = {}> extends AsyncRateLimiterOptions<TFn> {
7
- /**
8
- * Optional callback invoked when the owning component unmounts. Receives the rate limiter instance.
9
- * When provided, replaces the default cleanup (abort); use it to call reset(), add logging, etc.
10
- */
11
- onUnmount?: (rateLimiter: SolidAsyncRateLimiter<TFn, TSelected>) => void;
12
- }
13
- interface SolidAsyncRateLimiter<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncRateLimiter<TFn>, 'store'> {
14
- /**
15
- * A Solid component that allows you to subscribe to the rate limiter state.
16
- *
17
- * This is useful for tracking specific parts of the rate limiter state
18
- * deep in your component tree without needing to pass a selector to the hook.
19
- *
20
- * @example
21
- * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount, isExecuting: state.isExecuting })}>
22
- * {(state) => (
23
- * <div>Rejected: {state().rejectionCount}, {state().isExecuting ? 'Executing' : 'Idle'}</div>
24
- * )}
25
- * </rateLimiter.Subscribe>
26
- */
27
- Subscribe: <TSelected>(props: {
28
- selector: (state: AsyncRateLimiterState<TFn>) => TSelected;
29
- children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
30
- }) => JSX.Element;
31
- /**
32
- * Reactive state that will be updated when the rate limiter state changes
33
- *
34
- * Use this instead of `rateLimiter.store.state`
35
- */
36
- readonly state: Accessor<Readonly<TSelected>>;
37
- /**
38
- * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.
39
- * The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
40
- * Although, you can make the state reactive by using the `useSelector` in your own usage.
41
- */
42
- readonly store: Store<Readonly<AsyncRateLimiterState<TFn>>>;
43
- }
44
- /**
45
- * A low-level Solid hook that creates an `AsyncRateLimiter` instance to limit how many times an async function can execute within a time window.
46
- *
47
- * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that
48
- * you can integrate with any state management solution (createSignal, etc).
49
- *
50
- * Rate limiting is a simple approach that allows a function to execute up to a limit within a time window,
51
- * then blocks all subsequent calls until the window passes. This can lead to "bursty" behavior where
52
- * all executions happen immediately, followed by a complete block.
53
- *
54
- * The rate limiter supports two types of windows:
55
- * - 'fixed': A strict window that resets after the window period. All executions within the window count
56
- * towards the limit, and the window resets completely after the period.
57
- * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more
58
- * consistent rate of execution over time.
59
- *
60
- * Unlike the non-async RateLimiter, this async version supports returning values from the rate-limited function,
61
- * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call
62
- * instead of setting the result on a state variable from within the rate-limited function.
63
- *
64
- * For smoother execution patterns, consider using:
65
- * - Throttling: Ensures consistent spacing between executions (e.g. max once per 200ms)
66
- * - Debouncing: Waits for a pause in calls before executing (e.g. after 500ms of no calls)
67
- *
68
- * Rate limiting is best used for hard API limits or resource constraints. For UI updates or
69
- * smoothing out frequent events, throttling or debouncing usually provide better user experience.
70
- *
71
- * Error Handling:
72
- * - If an `onError` handler is provided, it will be called with the error and rate limiter instance
73
- * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
74
- * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
75
- * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown
76
- * - The error state can be checked using the underlying AsyncRateLimiter instance
77
- * - Rate limit rejections (when limit is exceeded) are handled separately from execution errors via the `onReject` handler
78
- *
79
- * ## State Management and Selector
80
- *
81
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
82
- * in two ways:
83
- *
84
- * **1. Using `rateLimiter.Subscribe` component (Recommended for component tree subscriptions)**
85
- *
86
- * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
87
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
88
- * in child components.
89
- *
90
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
91
- *
92
- * The `selector` parameter allows you to specify which state changes will trigger reactive updates
93
- * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
94
- * state changes occur.
95
- *
96
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
97
- * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
98
- * updates and gives you full control over when your component tracks state changes.
99
- *
100
- * Available state properties:
101
- * - `currentWindowStart`: Timestamp when the current window started
102
- * - `executionCount`: Number of function executions that have been completed
103
- * - `hasError`: Whether the last execution resulted in an error
104
- * - `isExecuting`: Whether an async function execution is currently in progress
105
- * - `lastError`: The error from the most recent failed execution (if any)
106
- * - `lastResult`: The result from the most recent successful execution
107
- * - `nextWindowTime`: Timestamp when the next window begins
108
- * - `rejectionCount`: Number of function calls that were rejected due to rate limiting
109
- * - `remainingInWindow`: Number of executions remaining in the current window
110
- *
111
- * ## Unmount behavior
112
- *
113
- * By default, the primitive aborts any in-flight execution when the owning component unmounts.
114
- * Abort only cancels underlying operations (e.g. fetch) when the abort signal from `getAbortSignal()` is passed to them.
115
- * Use the `onUnmount` option to customize this.
116
- *
117
- * @example
118
- * ```tsx
119
- * // Default behavior - no reactive state subscriptions
120
- * const asyncRateLimiter = createAsyncRateLimiter(
121
- * async (id: string) => {
122
- * const data = await api.fetchData(id);
123
- * return data; // Return value is preserved
124
- * },
125
- * { limit: 5, window: 1000 } // 5 calls per second
126
- * );
127
- *
128
- * // Subscribe to state changes deep in component tree using Subscribe component
129
- * <asyncRateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount, isExecuting: state.isExecuting })}>
130
- * {(state) => (
131
- * <div>Rejected: {state().rejectionCount}, {state().isExecuting ? 'Executing' : 'Idle'}</div>
132
- * )}
133
- * </asyncRateLimiter.Subscribe>
134
- *
135
- * // Opt-in to track execution state changes at hook level (optimized for loading indicators)
136
- * const asyncRateLimiter = createAsyncRateLimiter(
137
- * async (id: string) => {
138
- * const data = await api.fetchData(id);
139
- * return data;
140
- * },
141
- * { limit: 5, window: 1000 },
142
- * (state) => ({ isExecuting: state.isExecuting })
143
- * );
144
- *
145
- * // Opt-in to track results when available (optimized for data display)
146
- * const asyncRateLimiter = createAsyncRateLimiter(
147
- * async (id: string) => {
148
- * const data = await api.fetchData(id);
149
- * return data;
150
- * },
151
- * { limit: 5, window: 1000 },
152
- * (state) => ({
153
- * lastResult: state.lastResult,
154
- * successCount: state.successCount
155
- * })
156
- * );
157
- *
158
- * // Opt-in to track error/rejection state changes (optimized for error handling)
159
- * const asyncRateLimiter = createAsyncRateLimiter(
160
- * async (id: string) => {
161
- * const data = await api.fetchData(id);
162
- * return data;
163
- * },
164
- * {
165
- * limit: 5,
166
- * window: 1000,
167
- * onError: (error) => console.error('API call failed:', error),
168
- * onReject: (rateLimiter) => console.log('Rate limit exceeded')
169
- * },
170
- * (state) => ({
171
- * errorCount: state.errorCount,
172
- * rejectionCount: state.rejectionCount
173
- * })
174
- * );
175
- *
176
- * // Opt-in to track execution metrics changes (optimized for stats display)
177
- * const asyncRateLimiter = createAsyncRateLimiter(
178
- * async (id: string) => {
179
- * const data = await api.fetchData(id);
180
- * return data;
181
- * },
182
- * { limit: 5, window: 1000 },
183
- * (state) => ({
184
- * successCount: state.successCount,
185
- * errorCount: state.errorCount,
186
- * settleCount: state.settleCount,
187
- * rejectionCount: state.rejectionCount
188
- * })
189
- * );
190
- *
191
- * // Opt-in to track execution times changes (optimized for window calculations)
192
- * const asyncRateLimiter = createAsyncRateLimiter(
193
- * async (id: string) => {
194
- * const data = await api.fetchData(id);
195
- * return data;
196
- * },
197
- * { limit: 5, window: 1000 },
198
- * (state) => ({ executionTimes: state.executionTimes })
199
- * );
200
- *
201
- * // Access the selected state (will be empty object {} unless selector provided)
202
- * const { isExecuting, lastResult, rejectionCount } = asyncRateLimiter.state();
203
- * ```
204
- */
205
- declare function createAsyncRateLimiter<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: SolidAsyncRateLimiterOptions<TFn, TSelected>, selector?: (state: AsyncRateLimiterState<TFn>) => TSelected): SolidAsyncRateLimiter<TFn, TSelected>;
206
- //#endregion
207
- export { SolidAsyncRateLimiter, SolidAsyncRateLimiterOptions, createAsyncRateLimiter };
208
- //# sourceMappingURL=createAsyncRateLimiter.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createAsyncRateLimiter.js","names":[],"sources":["../../src/async-rate-limiter/createAsyncRateLimiter.ts"],"sourcesContent":["import { AsyncRateLimiter } from '@tanstack/pacer/async-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 { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncRateLimiterOptions,\n AsyncRateLimiterState,\n} from '@tanstack/pacer/async-rate-limiter'\n\nexport interface SolidAsyncRateLimiterOptions<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends AsyncRateLimiterOptions<TFn> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the rate limiter instance.\n * When provided, replaces the default cleanup (abort); use it to call reset(), add logging, etc.\n */\n onUnmount?: (rateLimiter: SolidAsyncRateLimiter<TFn, TSelected>) => void\n}\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 `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<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 * ## Unmount behavior\n *\n * By default, the primitive aborts any in-flight execution when the owning component unmounts.\n * Abort only cancels underlying operations (e.g. fetch) when the abort signal from `getAbortSignal()` is passed to them.\n * Use the `onUnmount` option to customize this.\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: SolidAsyncRateLimiterOptions<TFn, TSelected>,\n selector: (state: AsyncRateLimiterState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncRateLimiter,\n ...options,\n } as SolidAsyncRateLimiterOptions<TFn, TSelected>\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 = useSelector(asyncRateLimiter.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(asyncRateLimiter.store, selector, {\n compare: shallow,\n })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(asyncRateLimiter)\n } else {\n asyncRateLimiter.abort()\n }\n })\n })\n\n return {\n ...asyncRateLimiter,\n state,\n } as SolidAsyncRateLimiter<TFn, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2NA,SAAgB,uBAId,IACA,SACA,kBACG,CAAC,IACmC;CACvC,MAAM,gBAAgB;EACpB,GAAG,uBAAuB,CAAC,CAAC;EAC5B,GAAG;CACL;CACA,MAAM,mBAAmB,IAAI,iBAC3B,IACA,aACF;CAEA,iBAAiB,YAAY,SAAS,UAAqB,OAGxD;EACD,MAAM,WAAW,YAAY,iBAAiB,OAAO,MAAM,UAAU,EACnE,SAAS,QACX,CAAC;EAED,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,QAAQ,IACvB,MAAM;CACZ;CAEA,MAAM,QAAQ,YAAY,iBAAiB,OAAO,UAAU,EAC1D,SAAS,QACX,CAAC;CAED,mBAAmB;EACjB,gBAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,gBAAgB;QAExC,iBAAiB,MAAM;EAE3B,CAAC;CACH,CAAC;CAED,OAAO;EACL,GAAG;EACH;CACF;AACF"}
@@ -1,11 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_createAsyncRateLimiter = require('./createAsyncRateLimiter.cjs');
3
-
4
- exports.createAsyncRateLimiter = require_createAsyncRateLimiter.createAsyncRateLimiter;
5
- var _tanstack_pacer_async_rate_limiter = require("@tanstack/pacer/async-rate-limiter");
6
- Object.keys(_tanstack_pacer_async_rate_limiter).forEach(function (k) {
7
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
8
- enumerable: true,
9
- get: function () { return _tanstack_pacer_async_rate_limiter[k]; }
10
- });
11
- });
@@ -1,3 +0,0 @@
1
- import { SolidAsyncRateLimiter, SolidAsyncRateLimiterOptions, createAsyncRateLimiter } from "./createAsyncRateLimiter.cjs";
2
- export * from "@tanstack/pacer/async-rate-limiter";
3
- export { SolidAsyncRateLimiter, SolidAsyncRateLimiterOptions, createAsyncRateLimiter };
@@ -1,151 +0,0 @@
1
- const require_PacerProvider = require('../provider/PacerProvider.cjs');
2
- let solid_js = require("solid-js");
3
- let _tanstack_solid_store = require("@tanstack/solid-store");
4
- let _tanstack_pacer_async_throttler = require("@tanstack/pacer/async-throttler");
5
-
6
- //#region src/async-throttler/createAsyncThrottler.ts
7
- /**
8
- * A low-level Solid hook that creates an `AsyncThrottler` instance to limit how often an async function can execute.
9
- *
10
- * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that
11
- * you can integrate with any state management solution (createSignal, etc).
12
- *
13
- * Async throttling ensures an async function executes at most once within a specified time window,
14
- * regardless of how many times it is called. This is useful for rate-limiting expensive API calls,
15
- * database operations, or other async tasks.
16
- *
17
- * Unlike the non-async Throttler, this async version supports returning values from the throttled function,
18
- * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call
19
- * instead of setting the result on a state variable from within the throttled function.
20
- *
21
- * Error Handling:
22
- * - If an `onError` handler is provided, it will be called with the error and throttler instance
23
- * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
24
- * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
25
- * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown
26
- * - The error state can be checked using the underlying AsyncThrottler instance
27
- *
28
- * ## State Management and Selector
29
- *
30
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
31
- * in two ways:
32
- *
33
- * **1. Using `throttler.Subscribe` component (Recommended for component tree subscriptions)**
34
- *
35
- * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
36
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
37
- * in child components.
38
- *
39
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
40
- *
41
- * The `selector` parameter allows you to specify which state changes will trigger reactive updates
42
- * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
43
- * state changes occur.
44
- *
45
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
46
- * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
47
- * updates and gives you full control over when your component tracks state changes.
48
- *
49
- * Available state properties:
50
- * - `canLeadingExecute`: Whether the throttler can execute on the leading edge
51
- * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge
52
- * - `executionCount`: Number of function executions that have been completed
53
- * - `hasError`: Whether the last execution resulted in an error
54
- * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution
55
- * - `isExecuting`: Whether an async function execution is currently in progress
56
- * - `lastArgs`: The arguments from the most recent call to maybeExecute
57
- * - `lastError`: The error from the most recent failed execution (if any)
58
- * - `lastExecutionTime`: Timestamp of the last execution
59
- * - `lastResult`: The result from the most recent successful execution
60
- * - `nextExecutionTime`: Timestamp of the next allowed execution
61
- * - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing')
62
- *
63
- * ## Unmount behavior
64
- *
65
- * By default, the primitive cancels any pending execution and aborts any in-flight execution when the owning component unmounts.
66
- * Abort only cancels underlying operations (e.g. fetch) when the abort signal from `getAbortSignal()` is passed to them.
67
- * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
68
- *
69
- * ```tsx
70
- * const throttler = createAsyncThrottler(fn, {
71
- * wait: 1000,
72
- * onUnmount: (t) => t.flush()
73
- * });
74
- * ```
75
- *
76
- * Note: For async utils, `flush()` returns a Promise and runs fire-and-forget in the cleanup.
77
- * If your throttled function updates Solid signals, those updates may run after the component has
78
- * unmounted, which can cause unexpected reactive updates. Guard your callbacks accordingly when
79
- * using onUnmount with flush.
80
- *
81
- * @example
82
- * ```tsx
83
- * // Default behavior - no reactive state subscriptions
84
- * const { maybeExecute } = createAsyncThrottler(
85
- * async (id: string) => {
86
- * const data = await api.fetchData(id);
87
- * return data;
88
- * },
89
- * { wait: 1000 }
90
- * );
91
- *
92
- * // Opt-in to track isPending or isExecuting changes (optimized for loading states)
93
- * const throttler = createAsyncThrottler(
94
- * async (query) => {
95
- * const result = await searchAPI(query);
96
- * return result;
97
- * },
98
- * { wait: 2000 },
99
- * (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })
100
- * );
101
- *
102
- * // Opt-in to track error state changes (optimized for error handling)
103
- * const throttler = createAsyncThrottler(
104
- * async (query) => {
105
- * const result = await searchAPI(query);
106
- * return result;
107
- * },
108
- * {
109
- * wait: 2000,
110
- * leading: true, // Execute immediately on first call
111
- * trailing: false, // Skip trailing edge updates
112
- * onError: (error) => {
113
- * console.error('API call failed:', error);
114
- * }
115
- * },
116
- * (state) => ({ hasError: state.hasError, lastError: state.lastError })
117
- * );
118
- *
119
- * // Access the selected state (will be empty object {} unless selector provided)
120
- * const { isPending, isExecuting } = throttler.state();
121
- * ```
122
- */
123
- function createAsyncThrottler(fn, options, selector = () => ({})) {
124
- const mergedOptions = {
125
- ...require_PacerProvider.useDefaultPacerOptions().asyncThrottler,
126
- ...options
127
- };
128
- const asyncThrottler = new _tanstack_pacer_async_throttler.AsyncThrottler(fn, mergedOptions);
129
- asyncThrottler.Subscribe = function Subscribe(props) {
130
- const selected = (0, _tanstack_solid_store.useSelector)(asyncThrottler.store, props.selector, { compare: _tanstack_solid_store.shallow });
131
- return typeof props.children === "function" ? props.children(selected) : props.children;
132
- };
133
- const state = (0, _tanstack_solid_store.useSelector)(asyncThrottler.store, selector, { compare: _tanstack_solid_store.shallow });
134
- (0, solid_js.createEffect)(() => {
135
- (0, solid_js.onCleanup)(() => {
136
- if (mergedOptions.onUnmount) mergedOptions.onUnmount(asyncThrottler);
137
- else {
138
- asyncThrottler.cancel();
139
- asyncThrottler.abort();
140
- }
141
- });
142
- });
143
- return {
144
- ...asyncThrottler,
145
- state
146
- };
147
- }
148
-
149
- //#endregion
150
- exports.createAsyncThrottler = createAsyncThrottler;
151
- //# sourceMappingURL=createAsyncThrottler.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createAsyncThrottler.cjs","names":["useDefaultPacerOptions","AsyncThrottler","useSelector","shallow"],"sources":["../../src/async-throttler/createAsyncThrottler.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { AsyncThrottler } from '@tanstack/pacer/async-throttler'\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 { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncThrottlerOptions,\n AsyncThrottlerState,\n} from '@tanstack/pacer/async-throttler'\n\nexport interface SolidAsyncThrottlerOptions<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends AsyncThrottlerOptions<TFn> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the throttler instance.\n * When provided, replaces the default cleanup (cancel + abort); use it to call flush(), reset(), cancel(), add logging, etc.\n */\n onUnmount?: (throttler: SolidAsyncThrottler<TFn, TSelected>) => void\n}\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 `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<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 * ## Unmount behavior\n *\n * By default, the primitive cancels any pending execution and aborts any in-flight execution when the owning component unmounts.\n * Abort only cancels underlying operations (e.g. fetch) when the abort signal from `getAbortSignal()` is passed to them.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```tsx\n * const throttler = createAsyncThrottler(fn, {\n * wait: 1000,\n * onUnmount: (t) => t.flush()\n * });\n * ```\n *\n * Note: For async utils, `flush()` returns a Promise and runs fire-and-forget in the cleanup.\n * If your throttled function updates Solid signals, those updates may run after the component has\n * unmounted, which can cause unexpected reactive updates. Guard your callbacks accordingly when\n * using onUnmount with flush.\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: SolidAsyncThrottlerOptions<TFn, TSelected>,\n selector: (state: AsyncThrottlerState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncThrottler,\n ...options,\n } as SolidAsyncThrottlerOptions<TFn, TSelected>\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 = useSelector(asyncThrottler.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(asyncThrottler.store, selector, {\n compare: shallow,\n })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(asyncThrottler)\n } else {\n asyncThrottler.cancel()\n asyncThrottler.abort()\n }\n })\n })\n\n return {\n ...asyncThrottler,\n state,\n } as SolidAsyncThrottler<TFn, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8KA,SAAgB,qBAId,IACA,SACA,kBACG,CAAC,IACiC;CACrC,MAAM,gBAAgB;EACpB,GAAGA,6CAAuB,CAAC,CAAC;EAC5B,GAAG;CACL;CACA,MAAM,iBAAiB,IAAIC,+CACzB,IACA,aACF;CAEA,eAAe,YAAY,SAAS,UAAqB,OAGtD;EACD,MAAM,eAAWC,mCAAY,eAAe,OAAO,MAAM,UAAU,EACjE,SAASC,8BACX,CAAC;EAED,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,QAAQ,IACvB,MAAM;CACZ;CAEA,MAAM,YAAQD,mCAAY,eAAe,OAAO,UAAU,EACxD,SAASC,8BACX,CAAC;CAED,iCAAmB;EACjB,8BAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,cAAc;QACjC;IACL,eAAe,OAAO;IACtB,eAAe,MAAM;GACvB;EACF,CAAC;CACH,CAAC;CAED,OAAO;EACL,GAAG;EACH;CACF;AACF"}