@tanstack/solid-pacer 0.21.1 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/README.md +21 -6
  2. package/dist/async-batcher/createAsyncBatcher.d.ts +5 -10
  3. package/dist/async-batcher/createAsyncBatcher.js +2 -5
  4. package/dist/async-debouncer/createAsyncDebouncer.d.ts +8 -12
  5. package/dist/async-debouncer/createAsyncDebouncer.js +5 -7
  6. package/dist/async-queuer/createAsyncQueuer.d.ts +9 -12
  7. package/dist/async-queuer/createAsyncQueuer.js +4 -5
  8. package/dist/async-rate-limiter/createAsyncRateLimiter.d.ts +10 -13
  9. package/dist/async-rate-limiter/createAsyncRateLimiter.js +7 -8
  10. package/dist/async-throttler/createAsyncThrottler.d.ts +8 -14
  11. package/dist/async-throttler/createAsyncThrottler.js +5 -9
  12. package/dist/batcher/createBatcher.d.ts +11 -15
  13. package/dist/batcher/createBatcher.js +6 -8
  14. package/dist/debouncer/createDebouncedSignal.d.ts +2 -5
  15. package/dist/debouncer/createDebouncedSignal.js +1 -2
  16. package/dist/debouncer/createDebouncedValue.d.ts +2 -5
  17. package/dist/debouncer/createDebouncedValue.js +1 -2
  18. package/dist/debouncer/createDebouncer.d.ts +4 -7
  19. package/dist/debouncer/createDebouncer.js +1 -2
  20. package/dist/provider/PacerProvider.d.ts +6 -9
  21. package/dist/provider/PacerProvider.js +1 -2
  22. package/dist/queuer/createQueuedSignal.d.ts +2 -5
  23. package/dist/queuer/createQueuedSignal.js +1 -2
  24. package/dist/queuer/createQueuer.d.ts +4 -7
  25. package/dist/queuer/createQueuer.js +1 -2
  26. package/dist/rate-limiter/createRateLimitedSignal.d.ts +12 -14
  27. package/dist/rate-limiter/createRateLimitedSignal.js +11 -11
  28. package/dist/rate-limiter/createRateLimitedValue.d.ts +2 -5
  29. package/dist/rate-limiter/createRateLimitedValue.js +1 -2
  30. package/dist/rate-limiter/createRateLimiter.d.ts +8 -10
  31. package/dist/rate-limiter/createRateLimiter.js +5 -5
  32. package/dist/throttler/createThrottledSignal.d.ts +2 -7
  33. package/dist/throttler/createThrottledSignal.js +1 -4
  34. package/dist/throttler/createThrottledValue.d.ts +2 -7
  35. package/dist/throttler/createThrottledValue.js +1 -4
  36. package/dist/throttler/createThrottler.d.ts +4 -9
  37. package/dist/throttler/createThrottler.js +1 -4
  38. package/package.json +24 -68
  39. package/dist/async-batcher/createAsyncBatcher.cjs +0 -166
  40. package/dist/async-batcher/createAsyncBatcher.cjs.map +0 -1
  41. package/dist/async-batcher/createAsyncBatcher.d.cts +0 -178
  42. package/dist/async-batcher/createAsyncBatcher.js.map +0 -1
  43. package/dist/async-batcher/index.cjs +0 -11
  44. package/dist/async-batcher/index.d.cts +0 -3
  45. package/dist/async-debouncer/createAsyncDebouncer.cjs +0 -151
  46. package/dist/async-debouncer/createAsyncDebouncer.cjs.map +0 -1
  47. package/dist/async-debouncer/createAsyncDebouncer.d.cts +0 -164
  48. package/dist/async-debouncer/createAsyncDebouncer.js.map +0 -1
  49. package/dist/async-debouncer/index.cjs +0 -11
  50. package/dist/async-debouncer/index.d.cts +0 -3
  51. package/dist/async-queuer/createAsyncQueuer.cjs +0 -158
  52. package/dist/async-queuer/createAsyncQueuer.cjs.map +0 -1
  53. package/dist/async-queuer/createAsyncQueuer.d.cts +0 -170
  54. package/dist/async-queuer/createAsyncQueuer.js.map +0 -1
  55. package/dist/async-queuer/index.cjs +0 -11
  56. package/dist/async-queuer/index.d.cts +0 -3
  57. package/dist/async-rate-limiter/createAsyncRateLimiter.cjs +0 -193
  58. package/dist/async-rate-limiter/createAsyncRateLimiter.cjs.map +0 -1
  59. package/dist/async-rate-limiter/createAsyncRateLimiter.d.cts +0 -209
  60. package/dist/async-rate-limiter/createAsyncRateLimiter.js.map +0 -1
  61. package/dist/async-rate-limiter/index.cjs +0 -11
  62. package/dist/async-rate-limiter/index.d.cts +0 -3
  63. package/dist/async-throttler/createAsyncThrottler.cjs +0 -151
  64. package/dist/async-throttler/createAsyncThrottler.cjs.map +0 -1
  65. package/dist/async-throttler/createAsyncThrottler.d.cts +0 -164
  66. package/dist/async-throttler/createAsyncThrottler.js.map +0 -1
  67. package/dist/async-throttler/index.cjs +0 -11
  68. package/dist/async-throttler/index.d.cts +0 -3
  69. package/dist/batcher/createBatcher.cjs +0 -132
  70. package/dist/batcher/createBatcher.cjs.map +0 -1
  71. package/dist/batcher/createBatcher.d.cts +0 -147
  72. package/dist/batcher/createBatcher.js.map +0 -1
  73. package/dist/batcher/index.cjs +0 -11
  74. package/dist/batcher/index.d.cts +0 -3
  75. package/dist/debouncer/createDebouncedSignal.cjs +0 -88
  76. package/dist/debouncer/createDebouncedSignal.cjs.map +0 -1
  77. package/dist/debouncer/createDebouncedSignal.d.cts +0 -80
  78. package/dist/debouncer/createDebouncedSignal.js.map +0 -1
  79. package/dist/debouncer/createDebouncedValue.cjs +0 -77
  80. package/dist/debouncer/createDebouncedValue.cjs.map +0 -1
  81. package/dist/debouncer/createDebouncedValue.d.cts +0 -71
  82. package/dist/debouncer/createDebouncedValue.js.map +0 -1
  83. package/dist/debouncer/createDebouncer.cjs +0 -129
  84. package/dist/debouncer/createDebouncer.cjs.map +0 -1
  85. package/dist/debouncer/createDebouncer.d.cts +0 -145
  86. package/dist/debouncer/createDebouncer.js.map +0 -1
  87. package/dist/debouncer/index.cjs +0 -15
  88. package/dist/debouncer/index.d.cts +0 -5
  89. package/dist/index.cjs +0 -47
  90. package/dist/index.d.cts +0 -20
  91. package/dist/provider/PacerProvider.cjs +0 -27
  92. package/dist/provider/PacerProvider.cjs.map +0 -1
  93. package/dist/provider/PacerProvider.d.cts +0 -29
  94. package/dist/provider/PacerProvider.js.map +0 -1
  95. package/dist/provider/index.cjs +0 -6
  96. package/dist/provider/index.d.cts +0 -2
  97. package/dist/queuer/createQueuedSignal.cjs +0 -129
  98. package/dist/queuer/createQueuedSignal.cjs.map +0 -1
  99. package/dist/queuer/createQueuedSignal.d.cts +0 -122
  100. package/dist/queuer/createQueuedSignal.js.map +0 -1
  101. package/dist/queuer/createQueuer.cjs +0 -133
  102. package/dist/queuer/createQueuer.cjs.map +0 -1
  103. package/dist/queuer/createQueuer.d.cts +0 -148
  104. package/dist/queuer/createQueuer.js.map +0 -1
  105. package/dist/queuer/index.cjs +0 -13
  106. package/dist/queuer/index.d.cts +0 -4
  107. package/dist/rate-limiter/createRateLimitedSignal.cjs +0 -102
  108. package/dist/rate-limiter/createRateLimitedSignal.cjs.map +0 -1
  109. package/dist/rate-limiter/createRateLimitedSignal.d.cts +0 -94
  110. package/dist/rate-limiter/createRateLimitedSignal.js.map +0 -1
  111. package/dist/rate-limiter/createRateLimitedValue.cjs +0 -102
  112. package/dist/rate-limiter/createRateLimitedValue.cjs.map +0 -1
  113. package/dist/rate-limiter/createRateLimitedValue.d.cts +0 -96
  114. package/dist/rate-limiter/createRateLimitedValue.js.map +0 -1
  115. package/dist/rate-limiter/createRateLimiter.cjs +0 -157
  116. package/dist/rate-limiter/createRateLimiter.cjs.map +0 -1
  117. package/dist/rate-limiter/createRateLimiter.d.cts +0 -174
  118. package/dist/rate-limiter/createRateLimiter.js.map +0 -1
  119. package/dist/rate-limiter/index.cjs +0 -15
  120. package/dist/rate-limiter/index.d.cts +0 -5
  121. package/dist/throttler/createThrottledSignal.cjs +0 -79
  122. package/dist/throttler/createThrottledSignal.cjs.map +0 -1
  123. package/dist/throttler/createThrottledSignal.d.cts +0 -71
  124. package/dist/throttler/createThrottledSignal.js.map +0 -1
  125. package/dist/throttler/createThrottledValue.cjs +0 -74
  126. package/dist/throttler/createThrottledValue.cjs.map +0 -1
  127. package/dist/throttler/createThrottledValue.d.cts +0 -68
  128. package/dist/throttler/createThrottledValue.js.map +0 -1
  129. package/dist/throttler/createThrottler.cjs +0 -132
  130. package/dist/throttler/createThrottler.cjs.map +0 -1
  131. package/dist/throttler/createThrottler.d.cts +0 -148
  132. package/dist/throttler/createThrottler.js.map +0 -1
  133. package/dist/throttler/index.cjs +0 -15
  134. package/dist/throttler/index.d.cts +0 -5
  135. package/dist/types/index.cjs +0 -9
  136. package/dist/types/index.d.cts +0 -1
  137. package/dist/utils/index.cjs +0 -9
  138. package/dist/utils/index.d.cts +0 -1
  139. package/src/async-batcher/createAsyncBatcher.ts +0 -234
  140. package/src/async-batcher/index.ts +0 -3
  141. package/src/async-debouncer/createAsyncDebouncer.ts +0 -225
  142. package/src/async-debouncer/index.ts +0 -4
  143. package/src/async-queuer/createAsyncQueuer.ts +0 -226
  144. package/src/async-queuer/index.ts +0 -3
  145. package/src/async-rate-limiter/createAsyncRateLimiter.ts +0 -269
  146. package/src/async-rate-limiter/index.ts +0 -4
  147. package/src/async-throttler/createAsyncThrottler.ts +0 -225
  148. package/src/async-throttler/index.ts +0 -4
  149. package/src/batcher/createBatcher.ts +0 -199
  150. package/src/batcher/index.ts +0 -3
  151. package/src/debouncer/createDebouncedSignal.ts +0 -92
  152. package/src/debouncer/createDebouncedValue.ts +0 -85
  153. package/src/debouncer/createDebouncer.ts +0 -201
  154. package/src/debouncer/index.ts +0 -6
  155. package/src/index.ts +0 -46
  156. package/src/provider/PacerProvider.tsx +0 -63
  157. package/src/provider/index.ts +0 -1
  158. package/src/queuer/createQueuedSignal.ts +0 -138
  159. package/src/queuer/createQueuer.ts +0 -199
  160. package/src/queuer/index.ts +0 -4
  161. package/src/rate-limiter/createRateLimitedSignal.ts +0 -117
  162. package/src/rate-limiter/createRateLimitedValue.ts +0 -110
  163. package/src/rate-limiter/createRateLimiter.ts +0 -226
  164. package/src/rate-limiter/index.ts +0 -5
  165. package/src/throttler/createThrottledSignal.ts +0 -81
  166. package/src/throttler/createThrottledValue.ts +0 -82
  167. package/src/throttler/createThrottler.ts +0 -204
  168. package/src/throttler/index.ts +0 -6
  169. package/src/types/index.ts +0 -1
  170. package/src/utils/index.ts +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/solid-pacer",
