@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,163 +0,0 @@
1
- import { Store } from "@tanstack/solid-store";
2
- import { Accessor, JSX } from "solid-js";
3
- import { AsyncDebouncer, AsyncDebouncerOptions, AsyncDebouncerState } from "@tanstack/pacer/async-debouncer";
4
- import { AnyAsyncFunction } from "@tanstack/pacer/types";
5
- //#region src/async-debouncer/createAsyncDebouncer.d.ts
6
- interface SolidAsyncDebouncerOptions<TFn extends AnyAsyncFunction, TSelected = {}> extends AsyncDebouncerOptions<TFn> {
7
- /**
8
- * Optional callback invoked when the owning component unmounts. Receives the debouncer instance.
9
- * When provided, replaces the default cleanup (cancel + abort); use it to call flush(), reset(), cancel(), add logging, etc.
10
- */
11
- onUnmount?: (debouncer: SolidAsyncDebouncer<TFn, TSelected>) => void;
12
- }
13
- interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncDebouncer<TFn>, 'store'> {
14
- /**
15
- * A Solid component that allows you to subscribe to the debouncer state.
16
- *
17
- * This is useful for tracking specific parts of the debouncer state
18
- * deep in your component tree without needing to pass a selector to the hook.
19
- *
20
- * @example
21
- * <debouncer.Subscribe selector={(state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })}>
22
- * {(state) => (
23
- * <div>{state().isPending ? 'Waiting...' : state().isExecuting ? 'Executing...' : 'Ready'}</div>
24
- * )}
25
- * </debouncer.Subscribe>
26
- */
27
- Subscribe: <TSelected>(props: {
28
- selector: (state: AsyncDebouncerState<TFn>) => TSelected;
29
- children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
30
- }) => JSX.Element;
31
- /**
32
- * Reactive state that will be updated when the debouncer state changes
33
- *
34
- * Use this instead of `debouncer.store.state`
35
- */
36
- readonly state: Accessor<Readonly<TSelected>>;
37
- /**
38
- * @deprecated Use `debouncer.state` instead of `debouncer.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<AsyncDebouncerState<TFn>>>;
43
- }
44
- /**
45
- * A low-level Solid hook that creates an `AsyncDebouncer` instance to delay execution of an async function.
46
- *
47
- * This hook is designed to be flexible and state-management agnostic - it simply returns a debouncer instance that
48
- * you can integrate with any state management solution (createSignal, etc).
49
- *
50
- * Async debouncing ensures that an async function only executes after a specified delay has passed since its last invocation.
51
- * Each new invocation resets the delay timer. This is useful for handling frequent events like window resizing
52
- * or input changes where you only want to execute the handler after the events have stopped occurring.
53
- *
54
- * Unlike throttling which allows execution at regular intervals, debouncing prevents any execution until
55
- * the function stops being called for the specified delay period.
56
- *
57
- * Unlike the non-async Debouncer, this async version supports returning values from the debounced function,
58
- * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call
59
- * instead of setting the result on a state variable from within the debounced function.
60
- *
61
- * Error Handling:
62
- * - If an `onError` handler is provided, it will be called with the error and debouncer instance
63
- * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
64
- * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
65
- * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown
66
- * - The error state can be checked using the underlying AsyncDebouncer instance
67
- *
68
- * ## State Management and Selector
69
- *
70
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
71
- * in two ways:
72
- *
73
- * **1. Using `debouncer.Subscribe` component (Recommended for component tree subscriptions)**
74
- *
75
- * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
76
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
77
- * in child components.
78
- *
79
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
80
- *
81
- * The `selector` parameter allows you to specify which state changes will trigger reactive updates
82
- * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
83
- * state changes occur.
84
- *
85
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
86
- * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
87
- * updates and gives you full control over when your component tracks state changes.
88
- *
89
- * Available state properties:
90
- * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
91
- * - `executionCount`: Number of function executions that have been completed
92
- * - `hasError`: Whether the last execution resulted in an error
93
- * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
94
- * - `isExecuting`: Whether an async function execution is currently in progress
95
- * - `lastArgs`: The arguments from the most recent call to maybeExecute
96
- * - `lastError`: The error from the most recent failed execution (if any)
97
- * - `lastResult`: The result from the most recent successful execution
98
- * - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing')
99
- *
100
- * ## Unmount behavior
101
- *
102
- * By default, the primitive cancels any pending execution and aborts any in-flight execution when the owning component unmounts.
103
- * Abort only cancels underlying operations (e.g. fetch) when the abort signal from `getAbortSignal()` is passed to them.
104
- * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
105
- *
106
- * ```tsx
107
- * const debouncer = createAsyncDebouncer(fn, {
108
- * wait: 500,
109
- * onUnmount: (d) => d.flush()
110
- * });
111
- * ```
112
- *
113
- * Note: For async utils, `flush()` returns a Promise and runs fire-and-forget in the cleanup.
114
- * If your debounced function updates Solid signals, those updates may run after the component has
115
- * unmounted, which can cause unexpected reactive updates. Guard your callbacks accordingly when
116
- * using onUnmount with flush.
117
- *
118
- * @example
119
- * ```tsx
120
- * // Default behavior - no reactive state subscriptions
121
- * const { maybeExecute } = createAsyncDebouncer(
122
- * async (query: string) => {
123
- * const results = await api.search(query);
124
- * return results;
125
- * },
126
- * { wait: 500 }
127
- * );
128
- *
129
- * // Opt-in to track isPending or isExecuting changes (optimized for loading states)
130
- * const debouncer = createAsyncDebouncer(
131
- * async (query: string) => {
132
- * const results = await api.search(query);
133
- * return results;
134
- * },
135
- * { wait: 500 },
136
- * (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })
137
- * );
138
- *
139
- * // Opt-in to track error state changes (optimized for error handling)
140
- * const debouncer = createAsyncDebouncer(
141
- * async (searchTerm) => {
142
- * const data = await searchAPI(searchTerm);
143
- * return data;
144
- * },
145
- * {
146
- * wait: 300,
147
- * leading: true, // Execute immediately on first call
148
- * trailing: false, // Skip trailing edge updates
149
- * onError: (error) => {
150
- * console.error('API call failed:', error);
151
- * }
152
- * },
153
- * (state) => ({ hasError: state.hasError, lastError: state.lastError })
154
- * );
155
- *
156
- * // Access the selected state (will be empty object {} unless selector provided)
157
- * const { isPending, isExecuting } = debouncer.state();
158
- * ```
159
- */
160
- declare function createAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: SolidAsyncDebouncerOptions<TFn, TSelected>, selector?: (state: AsyncDebouncerState<TFn>) => TSelected): SolidAsyncDebouncer<TFn, TSelected>;
161
- //#endregion
162
- export { SolidAsyncDebouncer, SolidAsyncDebouncerOptions, createAsyncDebouncer };
163
- //# sourceMappingURL=createAsyncDebouncer.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createAsyncDebouncer.js","names":[],"sources":["../../src/async-debouncer/createAsyncDebouncer.ts"],"sourcesContent":["import { AsyncDebouncer } from '@tanstack/pacer/async-debouncer'\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 {\n AsyncDebouncerOptions,\n AsyncDebouncerState,\n} from '@tanstack/pacer/async-debouncer'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\n\nexport interface SolidAsyncDebouncerOptions<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends AsyncDebouncerOptions<TFn> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the debouncer instance.\n * When provided, replaces the default cleanup (cancel + abort); use it to call flush(), reset(), cancel(), add logging, etc.\n */\n onUnmount?: (debouncer: SolidAsyncDebouncer<TFn, TSelected>) => void\n}\n\nexport interface SolidAsyncDebouncer<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncDebouncer<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the debouncer state.\n *\n * This is useful for tracking specific parts of the debouncer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <debouncer.Subscribe selector={(state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })}>\n * {(state) => (\n * <div>{state().isPending ? 'Waiting...' : state().isExecuting ? 'Executing...' : 'Ready'}</div>\n * )}\n * </debouncer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: AsyncDebouncerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the debouncer state changes\n *\n * Use this instead of `debouncer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `debouncer.state` instead of `debouncer.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<AsyncDebouncerState<TFn>>>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncDebouncer` instance to delay execution of an async function.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a debouncer instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Async debouncing ensures that an async function only executes after a specified delay has passed since its last invocation.\n * Each new invocation resets the delay timer. This is useful for handling frequent events like window resizing\n * or input changes where you only want to execute the handler after the events have stopped occurring.\n *\n * Unlike throttling which allows execution at regular intervals, debouncing prevents any execution until\n * the function stops being called for the specified delay period.\n *\n * Unlike the non-async Debouncer, this async version supports returning values from the debounced 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 debounced function.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and debouncer 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 AsyncDebouncer 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 `debouncer.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 debouncer can execute on the leading 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 debouncer 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 * - `lastResult`: The result from the most recent successful 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 debouncer = createAsyncDebouncer(fn, {\n * wait: 500,\n * onUnmount: (d) => d.flush()\n * });\n * ```\n *\n * Note: For async utils, `flush()` returns a Promise and runs fire-and-forget in the cleanup.\n * If your debounced 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 } = createAsyncDebouncer(\n * async (query: string) => {\n * const results = await api.search(query);\n * return results;\n * },\n * { wait: 500 }\n * );\n *\n * // Opt-in to track isPending or isExecuting changes (optimized for loading states)\n * const debouncer = createAsyncDebouncer(\n * async (query: string) => {\n * const results = await api.search(query);\n * return results;\n * },\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })\n * );\n *\n * // Opt-in to track error state changes (optimized for error handling)\n * const debouncer = createAsyncDebouncer(\n * async (searchTerm) => {\n * const data = await searchAPI(searchTerm);\n * return data;\n * },\n * {\n * wait: 300,\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 } = debouncer.state();\n * ```\n */\nexport function createAsyncDebouncer<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: SolidAsyncDebouncerOptions<TFn, TSelected>,\n selector: (state: AsyncDebouncerState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncDebouncer<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncDebouncer,\n ...options,\n } as SolidAsyncDebouncerOptions<TFn, TSelected>\n const asyncDebouncer = new AsyncDebouncer<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidAsyncDebouncer<TFn, TSelected>\n\n asyncDebouncer.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: AsyncDebouncerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(asyncDebouncer.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(asyncDebouncer.store, selector, {\n compare: shallow,\n })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(asyncDebouncer)\n } else {\n asyncDebouncer.cancel()\n asyncDebouncer.abort()\n }\n })\n })\n\n return {\n ...asyncDebouncer,\n state,\n } as SolidAsyncDebouncer<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8KA,SAAgB,qBAId,IACA,SACA,kBACG,CAAC,IACiC;CACrC,MAAM,gBAAgB;EACpB,GAAG,uBAAuB,CAAC,CAAC;EAC5B,GAAG;CACL;CACA,MAAM,iBAAiB,IAAI,eACzB,IACA,aACF;CAEA,eAAe,YAAY,SAAS,UAAqB,OAGtD;EACD,MAAM,WAAW,YAAY,eAAe,OAAO,MAAM,UAAU,EACjE,SAAS,QACX,CAAC;EAED,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,QAAQ,IACvB,MAAM;CACZ;CAEA,MAAM,QAAQ,YAAY,eAAe,OAAO,UAAU,EACxD,SAAS,QACX,CAAC;CAED,mBAAmB;EACjB,gBAAgB;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"}
@@ -1,11 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_createAsyncDebouncer = require('./createAsyncDebouncer.cjs');
3
-
4
- exports.createAsyncDebouncer = require_createAsyncDebouncer.createAsyncDebouncer;
5
- var _tanstack_pacer_async_debouncer = require("@tanstack/pacer/async-debouncer");
6
- Object.keys(_tanstack_pacer_async_debouncer).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_debouncer[k]; }
10
- });
11
- });
@@ -1,3 +0,0 @@
1
- import { SolidAsyncDebouncer, SolidAsyncDebouncerOptions, createAsyncDebouncer } from "./createAsyncDebouncer.cjs";
2
- export * from "@tanstack/pacer/async-debouncer";
3
- export { SolidAsyncDebouncer, SolidAsyncDebouncerOptions, createAsyncDebouncer };
@@ -1,158 +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_queuer = require("@tanstack/pacer/async-queuer");
5
-
6
- //#region src/async-queuer/createAsyncQueuer.ts
7
- /**
8
- * Creates a Solid-compatible AsyncQueuer instance for managing an asynchronous queue of items, exposing Solid signals for all stateful properties.
9
- *
10
- * Features:
11
- * - Priority queueing via `getPriority` or item `priority` property
12
- * - Configurable concurrency limit
13
- * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior
14
- * - Pause/resume processing
15
- * - Task cancellation
16
- * - Item expiration
17
- * - Lifecycle callbacks for success, error, settled, items change, etc.
18
- * - All stateful properties (active items, pending items, counts, etc.) are exposed as Solid signals for reactivity
19
- *
20
- * Tasks are processed concurrently up to the configured concurrency limit. When a task completes,
21
- * the next pending task is processed if the concurrency limit allows.
22
- *
23
- * Error Handling:
24
- * - If an `onError` handler is provided, it will be called with the error and queuer instance
25
- * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
26
- * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
27
- * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown
28
- * - The error state can be checked using the underlying AsyncQueuer instance
29
- *
30
- * ## State Management and Selector
31
- *
32
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
33
- * in two ways:
34
- *
35
- * **1. Using `queuer.Subscribe` component (Recommended for component tree subscriptions)**
36
- *
37
- * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
38
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
39
- * in child components.
40
- *
41
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
42
- *
43
- * The `selector` parameter allows you to specify which state changes will trigger reactive updates
44
- * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
45
- * state changes occur.
46
- *
47
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
48
- * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
49
- * updates and gives you full control over when your component tracks state changes.
50
- *
51
- * Available state properties:
52
- * - `activeItems`: Array of items currently being processed
53
- * - `errorCount`: Number of items that failed processing
54
- * - `isRunning`: Whether the queuer is currently running (not stopped)
55
- * - `pendingItems`: Array of items waiting to be processed
56
- * - `rejectionCount`: Number of items that were rejected (expired or failed validation)
57
- * - `settleCount`: Number of items that have completed processing (successful or failed)
58
- * - `successCount`: Number of items that were processed successfully
59
- *
60
- * ## Unmount behavior
61
- *
62
- * By default, the primitive stops the queuer and aborts any in-flight task executions when the owning component unmounts.
63
- * Abort only cancels underlying operations (e.g. fetch) when the abort signal from `getAbortSignal()` is passed to them.
64
- * Use the `onUnmount` option to customize this. For example, to flush pending items instead:
65
- *
66
- * ```tsx
67
- * const queuer = createAsyncQueuer(fn, {
68
- * concurrency: 2,
69
- * started: false,
70
- * onUnmount: (q) => q.flush()
71
- * });
72
- * ```
73
- *
74
- * Note: For async utils, `flush()` returns a Promise and runs fire-and-forget in the cleanup.
75
- * If your task function updates Solid signals, those updates may run after the component has
76
- * unmounted, which can cause unexpected reactive updates. Guard your callbacks accordingly when
77
- * using onUnmount with flush.
78
- *
79
- * Example usage:
80
- * ```tsx
81
- * // Default behavior - no reactive state subscriptions
82
- * const asyncQueuer = createAsyncQueuer(async (item) => {
83
- * // process item
84
- * return await fetchData(item);
85
- * }, {
86
- * initialItems: [],
87
- * concurrency: 2,
88
- * maxSize: 100,
89
- * started: false,
90
- * onSuccess: (result) => {
91
- * console.log('Item processed:', result);
92
- * },
93
- * onError: (error) => {
94
- * console.error('Processing failed:', error);
95
- * }
96
- * });
97
- *
98
- * // Opt-in to track queue state changes (optimized for UI updates)
99
- * const asyncQueuer = createAsyncQueuer(
100
- * async (item) => await fetchData(item),
101
- * { concurrency: 2, started: true },
102
- * (state) => ({
103
- * pendingItems: state.pendingItems,
104
- * activeItems: state.activeItems,
105
- * isRunning: state.isRunning
106
- * })
107
- * );
108
- *
109
- * // Opt-in to track processing metrics changes (optimized for tracking progress)
110
- * const asyncQueuer = createAsyncQueuer(
111
- * async (item) => await fetchData(item),
112
- * { concurrency: 2, started: true },
113
- * (state) => ({
114
- * successCount: state.successCount,
115
- * errorCount: state.errorCount,
116
- * settleCount: state.settleCount
117
- * })
118
- * );
119
- *
120
- * // Add items to queue
121
- * asyncQueuer.addItem(newItem);
122
- *
123
- * // Start processing
124
- * asyncQueuer.start();
125
- *
126
- * // Access the selected state (will be empty object {} unless selector provided)
127
- * const { pendingItems, activeItems } = asyncQueuer.state();
128
- * ```
129
- */
130
- function createAsyncQueuer(fn, options = {}, selector = () => ({})) {
131
- const mergedOptions = {
132
- ...require_PacerProvider.useDefaultPacerOptions().asyncQueuer,
133
- ...options
134
- };
135
- const asyncQueuer = new _tanstack_pacer_async_queuer.AsyncQueuer(fn, mergedOptions);
136
- asyncQueuer.Subscribe = function Subscribe(props) {
137
- const selected = (0, _tanstack_solid_store.useSelector)(asyncQueuer.store, props.selector, { compare: _tanstack_solid_store.shallow });
138
- return typeof props.children === "function" ? props.children(selected) : props.children;
139
- };
140
- const state = (0, _tanstack_solid_store.useSelector)(asyncQueuer.store, selector, { compare: _tanstack_solid_store.shallow });
141
- (0, solid_js.createEffect)(() => {
142
- (0, solid_js.onCleanup)(() => {
143
- if (mergedOptions.onUnmount) mergedOptions.onUnmount(asyncQueuer);
144
- else {
145
- asyncQueuer.stop();
146
- asyncQueuer.abort();
147
- }
148
- });
149
- });
150
- return {
151
- ...asyncQueuer,
152
- state
153
- };
154
- }
155
-
156
- //#endregion
157
- exports.createAsyncQueuer = createAsyncQueuer;
158
- //# sourceMappingURL=createAsyncQueuer.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createAsyncQueuer.cjs","names":["useDefaultPacerOptions","AsyncQueuer","useSelector","shallow"],"sources":["../../src/async-queuer/createAsyncQueuer.ts"],"sourcesContent":["import { AsyncQueuer } from '@tanstack/pacer/async-queuer'\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 {\n AsyncQueuerOptions,\n AsyncQueuerState,\n} from '@tanstack/pacer/async-queuer'\n\nexport interface SolidAsyncQueuerOptions<\n TValue,\n TSelected = {},\n> extends AsyncQueuerOptions<TValue> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop + abort); use it to call flush(), flushAsBatch(), stop(), add logging, etc.\n */\n onUnmount?: (queuer: SolidAsyncQueuer<TValue, TSelected>) => void\n}\n\nexport interface SolidAsyncQueuer<TValue, TSelected = {}> extends Omit<\n AsyncQueuer<TValue>,\n 'store'\n> {\n /**\n * A Solid component that allows you to subscribe to the queuer state.\n *\n * This is useful for tracking specific parts of the queuer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <queuer.Subscribe selector={(state) => ({ pendingItems: state.pendingItems, activeItems: state.activeItems })}>\n * {(state) => (\n * <div>Pending: {state().pendingItems.length}, Active: {state().activeItems.length}</div>\n * )}\n * </queuer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: AsyncQueuerState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `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<AsyncQueuerState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible AsyncQueuer instance for managing an asynchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Priority queueing via `getPriority` or item `priority` property\n * - Configurable concurrency limit\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Pause/resume processing\n * - Task cancellation\n * - Item expiration\n * - Lifecycle callbacks for success, error, settled, items change, etc.\n * - All stateful properties (active items, pending items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * Tasks are processed concurrently up to the configured concurrency limit. When a task completes,\n * the next pending task is processed if the concurrency limit allows.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and queuer 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 AsyncQueuer 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 `queuer.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 * - `activeItems`: Array of items currently being processed\n * - `errorCount`: Number of items that failed processing\n * - `isRunning`: Whether the queuer is currently running (not stopped)\n * - `pendingItems`: Array of items waiting to be processed\n * - `rejectionCount`: Number of items that were rejected (expired or failed validation)\n * - `settleCount`: Number of items that have completed processing (successful or failed)\n * - `successCount`: Number of items that were processed successfully\n *\n * ## Unmount behavior\n *\n * By default, the primitive stops the queuer and aborts any in-flight task executions 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 items instead:\n *\n * ```tsx\n * const queuer = createAsyncQueuer(fn, {\n * concurrency: 2,\n * started: false,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n *\n * Note: For async utils, `flush()` returns a Promise and runs fire-and-forget in the cleanup.\n * If your task 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 usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const asyncQueuer = createAsyncQueuer(async (item) => {\n * // process item\n * return await fetchData(item);\n * }, {\n * initialItems: [],\n * concurrency: 2,\n * maxSize: 100,\n * started: false,\n * onSuccess: (result) => {\n * console.log('Item processed:', result);\n * },\n * onError: (error) => {\n * console.error('Processing failed:', error);\n * }\n * });\n *\n * // Opt-in to track queue state changes (optimized for UI updates)\n * const asyncQueuer = createAsyncQueuer(\n * async (item) => await fetchData(item),\n * { concurrency: 2, started: true },\n * (state) => ({\n * pendingItems: state.pendingItems,\n * activeItems: state.activeItems,\n * isRunning: state.isRunning\n * })\n * );\n *\n * // Opt-in to track processing metrics changes (optimized for tracking progress)\n * const asyncQueuer = createAsyncQueuer(\n * async (item) => await fetchData(item),\n * { concurrency: 2, started: true },\n * (state) => ({\n * successCount: state.successCount,\n * errorCount: state.errorCount,\n * settleCount: state.settleCount\n * })\n * );\n *\n * // Add items to queue\n * asyncQueuer.addItem(newItem);\n *\n * // Start processing\n * asyncQueuer.start();\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { pendingItems, activeItems } = asyncQueuer.state();\n * ```\n */\nexport function createAsyncQueuer<TValue, TSelected = {}>(\n fn: (value: TValue) => Promise<any>,\n options: SolidAsyncQueuerOptions<TValue, TSelected> = {},\n selector: (state: AsyncQueuerState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncQueuer,\n ...options,\n } as SolidAsyncQueuerOptions<TValue, TSelected>\n const asyncQueuer = new AsyncQueuer<TValue>(\n fn,\n mergedOptions,\n ) as unknown as SolidAsyncQueuer<TValue, TSelected>\n\n asyncQueuer.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: AsyncQueuerState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(asyncQueuer.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(asyncQueuer.store, selector, { compare: shallow })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(asyncQueuer)\n } else {\n asyncQueuer.stop()\n asyncQueuer.abort()\n }\n })\n })\n\n return {\n ...asyncQueuer,\n state,\n } as SolidAsyncQueuer<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoLA,SAAgB,kBACd,IACA,UAAsD,CAAC,GACvD,kBACG,CAAC,IACiC;CACrC,MAAM,gBAAgB;EACpB,GAAGA,6CAAuB,CAAC,CAAC;EAC5B,GAAG;CACL;CACA,MAAM,cAAc,IAAIC,yCACtB,IACA,aACF;CAEA,YAAY,YAAY,SAAS,UAAqB,OAGnD;EACD,MAAM,eAAWC,mCAAY,YAAY,OAAO,MAAM,UAAU,EAC9D,SAASC,8BACX,CAAC;EAED,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,QAAQ,IACvB,MAAM;CACZ;CAEA,MAAM,YAAQD,mCAAY,YAAY,OAAO,UAAU,EAAE,SAASC,8BAAQ,CAAC;CAE3E,iCAAmB;EACjB,8BAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,WAAW;QAC9B;IACL,YAAY,KAAK;IACjB,YAAY,MAAM;GACpB;EACF,CAAC;CACH,CAAC;CAED,OAAO;EACL,GAAG;EACH;CACF;AACF"}
@@ -1,169 +0,0 @@
1
- import { Store } from "@tanstack/solid-store";
2
- import { Accessor, JSX } from "solid-js";
3
- import { AsyncQueuer, AsyncQueuerOptions, AsyncQueuerState } from "@tanstack/pacer/async-queuer";
4
- //#region src/async-queuer/createAsyncQueuer.d.ts
5
- interface SolidAsyncQueuerOptions<TValue, TSelected = {}> extends AsyncQueuerOptions<TValue> {
6
- /**
7
- * Optional callback invoked when the owning component unmounts. Receives the queuer instance.
8
- * When provided, replaces the default cleanup (stop + abort); use it to call flush(), flushAsBatch(), stop(), add logging, etc.
9
- */
10
- onUnmount?: (queuer: SolidAsyncQueuer<TValue, TSelected>) => void;
11
- }
12
- interface SolidAsyncQueuer<TValue, TSelected = {}> extends Omit<AsyncQueuer<TValue>, 'store'> {
13
- /**
14
- * A Solid component that allows you to subscribe to the queuer state.
15
- *
16
- * This is useful for tracking specific parts of the queuer state
17
- * deep in your component tree without needing to pass a selector to the hook.
18
- *
19
- * @example
20
- * <queuer.Subscribe selector={(state) => ({ pendingItems: state.pendingItems, activeItems: state.activeItems })}>
21
- * {(state) => (
22
- * <div>Pending: {state().pendingItems.length}, Active: {state().activeItems.length}</div>
23
- * )}
24
- * </queuer.Subscribe>
25
- */
26
- Subscribe: <TSelected>(props: {
27
- selector: (state: AsyncQueuerState<TValue>) => TSelected;
28
- children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
29
- }) => JSX.Element;
30
- /**
31
- * Reactive state that will be updated when the queuer state changes
32
- *
33
- * Use this instead of `queuer.store.state`
34
- */
35
- readonly state: Accessor<Readonly<TSelected>>;
36
- /**
37
- * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.
38
- * The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
39
- * Although, you can make the state reactive by using the `useSelector` in your own usage.
40
- */
41
- readonly store: Store<Readonly<AsyncQueuerState<TValue>>>;
42
- }
43
- /**
44
- * Creates a Solid-compatible AsyncQueuer instance for managing an asynchronous queue of items, exposing Solid signals for all stateful properties.
45
- *
46
- * Features:
47
- * - Priority queueing via `getPriority` or item `priority` property
48
- * - Configurable concurrency limit
49
- * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior
50
- * - Pause/resume processing
51
- * - Task cancellation
52
- * - Item expiration
53
- * - Lifecycle callbacks for success, error, settled, items change, etc.
54
- * - All stateful properties (active items, pending items, counts, etc.) are exposed as Solid signals for reactivity
55
- *
56
- * Tasks are processed concurrently up to the configured concurrency limit. When a task completes,
57
- * the next pending task is processed if the concurrency limit allows.
58
- *
59
- * Error Handling:
60
- * - If an `onError` handler is provided, it will be called with the error and queuer 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 AsyncQueuer 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 `queuer.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
- * - `activeItems`: Array of items currently being processed
89
- * - `errorCount`: Number of items that failed processing
90
- * - `isRunning`: Whether the queuer is currently running (not stopped)
91
- * - `pendingItems`: Array of items waiting to be processed
92
- * - `rejectionCount`: Number of items that were rejected (expired or failed validation)
93
- * - `settleCount`: Number of items that have completed processing (successful or failed)
94
- * - `successCount`: Number of items that were processed successfully
95
- *
96
- * ## Unmount behavior
97
- *
98
- * By default, the primitive stops the queuer and aborts any in-flight task executions when the owning component unmounts.
99
- * Abort only cancels underlying operations (e.g. fetch) when the abort signal from `getAbortSignal()` is passed to them.
100
- * Use the `onUnmount` option to customize this. For example, to flush pending items instead:
101
- *
102
- * ```tsx
103
- * const queuer = createAsyncQueuer(fn, {
104
- * concurrency: 2,
105
- * started: false,
106
- * onUnmount: (q) => q.flush()
107
- * });
108
- * ```
109
- *
110
- * Note: For async utils, `flush()` returns a Promise and runs fire-and-forget in the cleanup.
111
- * If your task function updates Solid signals, those updates may run after the component has
112
- * unmounted, which can cause unexpected reactive updates. Guard your callbacks accordingly when
113
- * using onUnmount with flush.
114
- *
115
- * Example usage:
116
- * ```tsx
117
- * // Default behavior - no reactive state subscriptions
118
- * const asyncQueuer = createAsyncQueuer(async (item) => {
119
- * // process item
120
- * return await fetchData(item);
121
- * }, {
122
- * initialItems: [],
123
- * concurrency: 2,
124
- * maxSize: 100,
125
- * started: false,
126
- * onSuccess: (result) => {
127
- * console.log('Item processed:', result);
128
- * },
129
- * onError: (error) => {
130
- * console.error('Processing failed:', error);
131
- * }
132
- * });
133
- *
134
- * // Opt-in to track queue state changes (optimized for UI updates)
135
- * const asyncQueuer = createAsyncQueuer(
136
- * async (item) => await fetchData(item),
137
- * { concurrency: 2, started: true },
138
- * (state) => ({
139
- * pendingItems: state.pendingItems,
140
- * activeItems: state.activeItems,
141
- * isRunning: state.isRunning
142
- * })
143
- * );
144
- *
145
- * // Opt-in to track processing metrics changes (optimized for tracking progress)
146
- * const asyncQueuer = createAsyncQueuer(
147
- * async (item) => await fetchData(item),
148
- * { concurrency: 2, started: true },
149
- * (state) => ({
150
- * successCount: state.successCount,
151
- * errorCount: state.errorCount,
152
- * settleCount: state.settleCount
153
- * })
154
- * );
155
- *
156
- * // Add items to queue
157
- * asyncQueuer.addItem(newItem);
158
- *
159
- * // Start processing
160
- * asyncQueuer.start();
161
- *
162
- * // Access the selected state (will be empty object {} unless selector provided)
163
- * const { pendingItems, activeItems } = asyncQueuer.state();
164
- * ```
165
- */
166
- declare function createAsyncQueuer<TValue, TSelected = {}>(fn: (value: TValue) => Promise<any>, options?: SolidAsyncQueuerOptions<TValue, TSelected>, selector?: (state: AsyncQueuerState<TValue>) => TSelected): SolidAsyncQueuer<TValue, TSelected>;
167
- //#endregion
168
- export { SolidAsyncQueuer, SolidAsyncQueuerOptions, createAsyncQueuer };
169
- //# sourceMappingURL=createAsyncQueuer.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createAsyncQueuer.js","names":[],"sources":["../../src/async-queuer/createAsyncQueuer.ts"],"sourcesContent":["import { AsyncQueuer } from '@tanstack/pacer/async-queuer'\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 {\n AsyncQueuerOptions,\n AsyncQueuerState,\n} from '@tanstack/pacer/async-queuer'\n\nexport interface SolidAsyncQueuerOptions<\n TValue,\n TSelected = {},\n> extends AsyncQueuerOptions<TValue> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop + abort); use it to call flush(), flushAsBatch(), stop(), add logging, etc.\n */\n onUnmount?: (queuer: SolidAsyncQueuer<TValue, TSelected>) => void\n}\n\nexport interface SolidAsyncQueuer<TValue, TSelected = {}> extends Omit<\n AsyncQueuer<TValue>,\n 'store'\n> {\n /**\n * A Solid component that allows you to subscribe to the queuer state.\n *\n * This is useful for tracking specific parts of the queuer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <queuer.Subscribe selector={(state) => ({ pendingItems: state.pendingItems, activeItems: state.activeItems })}>\n * {(state) => (\n * <div>Pending: {state().pendingItems.length}, Active: {state().activeItems.length}</div>\n * )}\n * </queuer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: AsyncQueuerState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `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<AsyncQueuerState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible AsyncQueuer instance for managing an asynchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Priority queueing via `getPriority` or item `priority` property\n * - Configurable concurrency limit\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Pause/resume processing\n * - Task cancellation\n * - Item expiration\n * - Lifecycle callbacks for success, error, settled, items change, etc.\n * - All stateful properties (active items, pending items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * Tasks are processed concurrently up to the configured concurrency limit. When a task completes,\n * the next pending task is processed if the concurrency limit allows.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and queuer 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 AsyncQueuer 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 `queuer.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 * - `activeItems`: Array of items currently being processed\n * - `errorCount`: Number of items that failed processing\n * - `isRunning`: Whether the queuer is currently running (not stopped)\n * - `pendingItems`: Array of items waiting to be processed\n * - `rejectionCount`: Number of items that were rejected (expired or failed validation)\n * - `settleCount`: Number of items that have completed processing (successful or failed)\n * - `successCount`: Number of items that were processed successfully\n *\n * ## Unmount behavior\n *\n * By default, the primitive stops the queuer and aborts any in-flight task executions 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 items instead:\n *\n * ```tsx\n * const queuer = createAsyncQueuer(fn, {\n * concurrency: 2,\n * started: false,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n *\n * Note: For async utils, `flush()` returns a Promise and runs fire-and-forget in the cleanup.\n * If your task 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 usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const asyncQueuer = createAsyncQueuer(async (item) => {\n * // process item\n * return await fetchData(item);\n * }, {\n * initialItems: [],\n * concurrency: 2,\n * maxSize: 100,\n * started: false,\n * onSuccess: (result) => {\n * console.log('Item processed:', result);\n * },\n * onError: (error) => {\n * console.error('Processing failed:', error);\n * }\n * });\n *\n * // Opt-in to track queue state changes (optimized for UI updates)\n * const asyncQueuer = createAsyncQueuer(\n * async (item) => await fetchData(item),\n * { concurrency: 2, started: true },\n * (state) => ({\n * pendingItems: state.pendingItems,\n * activeItems: state.activeItems,\n * isRunning: state.isRunning\n * })\n * );\n *\n * // Opt-in to track processing metrics changes (optimized for tracking progress)\n * const asyncQueuer = createAsyncQueuer(\n * async (item) => await fetchData(item),\n * { concurrency: 2, started: true },\n * (state) => ({\n * successCount: state.successCount,\n * errorCount: state.errorCount,\n * settleCount: state.settleCount\n * })\n * );\n *\n * // Add items to queue\n * asyncQueuer.addItem(newItem);\n *\n * // Start processing\n * asyncQueuer.start();\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { pendingItems, activeItems } = asyncQueuer.state();\n * ```\n */\nexport function createAsyncQueuer<TValue, TSelected = {}>(\n fn: (value: TValue) => Promise<any>,\n options: SolidAsyncQueuerOptions<TValue, TSelected> = {},\n selector: (state: AsyncQueuerState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncQueuer,\n ...options,\n } as SolidAsyncQueuerOptions<TValue, TSelected>\n const asyncQueuer = new AsyncQueuer<TValue>(\n fn,\n mergedOptions,\n ) as unknown as SolidAsyncQueuer<TValue, TSelected>\n\n asyncQueuer.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: AsyncQueuerState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(asyncQueuer.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(asyncQueuer.store, selector, { compare: shallow })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(asyncQueuer)\n } else {\n asyncQueuer.stop()\n asyncQueuer.abort()\n }\n })\n })\n\n return {\n ...asyncQueuer,\n state,\n } as SolidAsyncQueuer<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoLA,SAAgB,kBACd,IACA,UAAsD,CAAC,GACvD,kBACG,CAAC,IACiC;CACrC,MAAM,gBAAgB;EACpB,GAAG,uBAAuB,CAAC,CAAC;EAC5B,GAAG;CACL;CACA,MAAM,cAAc,IAAI,YACtB,IACA,aACF;CAEA,YAAY,YAAY,SAAS,UAAqB,OAGnD;EACD,MAAM,WAAW,YAAY,YAAY,OAAO,MAAM,UAAU,EAC9D,SAAS,QACX,CAAC;EAED,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,QAAQ,IACvB,MAAM;CACZ;CAEA,MAAM,QAAQ,YAAY,YAAY,OAAO,UAAU,EAAE,SAAS,QAAQ,CAAC;CAE3E,mBAAmB;EACjB,gBAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,WAAW;QAC9B;IACL,YAAY,KAAK;IACjB,YAAY,MAAM;GACpB;EACF,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_createAsyncQueuer = require('./createAsyncQueuer.cjs');
3
-
4
- exports.createAsyncQueuer = require_createAsyncQueuer.createAsyncQueuer;
5
- var _tanstack_pacer_async_queuer = require("@tanstack/pacer/async-queuer");
6
- Object.keys(_tanstack_pacer_async_queuer).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_queuer[k]; }
10
- });
11
- });
@@ -1,3 +0,0 @@
1
- import { SolidAsyncQueuer, SolidAsyncQueuerOptions, createAsyncQueuer } from "./createAsyncQueuer.cjs";
2
- export * from "@tanstack/pacer/async-queuer";
3
- export { SolidAsyncQueuer, SolidAsyncQueuerOptions, createAsyncQueuer };