@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,166 +0,0 @@
1
- const require_PacerProvider = require('../provider/PacerProvider.cjs');
2
- let solid_js = require("solid-js");
3
- let _tanstack_pacer_async_batcher = require("@tanstack/pacer/async-batcher");
4
- let _tanstack_solid_store = require("@tanstack/solid-store");
5
-
6
- //#region src/async-batcher/createAsyncBatcher.ts
7
- /**
8
- * Creates a Solid-compatible AsyncBatcher instance for managing asynchronous batches of items, exposing Solid signals for all stateful properties.
9
- *
10
- * This is the async version of the createBatcher hook. Unlike the sync version, this async batcher:
11
- * - Handles promises and returns results from batch executions
12
- * - Provides error handling with configurable error behavior
13
- * - Tracks success, error, and settle counts separately
14
- * - Has state tracking for when batches are executing
15
- * - Returns the result of the batch function execution
16
- *
17
- * Features:
18
- * - Configurable batch size and wait time
19
- * - Custom batch processing logic via getShouldExecute
20
- * - Event callbacks for monitoring batch operations
21
- * - Error handling for failed batch operations
22
- * - Automatic or manual batch processing
23
- * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity
24
- *
25
- * The batcher collects items and processes them in batches based on:
26
- * - Maximum batch size (number of items per batch)
27
- * - Time-based batching (process after X milliseconds)
28
- * - Custom batch processing logic via getShouldExecute
29
- *
30
- * Error Handling:
31
- * - If an `onError` handler is provided, it will be called with the error and batcher instance
32
- * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
33
- * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
34
- * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown
35
- * - The error state can be checked using the underlying AsyncBatcher instance
36
- *
37
- * ## State Management and Selector
38
- *
39
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
40
- * in two ways:
41
- *
42
- * **1. Using `batcher.Subscribe` component (Recommended for component tree subscriptions)**
43
- *
44
- * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
45
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
46
- * in child components.
47
- *
48
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
49
- *
50
- * The `selector` parameter allows you to specify which state changes will trigger reactive updates
51
- * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
52
- * state changes occur.
53
- *
54
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
55
- * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
56
- * updates and gives you full control over when your component tracks state changes.
57
- *
58
- * Available state properties:
59
- * - `errorCount`: Number of failed batch executions
60
- * - `executionCount`: Total number of batch execution attempts (successful + failed)
61
- * - `hasError`: Whether the last batch execution resulted in an error
62
- * - `isExecuting`: Whether a batch execution is currently in progress
63
- * - `items`: Array of items currently queued for batching
64
- * - `lastError`: The error from the most recent failed batch execution (if any)
65
- * - `lastResult`: The result from the most recent successful batch execution
66
- * - `settleCount`: Number of batch executions that have completed (successful or failed)
67
- * - `successCount`: Number of successful batch executions
68
- *
69
- * ## Unmount behavior
70
- *
71
- * By default, the primitive cancels any pending batch and aborts any in-flight execution when the owning component unmounts.
72
- * Abort only cancels underlying operations (e.g. fetch) when the abort signal from `getAbortSignal()` is passed to them.
73
- * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
74
- *
75
- * ```tsx
76
- * const batcher = createAsyncBatcher(fn, {
77
- * maxSize: 10,
78
- * wait: 2000,
79
- * onUnmount: (b) => b.flush()
80
- * });
81
- * ```
82
- *
83
- * Note: For async utils, `flush()` returns a Promise and runs fire-and-forget in the cleanup.
84
- * If your batch function updates Solid signals, those updates may run after the component has
85
- * unmounted, which can cause unexpected reactive updates. Guard your callbacks accordingly when
86
- * using onUnmount with flush.
87
- *
88
- * Example usage:
89
- * ```tsx
90
- * // Default behavior - no reactive state subscriptions
91
- * const asyncBatcher = createAsyncBatcher(
92
- * async (items) => {
93
- * const results = await Promise.all(items.map(item => processItem(item)));
94
- * return results;
95
- * },
96
- * {
97
- * maxSize: 10,
98
- * wait: 2000,
99
- * onSuccess: (result) => {
100
- * console.log('Batch processed successfully:', result);
101
- * },
102
- * onError: (error) => {
103
- * console.error('Batch processing failed:', error);
104
- * }
105
- * }
106
- * );
107
- *
108
- * // Opt-in to track items or isExecuting changes (optimized for UI updates)
109
- * const asyncBatcher = createAsyncBatcher(
110
- * async (items) => {
111
- * const results = await Promise.all(items.map(item => processItem(item)));
112
- * return results;
113
- * },
114
- * { maxSize: 10, wait: 2000 },
115
- * (state) => ({ items: state.items, isExecuting: state.isExecuting })
116
- * );
117
- *
118
- * // Opt-in to track error state changes (optimized for error handling)
119
- * const asyncBatcher = createAsyncBatcher(
120
- * async (items) => {
121
- * const results = await Promise.all(items.map(item => processItem(item)));
122
- * return results;
123
- * },
124
- * { maxSize: 10, wait: 2000 },
125
- * (state) => ({ hasError: state.hasError, lastError: state.lastError })
126
- * );
127
- *
128
- * // Add items to batch
129
- * asyncBatcher.addItem(newItem);
130
- *
131
- * // Manually execute batch
132
- * const result = await asyncBatcher.execute();
133
- *
134
- * // Access the selected state (will be empty object {} unless selector provided)
135
- * const { items, isExecuting } = asyncBatcher.state();
136
- * ```
137
- */
138
- function createAsyncBatcher(fn, options = {}, selector = () => ({})) {
139
- const mergedOptions = {
140
- ...require_PacerProvider.useDefaultPacerOptions().asyncBatcher,
141
- ...options
142
- };
143
- const asyncBatcher = new _tanstack_pacer_async_batcher.AsyncBatcher(fn, mergedOptions);
144
- asyncBatcher.Subscribe = function Subscribe(props) {
145
- const selected = (0, _tanstack_solid_store.useSelector)(asyncBatcher.store, props.selector, { compare: _tanstack_solid_store.shallow });
146
- return typeof props.children === "function" ? props.children(selected) : props.children;
147
- };
148
- const state = (0, _tanstack_solid_store.useSelector)(asyncBatcher.store, selector, { compare: _tanstack_solid_store.shallow });
149
- (0, solid_js.createEffect)(() => {
150
- (0, solid_js.onCleanup)(() => {
151
- if (mergedOptions.onUnmount) mergedOptions.onUnmount(asyncBatcher);
152
- else {
153
- asyncBatcher.cancel();
154
- asyncBatcher.abort();
155
- }
156
- });
157
- });
158
- return {
159
- ...asyncBatcher,
160
- state
161
- };
162
- }
163
-
164
- //#endregion
165
- exports.createAsyncBatcher = createAsyncBatcher;
166
- //# sourceMappingURL=createAsyncBatcher.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createAsyncBatcher.cjs","names":["useDefaultPacerOptions","AsyncBatcher","useSelector","shallow"],"sources":["../../src/async-batcher/createAsyncBatcher.ts"],"sourcesContent":["import { AsyncBatcher } from '@tanstack/pacer/async-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 {\n AsyncBatcherOptions,\n AsyncBatcherState,\n} from '@tanstack/pacer/async-batcher'\n\nexport interface SolidAsyncBatcherOptions<\n TValue,\n TSelected = {},\n> extends AsyncBatcherOptions<TValue> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the batcher instance.\n * When provided, replaces the default cleanup (cancel + abort); use it to call flush(), reset(), cancel(), add logging, etc.\n */\n onUnmount?: (batcher: SolidAsyncBatcher<TValue, TSelected>) => void\n}\n\nexport interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<\n AsyncBatcher<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, isExecuting: state.isExecuting })}>\n * {(state) => (\n * <div>Batch: {state().size} items, {state().isExecuting ? 'Executing...' : 'Idle'}</div>\n * )}\n * </batcher.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: AsyncBatcherState<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<AsyncBatcherState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible AsyncBatcher instance for managing asynchronous batches of items, exposing Solid signals for all stateful properties.\n *\n * This is the async version of the createBatcher hook. Unlike the sync version, this async batcher:\n * - Handles promises and returns results from batch executions\n * - Provides error handling with configurable error behavior\n * - Tracks success, error, and settle counts separately\n * - Has state tracking for when batches are executing\n * - Returns the result of the batch function execution\n *\n * Features:\n * - Configurable batch size and wait time\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\n * - Error handling for failed batch operations\n * - Automatic or manual batch processing\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 (number of items per batch)\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and batcher 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 AsyncBatcher 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 `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 * - `errorCount`: Number of failed batch executions\n * - `executionCount`: Total number of batch execution attempts (successful + failed)\n * - `hasError`: Whether the last batch execution resulted in an error\n * - `isExecuting`: Whether a batch execution is currently in progress\n * - `items`: Array of items currently queued for batching\n * - `lastError`: The error from the most recent failed batch execution (if any)\n * - `lastResult`: The result from the most recent successful batch execution\n * - `settleCount`: Number of batch executions that have completed (successful or failed)\n * - `successCount`: Number of successful batch executions\n *\n * ## Unmount behavior\n *\n * By default, the primitive cancels any pending batch 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 batcher = createAsyncBatcher(fn, {\n * maxSize: 10,\n * wait: 2000,\n * onUnmount: (b) => b.flush()\n * });\n * ```\n *\n * Note: For async utils, `flush()` returns a Promise and runs fire-and-forget in the cleanup.\n * If your batch 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 asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * {\n * maxSize: 10,\n * wait: 2000,\n * onSuccess: (result) => {\n * console.log('Batch processed successfully:', result);\n * },\n * onError: (error) => {\n * console.error('Batch processing failed:', error);\n * }\n * }\n * );\n *\n * // Opt-in to track items or isExecuting changes (optimized for UI updates)\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * { maxSize: 10, wait: 2000 },\n * (state) => ({ items: state.items, isExecuting: state.isExecuting })\n * );\n *\n * // Opt-in to track error state changes (optimized for error handling)\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * { maxSize: 10, wait: 2000 },\n * (state) => ({ hasError: state.hasError, lastError: state.lastError })\n * );\n *\n * // Add items to batch\n * asyncBatcher.addItem(newItem);\n *\n * // Manually execute batch\n * const result = await asyncBatcher.execute();\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isExecuting } = asyncBatcher.state();\n * ```\n */\nexport function createAsyncBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => Promise<any>,\n options: SolidAsyncBatcherOptions<TValue, TSelected> = {},\n selector: (state: AsyncBatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncBatcher,\n ...options,\n } as SolidAsyncBatcherOptions<TValue, TSelected>\n const asyncBatcher = new AsyncBatcher<TValue>(\n fn,\n mergedOptions,\n ) as unknown as SolidAsyncBatcher<TValue, TSelected>\n\n asyncBatcher.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: AsyncBatcherState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(asyncBatcher.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(asyncBatcher.store, selector, { compare: shallow })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(asyncBatcher)\n } else {\n asyncBatcher.cancel()\n asyncBatcher.abort()\n }\n })\n })\n\n return {\n ...asyncBatcher,\n state,\n } as SolidAsyncBatcher<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4LA,SAAgB,mBACd,IACA,UAAuD,CAAC,GACxD,kBACG,CAAC,IACkC;CACtC,MAAM,gBAAgB;EACpB,GAAGA,6CAAuB,CAAC,CAAC;EAC5B,GAAG;CACL;CACA,MAAM,eAAe,IAAIC,2CACvB,IACA,aACF;CAEA,aAAa,YAAY,SAAS,UAAqB,OAGpD;EACD,MAAM,eAAWC,mCAAY,aAAa,OAAO,MAAM,UAAU,EAC/D,SAASC,8BACX,CAAC;EAED,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,QAAQ,IACvB,MAAM;CACZ;CAEA,MAAM,YAAQD,mCAAY,aAAa,OAAO,UAAU,EAAE,SAASC,8BAAQ,CAAC;CAE5E,iCAAmB;EACjB,8BAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,YAAY;QAC/B;IACL,aAAa,OAAO;IACpB,aAAa,MAAM;GACrB;EACF,CAAC;CACH,CAAC;CAED,OAAO;EACL,GAAG;EACH;CACF;AACF"}
@@ -1,177 +0,0 @@
1
- import { AsyncBatcher, AsyncBatcherOptions, AsyncBatcherState } from "@tanstack/pacer/async-batcher";
2
- import { Store } from "@tanstack/solid-store";
3
- import { Accessor, JSX } from "solid-js";
4
- //#region src/async-batcher/createAsyncBatcher.d.ts
5
- interface SolidAsyncBatcherOptions<TValue, TSelected = {}> extends AsyncBatcherOptions<TValue> {
6
- /**
7
- * Optional callback invoked when the owning component unmounts. Receives the batcher instance.
8
- * When provided, replaces the default cleanup (cancel + abort); use it to call flush(), reset(), cancel(), add logging, etc.
9
- */
10
- onUnmount?: (batcher: SolidAsyncBatcher<TValue, TSelected>) => void;
11
- }
12
- interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBatcher<TValue>, 'store'> {
13
- /**
14
- * A Solid component that allows you to subscribe to the batcher state.
15
- *
16
- * This is useful for tracking specific parts of the batcher state
17
- * deep in your component tree without needing to pass a selector to the hook.
18
- *
19
- * @example
20
- * <batcher.Subscribe selector={(state) => ({ size: state.size, isExecuting: state.isExecuting })}>
21
- * {(state) => (
22
- * <div>Batch: {state().size} items, {state().isExecuting ? 'Executing...' : 'Idle'}</div>
23
- * )}
24
- * </batcher.Subscribe>
25
- */
26
- Subscribe: <TSelected>(props: {
27
- selector: (state: AsyncBatcherState<TValue>) => TSelected;
28
- children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
29
- }) => JSX.Element;
30
- /**
31
- * Reactive state that will be updated when the batcher state changes
32
- *
33
- * Use this instead of `batcher.store.state`
34
- */
35
- readonly state: Accessor<Readonly<TSelected>>;
36
- /**
37
- * @deprecated Use `batcher.state` instead of `batcher.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<AsyncBatcherState<TValue>>>;
42
- }
43
- /**
44
- * Creates a Solid-compatible AsyncBatcher instance for managing asynchronous batches of items, exposing Solid signals for all stateful properties.
45
- *
46
- * This is the async version of the createBatcher hook. Unlike the sync version, this async batcher:
47
- * - Handles promises and returns results from batch executions
48
- * - Provides error handling with configurable error behavior
49
- * - Tracks success, error, and settle counts separately
50
- * - Has state tracking for when batches are executing
51
- * - Returns the result of the batch function execution
52
- *
53
- * Features:
54
- * - Configurable batch size and wait time
55
- * - Custom batch processing logic via getShouldExecute
56
- * - Event callbacks for monitoring batch operations
57
- * - Error handling for failed batch operations
58
- * - Automatic or manual batch processing
59
- * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity
60
- *
61
- * The batcher collects items and processes them in batches based on:
62
- * - Maximum batch size (number of items per batch)
63
- * - Time-based batching (process after X milliseconds)
64
- * - Custom batch processing logic via getShouldExecute
65
- *
66
- * Error Handling:
67
- * - If an `onError` handler is provided, it will be called with the error and batcher instance
68
- * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
69
- * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
70
- * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown
71
- * - The error state can be checked using the underlying AsyncBatcher instance
72
- *
73
- * ## State Management and Selector
74
- *
75
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
76
- * in two ways:
77
- *
78
- * **1. Using `batcher.Subscribe` component (Recommended for component tree subscriptions)**
79
- *
80
- * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
81
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
82
- * in child components.
83
- *
84
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
85
- *
86
- * The `selector` parameter allows you to specify which state changes will trigger reactive updates
87
- * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
88
- * state changes occur.
89
- *
90
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
91
- * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
92
- * updates and gives you full control over when your component tracks state changes.
93
- *
94
- * Available state properties:
95
- * - `errorCount`: Number of failed batch executions
96
- * - `executionCount`: Total number of batch execution attempts (successful + failed)
97
- * - `hasError`: Whether the last batch execution resulted in an error
98
- * - `isExecuting`: Whether a batch execution is currently in progress
99
- * - `items`: Array of items currently queued for batching
100
- * - `lastError`: The error from the most recent failed batch execution (if any)
101
- * - `lastResult`: The result from the most recent successful batch execution
102
- * - `settleCount`: Number of batch executions that have completed (successful or failed)
103
- * - `successCount`: Number of successful batch executions
104
- *
105
- * ## Unmount behavior
106
- *
107
- * By default, the primitive cancels any pending batch and aborts any in-flight execution when the owning component unmounts.
108
- * Abort only cancels underlying operations (e.g. fetch) when the abort signal from `getAbortSignal()` is passed to them.
109
- * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
110
- *
111
- * ```tsx
112
- * const batcher = createAsyncBatcher(fn, {
113
- * maxSize: 10,
114
- * wait: 2000,
115
- * onUnmount: (b) => b.flush()
116
- * });
117
- * ```
118
- *
119
- * Note: For async utils, `flush()` returns a Promise and runs fire-and-forget in the cleanup.
120
- * If your batch function updates Solid signals, those updates may run after the component has
121
- * unmounted, which can cause unexpected reactive updates. Guard your callbacks accordingly when
122
- * using onUnmount with flush.
123
- *
124
- * Example usage:
125
- * ```tsx
126
- * // Default behavior - no reactive state subscriptions
127
- * const asyncBatcher = createAsyncBatcher(
128
- * async (items) => {
129
- * const results = await Promise.all(items.map(item => processItem(item)));
130
- * return results;
131
- * },
132
- * {
133
- * maxSize: 10,
134
- * wait: 2000,
135
- * onSuccess: (result) => {
136
- * console.log('Batch processed successfully:', result);
137
- * },
138
- * onError: (error) => {
139
- * console.error('Batch processing failed:', error);
140
- * }
141
- * }
142
- * );
143
- *
144
- * // Opt-in to track items or isExecuting changes (optimized for UI updates)
145
- * const asyncBatcher = createAsyncBatcher(
146
- * async (items) => {
147
- * const results = await Promise.all(items.map(item => processItem(item)));
148
- * return results;
149
- * },
150
- * { maxSize: 10, wait: 2000 },
151
- * (state) => ({ items: state.items, isExecuting: state.isExecuting })
152
- * );
153
- *
154
- * // Opt-in to track error state changes (optimized for error handling)
155
- * const asyncBatcher = createAsyncBatcher(
156
- * async (items) => {
157
- * const results = await Promise.all(items.map(item => processItem(item)));
158
- * return results;
159
- * },
160
- * { maxSize: 10, wait: 2000 },
161
- * (state) => ({ hasError: state.hasError, lastError: state.lastError })
162
- * );
163
- *
164
- * // Add items to batch
165
- * asyncBatcher.addItem(newItem);
166
- *
167
- * // Manually execute batch
168
- * const result = await asyncBatcher.execute();
169
- *
170
- * // Access the selected state (will be empty object {} unless selector provided)
171
- * const { items, isExecuting } = asyncBatcher.state();
172
- * ```
173
- */
174
- declare function createAsyncBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => Promise<any>, options?: SolidAsyncBatcherOptions<TValue, TSelected>, selector?: (state: AsyncBatcherState<TValue>) => TSelected): SolidAsyncBatcher<TValue, TSelected>;
175
- //#endregion
176
- export { SolidAsyncBatcher, SolidAsyncBatcherOptions, createAsyncBatcher };
177
- //# sourceMappingURL=createAsyncBatcher.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createAsyncBatcher.js","names":[],"sources":["../../src/async-batcher/createAsyncBatcher.ts"],"sourcesContent":["import { AsyncBatcher } from '@tanstack/pacer/async-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 {\n AsyncBatcherOptions,\n AsyncBatcherState,\n} from '@tanstack/pacer/async-batcher'\n\nexport interface SolidAsyncBatcherOptions<\n TValue,\n TSelected = {},\n> extends AsyncBatcherOptions<TValue> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the batcher instance.\n * When provided, replaces the default cleanup (cancel + abort); use it to call flush(), reset(), cancel(), add logging, etc.\n */\n onUnmount?: (batcher: SolidAsyncBatcher<TValue, TSelected>) => void\n}\n\nexport interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<\n AsyncBatcher<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, isExecuting: state.isExecuting })}>\n * {(state) => (\n * <div>Batch: {state().size} items, {state().isExecuting ? 'Executing...' : 'Idle'}</div>\n * )}\n * </batcher.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: AsyncBatcherState<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<AsyncBatcherState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible AsyncBatcher instance for managing asynchronous batches of items, exposing Solid signals for all stateful properties.\n *\n * This is the async version of the createBatcher hook. Unlike the sync version, this async batcher:\n * - Handles promises and returns results from batch executions\n * - Provides error handling with configurable error behavior\n * - Tracks success, error, and settle counts separately\n * - Has state tracking for when batches are executing\n * - Returns the result of the batch function execution\n *\n * Features:\n * - Configurable batch size and wait time\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\n * - Error handling for failed batch operations\n * - Automatic or manual batch processing\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 (number of items per batch)\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and batcher 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 AsyncBatcher 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 `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 * - `errorCount`: Number of failed batch executions\n * - `executionCount`: Total number of batch execution attempts (successful + failed)\n * - `hasError`: Whether the last batch execution resulted in an error\n * - `isExecuting`: Whether a batch execution is currently in progress\n * - `items`: Array of items currently queued for batching\n * - `lastError`: The error from the most recent failed batch execution (if any)\n * - `lastResult`: The result from the most recent successful batch execution\n * - `settleCount`: Number of batch executions that have completed (successful or failed)\n * - `successCount`: Number of successful batch executions\n *\n * ## Unmount behavior\n *\n * By default, the primitive cancels any pending batch 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 batcher = createAsyncBatcher(fn, {\n * maxSize: 10,\n * wait: 2000,\n * onUnmount: (b) => b.flush()\n * });\n * ```\n *\n * Note: For async utils, `flush()` returns a Promise and runs fire-and-forget in the cleanup.\n * If your batch 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 asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * {\n * maxSize: 10,\n * wait: 2000,\n * onSuccess: (result) => {\n * console.log('Batch processed successfully:', result);\n * },\n * onError: (error) => {\n * console.error('Batch processing failed:', error);\n * }\n * }\n * );\n *\n * // Opt-in to track items or isExecuting changes (optimized for UI updates)\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * { maxSize: 10, wait: 2000 },\n * (state) => ({ items: state.items, isExecuting: state.isExecuting })\n * );\n *\n * // Opt-in to track error state changes (optimized for error handling)\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * { maxSize: 10, wait: 2000 },\n * (state) => ({ hasError: state.hasError, lastError: state.lastError })\n * );\n *\n * // Add items to batch\n * asyncBatcher.addItem(newItem);\n *\n * // Manually execute batch\n * const result = await asyncBatcher.execute();\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isExecuting } = asyncBatcher.state();\n * ```\n */\nexport function createAsyncBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => Promise<any>,\n options: SolidAsyncBatcherOptions<TValue, TSelected> = {},\n selector: (state: AsyncBatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncBatcher,\n ...options,\n } as SolidAsyncBatcherOptions<TValue, TSelected>\n const asyncBatcher = new AsyncBatcher<TValue>(\n fn,\n mergedOptions,\n ) as unknown as SolidAsyncBatcher<TValue, TSelected>\n\n asyncBatcher.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: AsyncBatcherState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(asyncBatcher.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(asyncBatcher.store, selector, { compare: shallow })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(asyncBatcher)\n } else {\n asyncBatcher.cancel()\n asyncBatcher.abort()\n }\n })\n })\n\n return {\n ...asyncBatcher,\n state,\n } as SolidAsyncBatcher<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4LA,SAAgB,mBACd,IACA,UAAuD,CAAC,GACxD,kBACG,CAAC,IACkC;CACtC,MAAM,gBAAgB;EACpB,GAAG,uBAAuB,CAAC,CAAC;EAC5B,GAAG;CACL;CACA,MAAM,eAAe,IAAI,aACvB,IACA,aACF;CAEA,aAAa,YAAY,SAAS,UAAqB,OAGpD;EACD,MAAM,WAAW,YAAY,aAAa,OAAO,MAAM,UAAU,EAC/D,SAAS,QACX,CAAC;EAED,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,QAAQ,IACvB,MAAM;CACZ;CAEA,MAAM,QAAQ,YAAY,aAAa,OAAO,UAAU,EAAE,SAAS,QAAQ,CAAC;CAE5E,mBAAmB;EACjB,gBAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,YAAY;QAC/B;IACL,aAAa,OAAO;IACpB,aAAa,MAAM;GACrB;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_createAsyncBatcher = require('./createAsyncBatcher.cjs');
3
-
4
- exports.createAsyncBatcher = require_createAsyncBatcher.createAsyncBatcher;
5
- var _tanstack_pacer_async_batcher = require("@tanstack/pacer/async-batcher");
6
- Object.keys(_tanstack_pacer_async_batcher).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_batcher[k]; }
10
- });
11
- });
@@ -1,3 +0,0 @@
1
- import { SolidAsyncBatcher, SolidAsyncBatcherOptions, createAsyncBatcher } from "./createAsyncBatcher.cjs";
2
- export * from "@tanstack/pacer/async-batcher";
3
- export { SolidAsyncBatcher, SolidAsyncBatcherOptions, createAsyncBatcher };
@@ -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_debouncer = require("@tanstack/pacer/async-debouncer");
5
-
6
- //#region src/async-debouncer/createAsyncDebouncer.ts
7
- /**
8
- * A low-level Solid hook that creates an `AsyncDebouncer` instance to delay execution of an async function.
9
- *
10
- * This hook is designed to be flexible and state-management agnostic - it simply returns a debouncer instance that
11
- * you can integrate with any state management solution (createSignal, etc).
12
- *
13
- * Async debouncing ensures that an async function only executes after a specified delay has passed since its last invocation.
14
- * Each new invocation resets the delay timer. This is useful for handling frequent events like window resizing
15
- * or input changes where you only want to execute the handler after the events have stopped occurring.
16
- *
17
- * Unlike throttling which allows execution at regular intervals, debouncing prevents any execution until
18
- * the function stops being called for the specified delay period.
19
- *
20
- * Unlike the non-async Debouncer, this async version supports returning values from the debounced function,
21
- * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call
22
- * instead of setting the result on a state variable from within the debounced function.
23
- *
24
- * Error Handling:
25
- * - If an `onError` handler is provided, it will be called with the error and debouncer instance
26
- * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
27
- * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
28
- * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown
29
- * - The error state can be checked using the underlying AsyncDebouncer instance
30
- *
31
- * ## State Management and Selector
32
- *
33
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
34
- * in two ways:
35
- *
36
- * **1. Using `debouncer.Subscribe` component (Recommended for component tree subscriptions)**
37
- *
38
- * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
39
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
40
- * in child components.
41
- *
42
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
43
- *
44
- * The `selector` parameter allows you to specify which state changes will trigger reactive updates
45
- * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
46
- * state changes occur.
47
- *
48
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
49
- * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
50
- * updates and gives you full control over when your component tracks state changes.
51
- *
52
- * Available state properties:
53
- * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
54
- * - `executionCount`: Number of function executions that have been completed
55
- * - `hasError`: Whether the last execution resulted in an error
56
- * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
57
- * - `isExecuting`: Whether an async function execution is currently in progress
58
- * - `lastArgs`: The arguments from the most recent call to maybeExecute
59
- * - `lastError`: The error from the most recent failed execution (if any)
60
- * - `lastResult`: The result from the most recent successful 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 debouncer = createAsyncDebouncer(fn, {
71
- * wait: 500,
72
- * onUnmount: (d) => d.flush()
73
- * });
74
- * ```
75
- *
76
- * Note: For async utils, `flush()` returns a Promise and runs fire-and-forget in the cleanup.
77
- * If your debounced 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 } = createAsyncDebouncer(
85
- * async (query: string) => {
86
- * const results = await api.search(query);
87
- * return results;
88
- * },
89
- * { wait: 500 }
90
- * );
91
- *
92
- * // Opt-in to track isPending or isExecuting changes (optimized for loading states)
93
- * const debouncer = createAsyncDebouncer(
94
- * async (query: string) => {
95
- * const results = await api.search(query);
96
- * return results;
97
- * },
98
- * { wait: 500 },
99
- * (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })
100
- * );
101
- *
102
- * // Opt-in to track error state changes (optimized for error handling)
103
- * const debouncer = createAsyncDebouncer(
104
- * async (searchTerm) => {
105
- * const data = await searchAPI(searchTerm);
106
- * return data;
107
- * },
108
- * {
109
- * wait: 300,
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 } = debouncer.state();
121
- * ```
122
- */
123
- function createAsyncDebouncer(fn, options, selector = () => ({})) {
124
- const mergedOptions = {
125
- ...require_PacerProvider.useDefaultPacerOptions().asyncDebouncer,
126
- ...options
127
- };
128
- const asyncDebouncer = new _tanstack_pacer_async_debouncer.AsyncDebouncer(fn, mergedOptions);
129
- asyncDebouncer.Subscribe = function Subscribe(props) {
130
- const selected = (0, _tanstack_solid_store.useSelector)(asyncDebouncer.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)(asyncDebouncer.store, selector, { compare: _tanstack_solid_store.shallow });
134
- (0, solid_js.createEffect)(() => {
135
- (0, solid_js.onCleanup)(() => {
136
- if (mergedOptions.onUnmount) mergedOptions.onUnmount(asyncDebouncer);
137
- else {
138
- asyncDebouncer.cancel();
139
- asyncDebouncer.abort();
140
- }
141
- });
142
- });
143
- return {
144
- ...asyncDebouncer,
145
- state
146
- };
147
- }
148
-
149
- //#endregion
150
- exports.createAsyncDebouncer = createAsyncDebouncer;
151
- //# sourceMappingURL=createAsyncDebouncer.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createAsyncDebouncer.cjs","names":["useDefaultPacerOptions","AsyncDebouncer","useSelector","shallow"],"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,GAAGA,6CAAuB,CAAC,CAAC;EAC5B,GAAG;CACL;CACA,MAAM,iBAAiB,IAAIC,+CACzB,IACA,aACF;CAEA,eAAe,YAAY,SAAS,UAAqB,OAGtD;EACD,MAAM,eAAWC,mCAAY,eAAe,OAAO,MAAM,UAAU,EACjE,SAASC,8BACX,CAAC;EAED,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,QAAQ,IACvB,MAAM;CACZ;CAEA,MAAM,YAAQD,mCAAY,eAAe,OAAO,UAAU,EACxD,SAASC,8BACX,CAAC;CAED,iCAAmB;EACjB,8BAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,cAAc;QACjC;IACL,eAAe,OAAO;IACtB,eAAe,MAAM;GACvB;EACF,CAAC;CACH,CAAC;CAED,OAAO;EACL,GAAG;EACH;CACF;AACF"}