3
- "version": "0.21.1",
3
+ "version": "0.23.0",
4
4
  "description": "Utilities for debouncing and throttling functions in Solid.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -23,83 +23,38 @@
23
23
  "async"
24
24
  ],
25
25
  "type": "module",
26
- "main": "./dist/index.cjs",
27
- "module": "./dist/index.js",
28
- "types": "./dist/index.d.cts",
26
+ "types": "./dist/index.d.ts",
29
27
  "exports": {
30
- ".": {
31
- "import": "./dist/index.js",
32
- "require": "./dist/index.cjs"
33
- },
34
- "./async-batcher": {
35
- "import": "./dist/async-batcher/index.js",
36
- "require": "./dist/async-batcher/index.cjs"
37
- },
38
- "./async-debouncer": {
39
- "import": "./dist/async-debouncer/index.js",
40
- "require": "./dist/async-debouncer/index.cjs"
41
- },
42
- "./async-queuer": {
43
- "import": "./dist/async-queuer/index.js",
44
- "require": "./dist/async-queuer/index.cjs"
45
- },
46
- "./async-rate-limiter": {
47
- "import": "./dist/async-rate-limiter/index.js",
48
- "require": "./dist/async-rate-limiter/index.cjs"
49
- },
50
- "./async-throttler": {
51
- "import": "./dist/async-throttler/index.js",
52
- "require": "./dist/async-throttler/index.cjs"
53
- },
54
- "./batcher": {
55
- "import": "./dist/batcher/index.js",
56
- "require": "./dist/batcher/index.cjs"
57
- },
58
- "./debouncer": {
59
- "import": "./dist/debouncer/index.js",
60
- "require": "./dist/debouncer/index.cjs"
61
- },
62
- "./provider": {
63
- "import": "./dist/provider/index.js",
64
- "require": "./dist/provider/index.cjs"
65
- },
66
- "./queuer": {
67
- "import": "./dist/queuer/index.js",
68
- "require": "./dist/queuer/index.cjs"
69
- },
70
- "./rate-limiter": {
71
- "import": "./dist/rate-limiter/index.js",
72
- "require": "./dist/rate-limiter/index.cjs"
73
- },
74
- "./throttler": {
75
- "import": "./dist/throttler/index.js",
76
- "require": "./dist/throttler/index.cjs"
77
- },
78
- "./types": {
79
- "import": "./dist/types/index.js",
80
- "require": "./dist/types/index.cjs"
81
- },
82
- "./utils": {
83
- "import": "./dist/utils/index.js",
84
- "require": "./dist/utils/index.cjs"
85
- },
28
+ ".": "./dist/index.js",
29
+ "./async-batcher": "./dist/async-batcher/index.js",
30
+ "./async-debouncer": "./dist/async-debouncer/index.js",
31
+ "./async-queuer": "./dist/async-queuer/index.js",
32
+ "./async-rate-limiter": "./dist/async-rate-limiter/index.js",
33
+ "./async-throttler": "./dist/async-throttler/index.js",
34
+ "./batcher": "./dist/batcher/index.js",
35
+ "./debouncer": "./dist/debouncer/index.js",
36
+ "./provider": "./dist/provider/index.js",
37
+ "./queuer": "./dist/queuer/index.js",
38
+ "./rate-limiter": "./dist/rate-limiter/index.js",
39
+ "./throttler": "./dist/throttler/index.js",
40
+ "./types": "./dist/types/index.js",
41
+ "./utils": "./dist/utils/index.js",
86
42
  "./package.json": "./package.json"
87
43
  },
