@tanstack/solid-pacer 0.21.1 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/README.md +21 -6
  2. package/dist/async-batcher/createAsyncBatcher.d.ts +5 -10
  3. package/dist/async-batcher/createAsyncBatcher.js +2 -5
  4. package/dist/async-debouncer/createAsyncDebouncer.d.ts +8 -12
  5. package/dist/async-debouncer/createAsyncDebouncer.js +5 -7
  6. package/dist/async-queuer/createAsyncQueuer.d.ts +9 -12
  7. package/dist/async-queuer/createAsyncQueuer.js +4 -5
  8. package/dist/async-rate-limiter/createAsyncRateLimiter.d.ts +10 -13
  9. package/dist/async-rate-limiter/createAsyncRateLimiter.js +7 -8
  10. package/dist/async-throttler/createAsyncThrottler.d.ts +8 -14
  11. package/dist/async-throttler/createAsyncThrottler.js +5 -9
  12. package/dist/batcher/createBatcher.d.ts +11 -15
  13. package/dist/batcher/createBatcher.js +6 -8
  14. package/dist/debouncer/createDebouncedSignal.d.ts +2 -5
  15. package/dist/debouncer/createDebouncedSignal.js +1 -2
  16. package/dist/debouncer/createDebouncedValue.d.ts +2 -5
  17. package/dist/debouncer/createDebouncedValue.js +1 -2
  18. package/dist/debouncer/createDebouncer.d.ts +4 -7
  19. package/dist/debouncer/createDebouncer.js +1 -2
  20. package/dist/provider/PacerProvider.d.ts +6 -9
  21. package/dist/provider/PacerProvider.js +1 -2
  22. package/dist/queuer/createQueuedSignal.d.ts +2 -5
  23. package/dist/queuer/createQueuedSignal.js +1 -2
  24. package/dist/queuer/createQueuer.d.ts +4 -7
  25. package/dist/queuer/createQueuer.js +1 -2
  26. package/dist/rate-limiter/createRateLimitedSignal.d.ts +12 -14
  27. package/dist/rate-limiter/createRateLimitedSignal.js +11 -11
  28. package/dist/rate-limiter/createRateLimitedValue.d.ts +2 -5
  29. package/dist/rate-limiter/createRateLimitedValue.js +1 -2
  30. package/dist/rate-limiter/createRateLimiter.d.ts +8 -10
  31. package/dist/rate-limiter/createRateLimiter.js +5 -5
  32. package/dist/throttler/createThrottledSignal.d.ts +2 -7
  33. package/dist/throttler/createThrottledSignal.js +1 -4
  34. package/dist/throttler/createThrottledValue.d.ts +2 -7
  35. package/dist/throttler/createThrottledValue.js +1 -4
  36. package/dist/throttler/createThrottler.d.ts +4 -9
  37. package/dist/throttler/createThrottler.js +1 -4
  38. package/package.json +24 -68
  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 -178
  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 -164
  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 -170
  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 -209
  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 -164
  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 -147
  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 -80
  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 -71
  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 -145
  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 -29
  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 -122
  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 -148
  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 -94
  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 -96
  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 -174
  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 -71
  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 -68
  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 -148
  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 -9
  136. package/dist/types/index.d.cts +0 -1
  137. package/dist/utils/index.cjs +0 -9
  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 +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,EAAE,GACkC;CACvC,MAAM,gBAAgB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,mBAAmB,IAAI,iBAC3B,IACA,cACD;CAED,iBAAiB,YAAY,SAAS,UAAqB,OAGxD;EACD,MAAM,WAAW,YAAY,iBAAiB,OAAO,MAAM,UAAU,EACnE,SAAS,SACV,CAAC;EAEF,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,QAAQ,YAAY,iBAAiB,OAAO,UAAU,EAC1D,SAAS,SACV,CAAC;CAEF,mBAAmB;EACjB,gBAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,iBAAiB;QAEzC,iBAAiB,OAAO;IAE1B;GACF;CAEF,OAAO;EACL,GAAG;EACH;EACD"}