88
44
  "sideEffects": false,
89
45
  "engines": {
90
- "node": ">=18"
46
+ "node": ">=20"
91
47
  },
92
48
  "files": [
93
- "dist",
94
- "src"
49
+ "dist"
95
50
  ],
96
51
  "dependencies": {
97
- "@tanstack/solid-store": "^0.11.0",
98
- "@tanstack/pacer": "0.21.1"
52
+ "@tanstack/pacer": "0.23.0",
53
+ "@tanstack/solid-store": "^0.11.1"
99
54
  },
100
55
  "devDependencies": {
101
- "solid-js": "^1.9.12",
102
- "vite-plugin-solid": "^2.11.12"
56
+ "solid-js": "^1.9.15",
57
+ "vite-plugin-solid": "^2.11.14"
103
58
  },
104
59
  "peerDependencies": {
105
60
  "solid-js": ">=1.9.5"
@@ -111,6 +66,7 @@
111
66
  "test:lib": "vitest --passWithNoTests",
112
67
  "test:lib:dev": "pnpm test:lib --watch",
113
68
  "test:types": "tsc",
114
- "build": "tsdown"
69
+ "build": "tsdown",
70
+ "test:build": "publint --strict && node ../../scripts/verify-package.ts"
115
71
  }
116
72
  }
@@ -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","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,EAAE,EACzD,kBACG,EAAE,GACiC;CACtC,MAAM,gBAAgB;EACpB,GAAGA,8CAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,eAAe,IAAIC,2CACvB,IACA,cACD;CAED,aAAa,YAAY,SAAS,UAAqB,OAGpD;EACD,MAAM,kDAAuB,aAAa,OAAO,MAAM,UAAU,EAC/D,SAASC,+BACV,CAAC;EAEF,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,+CAAoB,aAAa,OAAO,UAAU,EAAE,SAASA,+BAAS,CAAC;CAE7E,iCAAmB;EACjB,8BAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,aAAa;QAChC;IACL,aAAa,QAAQ;IACrB,aAAa,OAAO;;IAEtB;GACF;CAEF,OAAO;EACL,GAAG;EACH;EACD"}
@@ -1,178 +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
-
5
- //#region src/async-batcher/createAsyncBatcher.d.ts
6
- interface SolidAsyncBatcherOptions<TValue, TSelected = {}> extends AsyncBatcherOptions<TValue> {
7
- /**
8
- * Optional callback invoked when the owning component unmounts. Receives the batcher instance.
9
- * When provided, replaces the default cleanup (cancel + abort); use it to call flush(), reset(), cancel(), add logging, etc.
10
- */
11
- onUnmount?: (batcher: SolidAsyncBatcher<TValue, TSelected>) => void;
12
- }
13
- interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBatcher<TValue>, 'store'> {
14
- /**
15
- * A Solid component that allows you to subscribe to the batcher state.
16
- *
17
- * This is useful for tracking specific parts of the batcher state
18
- * deep in your component tree without needing to pass a selector to the hook.
19
- *
20
- * @example
21
- * <batcher.Subscribe selector={(state) => ({ size: state.size, isExecuting: state.isExecuting })}>
22
- * {(state) => (
23
- * <div>Batch: {state().size} items, {state().isExecuting ? 'Executing...' : 'Idle'}</div>
24
- * )}
25
- * </batcher.Subscribe>
26
- */
27
- Subscribe: <TSelected>(props: {
28
- selector: (state: AsyncBatcherState<TValue>) => TSelected;
29
- children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
30
- }) => JSX.Element;
31
- /**
32
- * Reactive state that will be updated when the batcher state changes
33
- *
34
- * Use this instead of `batcher.store.state`
35
- */
36
- readonly state: Accessor<Readonly<TSelected>>;
37
- /**
38
- * @deprecated Use `batcher.state` instead of `batcher.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<AsyncBatcherState<TValue>>>;
43
- }
44
- /**
45
- * Creates a Solid-compatible AsyncBatcher instance for managing asynchronous batches of items, exposing Solid signals for all stateful properties.
46
- *
47
- * This is the async version of the createBatcher hook. Unlike the sync version, this async batcher:
48
- * - Handles promises and returns results from batch executions
49
- * - Provides error handling with configurable error behavior
50
- * - Tracks success, error, and settle counts separately
51
- * - Has state tracking for when batches are executing
52
- * - Returns the result of the batch function execution
53
- *
54
- * Features:
55
- * - Configurable batch size and wait time
56
- * - Custom batch processing logic via getShouldExecute
57
- * - Event callbacks for monitoring batch operations
58
- * - Error handling for failed batch operations
59
- * - Automatic or manual batch processing
60
- * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity
61
- *
62
- * The batcher collects items and processes them in batches based on:
63
- * - Maximum batch size (number of items per batch)
64
- * - Time-based batching (process after X milliseconds)
65
- * - Custom batch processing logic via getShouldExecute
66
- *
67
- * Error Handling:
68
- * - If an `onError` handler is provided, it will be called with the error and batcher instance
69
- * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
70
- * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
71
- * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown
72
- * - The error state can be checked using the underlying AsyncBatcher instance
73
- *
74
- * ## State Management and Selector
75
- *
76
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
77
- * in two ways:
78
- *
79
- * **1. Using `batcher.Subscribe` component (Recommended for component tree subscriptions)**
80
- *
81
- * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
82
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
83
- * in child components.
84
- *
85
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
86
- *
87
- * The `selector` parameter allows you to specify which state changes will trigger reactive updates
88
- * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
89
- * state changes occur.
90
- *
91
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
92
- * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
93
- * updates and gives you full control over when your component tracks state changes.
94
- *
95
- * Available state properties:
96
- * - `errorCount`: Number of failed batch executions
97
- * - `executionCount`: Total number of batch execution attempts (successful + failed)
98
- * - `hasError`: Whether the last batch execution resulted in an error
99
- * - `isExecuting`: Whether a batch execution is currently in progress
100
- * - `items`: Array of items currently queued for batching
101
- * - `lastError`: The error from the most recent failed batch execution (if any)
102
- * - `lastResult`: The result from the most recent successful batch execution
103
- * - `settleCount`: Number of batch executions that have completed (successful or failed)
104
- * - `successCount`: Number of successful batch executions
105
- *
106
- * ## Unmount behavior
107
- *
108
- * By default, the primitive cancels any pending batch and aborts any in-flight execution when the owning component unmounts.
109
- * Abort only cancels underlying operations (e.g. fetch) when the abort signal from `getAbortSignal()` is passed to them.
110
- * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
111
- *
112
- * ```tsx
113
- * const batcher = createAsyncBatcher(fn, {
114
- * maxSize: 10,
115
- * wait: 2000,
116
- * onUnmount: (b) => b.flush()
117
- * });
118
- * ```
119
- *
120
- * Note: For async utils, `flush()` returns a Promise and runs fire-and-forget in the cleanup.
121
- * If your batch function updates Solid signals, those updates may run after the component has
122
- * unmounted, which can cause unexpected reactive updates. Guard your callbacks accordingly when
123
- * using onUnmount with flush.
124
- *
125
- * Example usage:
126
- * ```tsx
127
- * // Default behavior - no reactive state subscriptions
128
- * const asyncBatcher = createAsyncBatcher(
129
- * async (items) => {
130
- * const results = await Promise.all(items.map(item => processItem(item)));
131
- * return results;
132
- * },
133
- * {
134
- * maxSize: 10,
135
- * wait: 2000,
136
- * onSuccess: (result) => {
137
- * console.log('Batch processed successfully:', result);
138
- * },
139
- * onError: (error) => {
140
- * console.error('Batch processing failed:', error);
141
- * }
142
- * }
143
- * );
144
- *
145
- * // Opt-in to track items or isExecuting changes (optimized for UI updates)
146
- * const asyncBatcher = createAsyncBatcher(
147
- * async (items) => {
148
- * const results = await Promise.all(items.map(item => processItem(item)));
149
- * return results;
150
- * },
151
- * { maxSize: 10, wait: 2000 },
152
- * (state) => ({ items: state.items, isExecuting: state.isExecuting })
153
- * );
154
- *
155
- * // Opt-in to track error state changes (optimized for error handling)
156
- * const asyncBatcher = createAsyncBatcher(
157
- * async (items) => {
158
- * const results = await Promise.all(items.map(item => processItem(item)));
159
- * return results;
160
- * },
161
- * { maxSize: 10, wait: 2000 },
162
- * (state) => ({ hasError: state.hasError, lastError: state.lastError })
163
- * );
164
- *
165
- * // Add items to batch
166
- * asyncBatcher.addItem(newItem);
167
- *
168
- * // Manually execute batch
169
- * const result = await asyncBatcher.execute();
170
- *
171
- * // Access the selected state (will be empty object {} unless selector provided)
172
- * const { items, isExecuting } = asyncBatcher.state();
173
- * ```
174
- */
175
- declare function createAsyncBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => Promise<any>, options?: SolidAsyncBatcherOptions<TValue, TSelected>, selector?: (state: AsyncBatcherState<TValue>) => TSelected): SolidAsyncBatcher<TValue, TSelected>;
176
- //#endregion
177
- export { SolidAsyncBatcher, SolidAsyncBatcherOptions, createAsyncBatcher };
178
- //# 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,EAAE,EACzD,kBACG,EAAE,GACiC;CACtC,MAAM,gBAAgB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,eAAe,IAAI,aACvB,IACA,cACD;CAED,aAAa,YAAY,SAAS,UAAqB,OAGpD;EACD,MAAM,WAAW,YAAY,aAAa,OAAO,MAAM,UAAU,EAC/D,SAAS,SACV,CAAC;EAEF,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,QAAQ,YAAY,aAAa,OAAO,UAAU,EAAE,SAAS,SAAS,CAAC;CAE7E,mBAAmB;EACjB,gBAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,aAAa;QAChC;IACL,aAAa,QAAQ;IACrB,aAAa,OAAO;;IAEtB;GACF;CAEF,OAAO;EACL,GAAG;EACH;EACD"}
@@ -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 };