@@ -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","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,EAAE,GACgC;CACrC,MAAM,gBAAgB;EACpB,GAAGA,8CAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,iBAAiB,IAAIC,+CACzB,IACA,cACD;CAED,eAAe,YAAY,SAAS,UAAqB,OAGtD;EACD,MAAM,kDAAuB,eAAe,OAAO,MAAM,UAAU,EACjE,SAASC,+BACV,CAAC;EAEF,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,+CAAoB,eAAe,OAAO,UAAU,EACxD,SAASA,+BACV,CAAC;CAEF,iCAAmB;EACjB,8BAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,eAAe;QAClC;IACL,eAAe,QAAQ;IACvB,eAAe,OAAO;;IAExB;GACF;CAEF,OAAO;EACL,GAAG;EACH;EACD"}
@@ -1,164 +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 { AsyncThrottler, AsyncThrottlerOptions, AsyncThrottlerState } from "@tanstack/pacer/async-throttler";
5
-
6
- //#region src/async-throttler/createAsyncThrottler.d.ts
7
- interface SolidAsyncThrottlerOptions<TFn extends AnyAsyncFunction, TSelected = {}> extends AsyncThrottlerOptions<TFn> {
8
- /**
9
- * Optional callback invoked when the owning component unmounts. Receives the throttler instance.
10
- * When provided, replaces the default cleanup (cancel + abort); use it to call flush(), reset(), cancel(), add logging, etc.
11
- */
12
- onUnmount?: (throttler: SolidAsyncThrottler<TFn, TSelected>) => void;
13
- }
14
- interface SolidAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncThrottler<TFn>, 'store'> {
15
- /**
16
- * A Solid component that allows you to subscribe to the throttler state.
17
- *
18
- * This is useful for tracking specific parts of the throttler state
19
- * deep in your component tree without needing to pass a selector to the hook.
20
- *
21
- * @example
22
- * <throttler.Subscribe selector={(state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })}>
23
- * {(state) => (
24
- * <div>{state().isPending ? 'Pending...' : state().isExecuting ? 'Executing...' : 'Ready'}</div>
25
- * )}
26
- * </throttler.Subscribe>
27
- */
28
- Subscribe: <TSelected>(props: {
29
- selector: (state: AsyncThrottlerState<TFn>) => TSelected;
30
- children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
31
- }) => JSX.Element;
32
- /**
33
- * Reactive state that will be updated when the throttler state changes
34
- *
35
- * Use this instead of `throttler.store.state`
36
- */
37
- readonly state: Accessor<Readonly<TSelected>>;
38
- /**
39
- * @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.
40
- * The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
41
- * Although, you can make the state reactive by using the `useSelector` in your own usage.
42
- */
43
- readonly store: Store<Readonly<AsyncThrottlerState<TFn>>>;
44
- }
45
- /**
46
- * A low-level Solid hook that creates an `AsyncThrottler` instance to limit how often an async function can execute.
47
- *
48
- * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that
49
- * you can integrate with any state management solution (createSignal, etc).
50
- *
51
- * Async throttling ensures an async function executes at most once within a specified time window,
52
- * regardless of how many times it is called. This is useful for rate-limiting expensive API calls,
53
- * database operations, or other async tasks.
54
- *
55
- * Unlike the non-async Throttler, this async version supports returning values from the throttled function,
56
- * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call
57
- * instead of setting the result on a state variable from within the throttled function.
58
- *
59
- * Error Handling:
60
- * - If an `onError` handler is provided, it will be called with the error and throttler instance
61
- * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
62
- * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
63
- * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown
64
- * - The error state can be checked using the underlying AsyncThrottler instance
65
- *
66
- * ## State Management and Selector
67
- *
68
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
69
- * in two ways:
70
- *
71
- * **1. Using `throttler.Subscribe` component (Recommended for component tree subscriptions)**
72
- *
73
- * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
74
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
75
- * in child components.
76
- *
77
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
78
- *
79
- * The `selector` parameter allows you to specify which state changes will trigger reactive updates
80
- * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
81
- * state changes occur.
82
- *
83
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
84
- * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
85
- * updates and gives you full control over when your component tracks state changes.
86
- *
87
- * Available state properties:
88
- * - `canLeadingExecute`: Whether the throttler can execute on the leading edge
89
- * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge
90
- * - `executionCount`: Number of function executions that have been completed
91
- * - `hasError`: Whether the last execution resulted in an error
92
- * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution
93
- * - `isExecuting`: Whether an async function execution is currently in progress
94
- * - `lastArgs`: The arguments from the most recent call to maybeExecute
95
- * - `lastError`: The error from the most recent failed execution (if any)
96
- * - `lastExecutionTime`: Timestamp of the last execution
97
- * - `lastResult`: The result from the most recent successful execution
98
- * - `nextExecutionTime`: Timestamp of the next allowed execution
99
- * - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing')
100
- *
101
- * ## Unmount behavior
102
- *
103
- * By default, the primitive cancels any pending execution and aborts any in-flight execution when the owning component unmounts.
104
- * Abort only cancels underlying operations (e.g. fetch) when the abort signal from `getAbortSignal()` is passed to them.
105
- * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
106
- *
107
- * ```tsx
108
- * const throttler = createAsyncThrottler(fn, {
109
- * wait: 1000,
110
- * onUnmount: (t) => t.flush()
111
- * });
112
- * ```
113
- *
114
- * Note: For async utils, `flush()` returns a Promise and runs fire-and-forget in the cleanup.
115
- * If your throttled function updates Solid signals, those updates may run after the component has
116
- * unmounted, which can cause unexpected reactive updates. Guard your callbacks accordingly when
117
- * using onUnmount with flush.
118
- *
119
- * @example
120
- * ```tsx
121
- * // Default behavior - no reactive state subscriptions
122
- * const { maybeExecute } = createAsyncThrottler(
123
- * async (id: string) => {
124
- * const data = await api.fetchData(id);
125
- * return data;
126
- * },
127
- * { wait: 1000 }
128
- * );
129
- *
130
- * // Opt-in to track isPending or isExecuting changes (optimized for loading states)
131
- * const throttler = createAsyncThrottler(
132
- * async (query) => {
133
- * const result = await searchAPI(query);
134
- * return result;
135
- * },
136
- * { wait: 2000 },
137
- * (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })
138
- * );
139
- *
140
- * // Opt-in to track error state changes (optimized for error handling)
141
- * const throttler = createAsyncThrottler(
142
- * async (query) => {
143
- * const result = await searchAPI(query);
144
- * return result;
145
- * },
146
- * {
147
- * wait: 2000,
148
- * leading: true, // Execute immediately on first call
149
- * trailing: false, // Skip trailing edge updates
150
- * onError: (error) => {
151
- * console.error('API call failed:', error);
152
- * }
153
- * },
154
- * (state) => ({ hasError: state.hasError, lastError: state.lastError })
155
- * );
156
- *
157
- * // Access the selected state (will be empty object {} unless selector provided)
158
- * const { isPending, isExecuting } = throttler.state();
159
- * ```
160
- */
161
- declare function createAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: SolidAsyncThrottlerOptions<TFn, TSelected>, selector?: (state: AsyncThrottlerState<TFn>) => TSelected): SolidAsyncThrottler<TFn, TSelected>;
162
- //#endregion
163
- export { SolidAsyncThrottler, SolidAsyncThrottlerOptions, createAsyncThrottler };
164
- //# sourceMappingURL=createAsyncThrottler.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createAsyncThrottler.js","names":[],"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,EAAE,GACgC;CACrC,MAAM,gBAAgB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,iBAAiB,IAAI,eACzB,IACA,cACD;CAED,eAAe,YAAY,SAAS,UAAqB,OAGtD;EACD,MAAM,WAAW,YAAY,eAAe,OAAO,MAAM,UAAU,EACjE,SAAS,SACV,CAAC;EAEF,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,QAAQ,YAAY,eAAe,OAAO,UAAU,EACxD,SAAS,SACV,CAAC;CAEF,mBAAmB;EACjB,gBAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,eAAe;QAClC;IACL,eAAe,QAAQ;IACvB,eAAe,OAAO;;IAExB;GACF;CAEF,OAAO;EACL,GAAG;EACH;EACD"}
@@ -1,11 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_createAsyncThrottler = require('./createAsyncThrottler.cjs');
3
-
4
- exports.createAsyncThrottler = require_createAsyncThrottler.createAsyncThrottler;
5
- var _tanstack_pacer_async_throttler = require("@tanstack/pacer/async-throttler");
6
- Object.keys(_tanstack_pacer_async_throttler).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_throttler[k]; }
10
- });
11
- });
@@ -1,3 +0,0 @@
1
- import { SolidAsyncThrottler, SolidAsyncThrottlerOptions, createAsyncThrottler } from "./createAsyncThrottler.cjs";
2
- export * from "@tanstack/pacer/async-throttler";
3
- export { SolidAsyncThrottler, SolidAsyncThrottlerOptions, createAsyncThrottler };
@@ -1,132 +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_batcher = require("@tanstack/pacer/batcher");
5
-
6
- //#region src/batcher/createBatcher.ts
7
- /**
8
- * Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.
9
- *
10
- * Features:
11
- * - Batch processing of items using the provided `fn` function
12
- * - Configurable batch size and wait time
13
- * - Custom batch processing logic via getShouldExecute
14
- * - Event callbacks for monitoring batch operations
15
- * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity
16
- *
17
- * The batcher collects items and processes them in batches based on:
18
- * - Maximum batch size
19
- * - Time-based batching (process after X milliseconds)
20
- * - Custom batch processing logic via getShouldExecute
21
- *
22
- * ## State Management and Selector
23
- *
24
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
25
- * in two ways:
26
- *
27
- * **1. Using `batcher.Subscribe` component (Recommended for component tree subscriptions)**
28
- *
29
- * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
30
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
31
- * in child components.
32
- *
33
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
34
- *
35
- * The `selector` parameter allows you to specify which state changes will trigger reactive updates
36
- * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
37
- * state changes occur.
38
- *
39
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
40
- * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
41
- * updates and gives you full control over when your component tracks state changes.
42
- *
43
- * Available state properties:
44
- * - `executionCount`: Number of batch executions that have been completed
45
- * - `isRunning`: Whether the batcher is currently running (not stopped)
46
- * - `items`: Array of items currently queued for batching
47
- * - `totalItemsProcessed`: Total number of individual items that have been processed across all batches
48
- *
49
- * ## Unmount behavior
50
- *
51
- * By default, the primitive cancels any pending batch when the owning component unmounts.
52
- * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
53
- *
54
- * ```tsx
55
- * const batcher = createBatcher(fn, {
56
- * maxSize: 10,
57
- * wait: 2000,
58
- * onUnmount: (b) => b.flush()
59
- * });
60
- * ```
61
- *
62
- * Example usage:
63
- * ```tsx
64
- * // Default behavior - no reactive state subscriptions
65
- * const batcher = createBatcher(
66
- * (items) => {
67
- * // Process batch of items
68
- * console.log('Processing batch:', items);
69
- * },
70
- * {
71
- * maxSize: 5,
72
- * wait: 2000,
73
- * onExecute: (batcher) => console.log('Batch executed'),
74
- * getShouldExecute: (items) => items.length >= 3
75
- * }
76
- * );
77
- *
78
- * // Opt-in to track items or isRunning changes (optimized for UI updates)
79
- * const batcher = createBatcher(
80
- * (items) => console.log('Processing batch:', items),
81
- * { maxSize: 5, wait: 2000 },
82
- * (state) => ({ items: state.items, isRunning: state.isRunning })
83
- * );
84
- *
85
- * // Opt-in to track execution metrics changes (optimized for tracking progress)
86
- * const batcher = createBatcher(
87
- * (items) => console.log('Processing batch:', items),
88
- * { maxSize: 5, wait: 2000 },
89
- * (state) => ({
90
- * executionCount: state.executionCount,
91
- * totalItemsProcessed: state.totalItemsProcessed
92
- * })
93
- * );
94
- *
95
- * // Add items to batch
96
- * batcher.addItem('task1');
97
- * batcher.addItem('task2');
98
- *
99
- * // Control the batcher
100
- * batcher.stop(); // Pause processing
101
- * batcher.start(); // Resume processing
102
- *
103
- * // Access the selected state (will be empty object {} unless selector provided)
104
- * const { items, isRunning } = batcher.state();
105
- * ```
106
- */
107
- function createBatcher(fn, options = {}, selector = () => ({})) {
108
- const mergedOptions = {
109
- ...require_PacerProvider.useDefaultPacerOptions().batcher,
110
- ...options
111
- };
112
- const batcher = new _tanstack_pacer_batcher.Batcher(fn, mergedOptions);
113
- batcher.Subscribe = function Subscribe(props) {
114
- const selected = (0, _tanstack_solid_store.useSelector)(batcher.store, props.selector, { compare: _tanstack_solid_store.shallow });
115
- return typeof props.children === "function" ? props.children(selected) : props.children;
116
- };
117
- const state = (0, _tanstack_solid_store.useSelector)(batcher.store, selector, { compare: _tanstack_solid_store.shallow });
118
- (0, solid_js.createEffect)(() => {
119
- (0, solid_js.onCleanup)(() => {
120
- if (mergedOptions.onUnmount) mergedOptions.onUnmount(batcher);
121
- else batcher.cancel();
122
- });
123
- });
124
- return {
125
- ...batcher,
126
- state
127
- };
128
- }
129
-
130
- //#endregion
131
- exports.createBatcher = createBatcher;
132
- //# sourceMappingURL=createBatcher.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createBatcher.cjs","names":["useDefaultPacerOptions","Batcher","shallow"],"sources":["../../src/batcher/createBatcher.ts"],"sourcesContent":["import { Batcher } from '@tanstack/pacer/batcher'\nimport { shallow, useSelector } from '@tanstack/solid-store'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { BatcherOptions, BatcherState } from '@tanstack/pacer/batcher'\n\nexport interface SolidBatcherOptions<\n TValue,\n TSelected = {},\n> extends BatcherOptions<TValue> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the batcher instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.\n */\n onUnmount?: (batcher: SolidBatcher<TValue, TSelected>) => void\n}\n\nexport interface SolidBatcher<TValue, TSelected = {}> extends Omit<\n Batcher<TValue>,\n 'store'\n> {\n /**\n * A Solid component that allows you to subscribe to the batcher state.\n *\n * This is useful for tracking specific parts of the batcher state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <batcher.Subscribe selector={(state) => ({ size: state.size, isRunning: state.isRunning })}>\n * {(state) => (\n * <div>Batch: {state().size} items, {state().isRunning ? 'Processing' : 'Idle'}</div>\n * )}\n * </batcher.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: BatcherState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.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<BatcherState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Batch processing of items using the provided `fn` function\n * - Configurable batch size and wait time\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The batcher collects items and processes them in batches based on:\n * - Maximum batch size\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\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 `batcher.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `executionCount`: Number of batch executions that have been completed\n * - `isRunning`: Whether the batcher is currently running (not stopped)\n * - `items`: Array of items currently queued for batching\n * - `totalItemsProcessed`: Total number of individual items that have been processed across all batches\n *\n * ## Unmount behavior\n *\n * By default, the primitive cancels any pending batch when the owning component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```tsx\n * const batcher = createBatcher(fn, {\n * maxSize: 10,\n * wait: 2000,\n * onUnmount: (b) => b.flush()\n * });\n * ```\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const batcher = createBatcher(\n * (items) => {\n * // Process batch of items\n * console.log('Processing batch:', items);\n * },\n * {\n * maxSize: 5,\n * wait: 2000,\n * onExecute: (batcher) => console.log('Batch executed'),\n * getShouldExecute: (items) => items.length >= 3\n * }\n * );\n *\n * // Opt-in to track items or isRunning changes (optimized for UI updates)\n * const batcher = createBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({ items: state.items, isRunning: state.isRunning })\n * );\n *\n * // Opt-in to track execution metrics changes (optimized for tracking progress)\n * const batcher = createBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * totalItemsProcessed: state.totalItemsProcessed\n * })\n * );\n *\n * // Add items to batch\n * batcher.addItem('task1');\n * batcher.addItem('task2');\n *\n * // Control the batcher\n * batcher.stop(); // Pause processing\n * batcher.start(); // Resume processing\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isRunning } = batcher.state();\n * ```\n */\nexport function createBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => void,\n options: SolidBatcherOptions<TValue, TSelected> = {},\n selector: (state: BatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): SolidBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().batcher,\n ...options,\n } as SolidBatcherOptions<TValue, TSelected>\n const batcher = new Batcher(fn, mergedOptions) as unknown as SolidBatcher<\n TValue,\n TSelected\n >\n\n batcher.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: BatcherState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(batcher.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(batcher.store, selector, { compare: shallow })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(batcher)\n } else {\n batcher.cancel()\n }\n })\n })\n\n return {\n ...batcher,\n state,\n } as SolidBatcher<TValue, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0JA,SAAgB,cACd,IACA,UAAkD,EAAE,EACpD,kBACG,EAAE,GAC4B;CACjC,MAAM,gBAAgB;EACpB,GAAGA,8CAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,UAAU,IAAIC,gCAAQ,IAAI,cAAc;CAK9C,QAAQ,YAAY,SAAS,UAAqB,OAG/C;EACD,MAAM,kDAAuB,QAAQ,OAAO,MAAM,UAAU,EAC1D,SAASC,+BACV,CAAC;EAEF,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,+CAAoB,QAAQ,OAAO,UAAU,EAAE,SAASA,+BAAS,CAAC;CAExE,iCAAmB;EACjB,8BAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,QAAQ;QAEhC,QAAQ,QAAQ;IAElB;GACF;CAEF,OAAO;EACL,GAAG;EACH;EACD"}