@tanstack/solid-pacer 0.21.1 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/README.md +21 -6
  2. package/dist/async-batcher/createAsyncBatcher.d.ts +5 -10
  3. package/dist/async-batcher/createAsyncBatcher.js +2 -5
  4. package/dist/async-debouncer/createAsyncDebouncer.d.ts +8 -12
  5. package/dist/async-debouncer/createAsyncDebouncer.js +5 -7
  6. package/dist/async-queuer/createAsyncQueuer.d.ts +9 -12
  7. package/dist/async-queuer/createAsyncQueuer.js +4 -5
  8. package/dist/async-rate-limiter/createAsyncRateLimiter.d.ts +10 -13
  9. package/dist/async-rate-limiter/createAsyncRateLimiter.js +7 -8
  10. package/dist/async-throttler/createAsyncThrottler.d.ts +8 -14
  11. package/dist/async-throttler/createAsyncThrottler.js +5 -9
  12. package/dist/batcher/createBatcher.d.ts +11 -15
  13. package/dist/batcher/createBatcher.js +6 -8
  14. package/dist/debouncer/createDebouncedSignal.d.ts +2 -5
  15. package/dist/debouncer/createDebouncedSignal.js +1 -2
  16. package/dist/debouncer/createDebouncedValue.d.ts +2 -5
  17. package/dist/debouncer/createDebouncedValue.js +1 -2
  18. package/dist/debouncer/createDebouncer.d.ts +4 -7
  19. package/dist/debouncer/createDebouncer.js +1 -2
  20. package/dist/provider/PacerProvider.d.ts +6 -9
  21. package/dist/provider/PacerProvider.js +1 -2
  22. package/dist/queuer/createQueuedSignal.d.ts +2 -5
  23. package/dist/queuer/createQueuedSignal.js +1 -2
  24. package/dist/queuer/createQueuer.d.ts +4 -7
  25. package/dist/queuer/createQueuer.js +1 -2
  26. package/dist/rate-limiter/createRateLimitedSignal.d.ts +12 -14
  27. package/dist/rate-limiter/createRateLimitedSignal.js +11 -11
  28. package/dist/rate-limiter/createRateLimitedValue.d.ts +2 -5
  29. package/dist/rate-limiter/createRateLimitedValue.js +1 -2
  30. package/dist/rate-limiter/createRateLimiter.d.ts +8 -10
  31. package/dist/rate-limiter/createRateLimiter.js +5 -5
  32. package/dist/throttler/createThrottledSignal.d.ts +2 -7
  33. package/dist/throttler/createThrottledSignal.js +1 -4
  34. package/dist/throttler/createThrottledValue.d.ts +2 -7
  35. package/dist/throttler/createThrottledValue.js +1 -4
  36. package/dist/throttler/createThrottler.d.ts +4 -9
  37. package/dist/throttler/createThrottler.js +1 -4
  38. package/package.json +24 -68
  39. package/dist/async-batcher/createAsyncBatcher.cjs +0 -166
  40. package/dist/async-batcher/createAsyncBatcher.cjs.map +0 -1
  41. package/dist/async-batcher/createAsyncBatcher.d.cts +0 -178
  42. package/dist/async-batcher/createAsyncBatcher.js.map +0 -1
  43. package/dist/async-batcher/index.cjs +0 -11
  44. package/dist/async-batcher/index.d.cts +0 -3
  45. package/dist/async-debouncer/createAsyncDebouncer.cjs +0 -151
  46. package/dist/async-debouncer/createAsyncDebouncer.cjs.map +0 -1
  47. package/dist/async-debouncer/createAsyncDebouncer.d.cts +0 -164
  48. package/dist/async-debouncer/createAsyncDebouncer.js.map +0 -1
  49. package/dist/async-debouncer/index.cjs +0 -11
  50. package/dist/async-debouncer/index.d.cts +0 -3
  51. package/dist/async-queuer/createAsyncQueuer.cjs +0 -158
  52. package/dist/async-queuer/createAsyncQueuer.cjs.map +0 -1
  53. package/dist/async-queuer/createAsyncQueuer.d.cts +0 -170
  54. package/dist/async-queuer/createAsyncQueuer.js.map +0 -1
  55. package/dist/async-queuer/index.cjs +0 -11
  56. package/dist/async-queuer/index.d.cts +0 -3
  57. package/dist/async-rate-limiter/createAsyncRateLimiter.cjs +0 -193
  58. package/dist/async-rate-limiter/createAsyncRateLimiter.cjs.map +0 -1
  59. package/dist/async-rate-limiter/createAsyncRateLimiter.d.cts +0 -209
  60. package/dist/async-rate-limiter/createAsyncRateLimiter.js.map +0 -1
  61. package/dist/async-rate-limiter/index.cjs +0 -11
  62. package/dist/async-rate-limiter/index.d.cts +0 -3
  63. package/dist/async-throttler/createAsyncThrottler.cjs +0 -151
  64. package/dist/async-throttler/createAsyncThrottler.cjs.map +0 -1
  65. package/dist/async-throttler/createAsyncThrottler.d.cts +0 -164
  66. package/dist/async-throttler/createAsyncThrottler.js.map +0 -1
  67. package/dist/async-throttler/index.cjs +0 -11
  68. package/dist/async-throttler/index.d.cts +0 -3
  69. package/dist/batcher/createBatcher.cjs +0 -132
  70. package/dist/batcher/createBatcher.cjs.map +0 -1
  71. package/dist/batcher/createBatcher.d.cts +0 -147
  72. package/dist/batcher/createBatcher.js.map +0 -1
  73. package/dist/batcher/index.cjs +0 -11
  74. package/dist/batcher/index.d.cts +0 -3
  75. package/dist/debouncer/createDebouncedSignal.cjs +0 -88
  76. package/dist/debouncer/createDebouncedSignal.cjs.map +0 -1
  77. package/dist/debouncer/createDebouncedSignal.d.cts +0 -80
  78. package/dist/debouncer/createDebouncedSignal.js.map +0 -1
  79. package/dist/debouncer/createDebouncedValue.cjs +0 -77
  80. package/dist/debouncer/createDebouncedValue.cjs.map +0 -1
  81. package/dist/debouncer/createDebouncedValue.d.cts +0 -71
  82. package/dist/debouncer/createDebouncedValue.js.map +0 -1
  83. package/dist/debouncer/createDebouncer.cjs +0 -129
  84. package/dist/debouncer/createDebouncer.cjs.map +0 -1
  85. package/dist/debouncer/createDebouncer.d.cts +0 -145
  86. package/dist/debouncer/createDebouncer.js.map +0 -1
  87. package/dist/debouncer/index.cjs +0 -15
  88. package/dist/debouncer/index.d.cts +0 -5
  89. package/dist/index.cjs +0 -47
  90. package/dist/index.d.cts +0 -20
  91. package/dist/provider/PacerProvider.cjs +0 -27
  92. package/dist/provider/PacerProvider.cjs.map +0 -1
  93. package/dist/provider/PacerProvider.d.cts +0 -29
  94. package/dist/provider/PacerProvider.js.map +0 -1
  95. package/dist/provider/index.cjs +0 -6
  96. package/dist/provider/index.d.cts +0 -2
  97. package/dist/queuer/createQueuedSignal.cjs +0 -129
  98. package/dist/queuer/createQueuedSignal.cjs.map +0 -1
  99. package/dist/queuer/createQueuedSignal.d.cts +0 -122
  100. package/dist/queuer/createQueuedSignal.js.map +0 -1
  101. package/dist/queuer/createQueuer.cjs +0 -133
  102. package/dist/queuer/createQueuer.cjs.map +0 -1
  103. package/dist/queuer/createQueuer.d.cts +0 -148
  104. package/dist/queuer/createQueuer.js.map +0 -1
  105. package/dist/queuer/index.cjs +0 -13
  106. package/dist/queuer/index.d.cts +0 -4
  107. package/dist/rate-limiter/createRateLimitedSignal.cjs +0 -102
  108. package/dist/rate-limiter/createRateLimitedSignal.cjs.map +0 -1
  109. package/dist/rate-limiter/createRateLimitedSignal.d.cts +0 -94
  110. package/dist/rate-limiter/createRateLimitedSignal.js.map +0 -1
  111. package/dist/rate-limiter/createRateLimitedValue.cjs +0 -102
  112. package/dist/rate-limiter/createRateLimitedValue.cjs.map +0 -1
  113. package/dist/rate-limiter/createRateLimitedValue.d.cts +0 -96
  114. package/dist/rate-limiter/createRateLimitedValue.js.map +0 -1
  115. package/dist/rate-limiter/createRateLimiter.cjs +0 -157
  116. package/dist/rate-limiter/createRateLimiter.cjs.map +0 -1
  117. package/dist/rate-limiter/createRateLimiter.d.cts +0 -174
  118. package/dist/rate-limiter/createRateLimiter.js.map +0 -1
  119. package/dist/rate-limiter/index.cjs +0 -15
  120. package/dist/rate-limiter/index.d.cts +0 -5
  121. package/dist/throttler/createThrottledSignal.cjs +0 -79
  122. package/dist/throttler/createThrottledSignal.cjs.map +0 -1
  123. package/dist/throttler/createThrottledSignal.d.cts +0 -71
  124. package/dist/throttler/createThrottledSignal.js.map +0 -1
  125. package/dist/throttler/createThrottledValue.cjs +0 -74
  126. package/dist/throttler/createThrottledValue.cjs.map +0 -1
  127. package/dist/throttler/createThrottledValue.d.cts +0 -68
  128. package/dist/throttler/createThrottledValue.js.map +0 -1
  129. package/dist/throttler/createThrottler.cjs +0 -132
  130. package/dist/throttler/createThrottler.cjs.map +0 -1
  131. package/dist/throttler/createThrottler.d.cts +0 -148
  132. package/dist/throttler/createThrottler.js.map +0 -1
  133. package/dist/throttler/index.cjs +0 -15
  134. package/dist/throttler/index.d.cts +0 -5
  135. package/dist/types/index.cjs +0 -9
  136. package/dist/types/index.d.cts +0 -1
  137. package/dist/utils/index.cjs +0 -9
  138. package/dist/utils/index.d.cts +0 -1
  139. package/src/async-batcher/createAsyncBatcher.ts +0 -234
  140. package/src/async-batcher/index.ts +0 -3
  141. package/src/async-debouncer/createAsyncDebouncer.ts +0 -225
  142. package/src/async-debouncer/index.ts +0 -4
  143. package/src/async-queuer/createAsyncQueuer.ts +0 -226
  144. package/src/async-queuer/index.ts +0 -3
  145. package/src/async-rate-limiter/createAsyncRateLimiter.ts +0 -269
  146. package/src/async-rate-limiter/index.ts +0 -4
  147. package/src/async-throttler/createAsyncThrottler.ts +0 -225
  148. package/src/async-throttler/index.ts +0 -4
  149. package/src/batcher/createBatcher.ts +0 -199
  150. package/src/batcher/index.ts +0 -3
  151. package/src/debouncer/createDebouncedSignal.ts +0 -92
  152. package/src/debouncer/createDebouncedValue.ts +0 -85
  153. package/src/debouncer/createDebouncer.ts +0 -201
  154. package/src/debouncer/index.ts +0 -6
  155. package/src/index.ts +0 -46
  156. package/src/provider/PacerProvider.tsx +0 -63
  157. package/src/provider/index.ts +0 -1
  158. package/src/queuer/createQueuedSignal.ts +0 -138
  159. package/src/queuer/createQueuer.ts +0 -199
  160. package/src/queuer/index.ts +0 -4
  161. package/src/rate-limiter/createRateLimitedSignal.ts +0 -117
  162. package/src/rate-limiter/createRateLimitedValue.ts +0 -110
  163. package/src/rate-limiter/createRateLimiter.ts +0 -226
  164. package/src/rate-limiter/index.ts +0 -5
  165. package/src/throttler/createThrottledSignal.ts +0 -81
  166. package/src/throttler/createThrottledValue.ts +0 -82
  167. package/src/throttler/createThrottler.ts +0 -204
  168. package/src/throttler/index.ts +0 -6
  169. package/src/types/index.ts +0 -1
  170. package/src/utils/index.ts +0 -1
@@ -1,122 +0,0 @@
1
- import { SolidQueuer, SolidQueuerOptions } from "./createQueuer.cjs";
2
- import { QueuerState } from "@tanstack/pacer/queuer";
3
-
4
- //#region src/queuer/createQueuedSignal.d.ts
5
- /**
6
- * A Solid primitive that creates a queuer with managed state, combining Solid's signals with queuing functionality.
7
- * This primitive provides both the current queue state and queue control methods.
8
- *
9
- * The queue state is automatically updated whenever items are added, removed, or reordered in the queue.
10
- * All queue operations are reflected in the state array returned by the primitive.
11
- *
12
- * The queue can be started and stopped to automatically process items at a specified interval,
13
- * making it useful as a scheduler. When started, it will process one item per tick, with an
14
- * optional wait time between ticks.
15
- *
16
- * The primitive returns a tuple containing:
17
- * - The current queue state as an array
18
- * - The queue instance with methods for queue manipulation
19
- *
20
- * ## State Management and Selector
21
- *
22
- * The primitive uses Solid's reactive state management via the underlying queuer instance.
23
- * The `selector` parameter allows you to specify which queuer state changes will trigger reactive updates,
24
- * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
25
- *
26
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
27
- * tracking by providing a selector function. This prevents unnecessary updates and gives you
28
- * full control over when your component tracks state changes. Only when you provide a selector will the
29
- * component track changes to the selected state values.
30
- *
31
- * Available queuer state properties:
32
- * - `executionCount`: Number of items that have been processed by the queuer
33
- * - `expirationCount`: Number of items that have been removed due to expiration
34
- * - `isEmpty`: Whether the queuer has no items to process
35
- * - `isFull`: Whether the queuer has reached its maximum capacity
36
- * - `isIdle`: Whether the queuer is not currently processing any items
37
- * - `isRunning`: Whether the queuer is active and will process items automatically
38
- * - `items`: Array of items currently waiting to be processed
39
- * - `itemTimestamps`: Timestamps when items were added for expiration tracking
40
- * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item
41
- * - `rejectionCount`: Number of items that have been rejected from being added
42
- * - `size`: Number of items currently in the queue
43
- * - `status`: Current processing status ('idle' | 'running' | 'stopped')
44
- *
45
- * @example
46
- * ```tsx
47
- * // Default behavior - no reactive state subscriptions
48
- * const [items, addItem, queue] = createQueuedSignal(
49
- * (item) => console.log('Processing:', item),
50
- * {
51
- * initialItems: ['item1', 'item2'],
52
- * started: true,
53
- * wait: 1000,
54
- * getPriority: (item) => item.priority
55
- * }
56
- * );
57
- *
58
- * // Opt-in to track queue contents changes (optimized for displaying queue items)
59
- * const [items, addItem, queue] = createQueuedSignal(
60
- * (item) => console.log('Processing:', item),
61
- * { started: true, wait: 1000 },
62
- * (state) => ({
63
- * items: state.items,
64
- * size: state.size,
65
- * isEmpty: state.isEmpty
66
- * })
67
- * );
68
- *
69
- * // Opt-in to track processing state changes (optimized for loading indicators)
70
- * const [items, addItem, queue] = createQueuedSignal(
71
- * (item) => console.log('Processing:', item),
72
- * { started: true, wait: 1000 },
73
- * (state) => ({
74
- * isRunning: state.isRunning,
75
- * isIdle: state.isIdle,
76
- * status: state.status,
77
- * pendingTick: state.pendingTick
78
- * })
79
- * );
80
- *
81
- * // Opt-in to track execution metrics changes (optimized for stats display)
82
- * const [items, addItem, queue] = createQueuedSignal(
83
- * (item) => console.log('Processing:', item),
84
- * { started: true, wait: 1000 },
85
- * (state) => ({
86
- * executionCount: state.executionCount,
87
- * expirationCount: state.expirationCount,
88
- * rejectionCount: state.rejectionCount
89
- * })
90
- * );
91
- *
92
- * // Add items to queue
93
- * const handleAdd = (item) => {
94
- * addItem(item);
95
- * };
96
- *
97
- * // Start automatic processing
98
- * const startProcessing = () => {
99
- * queue.start();
100
- * };
101
- *
102
- * // Stop automatic processing
103
- * const stopProcessing = () => {
104
- * queue.stop();
105
- * };
106
- *
107
- * // Manual processing still available
108
- * const handleProcess = () => {
109
- * const nextItem = queue.getNextItem();
110
- * if (nextItem) {
111
- * processItem(nextItem);
112
- * }
113
- * };
114
- *
115
- * // Access the selected queuer state (will be empty object {} unless selector provided)
116
- * const { size, isRunning, executionCount } = queue.state;
117
- * ```
118
- */
119
- declare function createQueuedSignal<TValue, TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<QueuerState<TValue>, 'items'>>(fn: (item: TValue) => void, options?: SolidQueuerOptions<TValue, TSelected>, selector?: (state: QueuerState<TValue>) => TSelected): [() => Array<TValue>, SolidQueuer<TValue, TSelected>['addItem'], SolidQueuer<TValue, TSelected>];
120
- //#endregion
121
- export { createQueuedSignal };
122
- //# sourceMappingURL=createQueuedSignal.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createQueuedSignal.js","names":[],"sources":["../../src/queuer/createQueuedSignal.ts"],"sourcesContent":["import { createQueuer } from './createQueuer'\nimport type { SolidQueuer, SolidQueuerOptions } from './createQueuer'\nimport type { QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * A Solid primitive that creates a queuer with managed state, combining Solid's signals with queuing functionality.\n * This primitive provides both the current queue state and queue control methods.\n *\n * The queue state is automatically updated whenever items are added, removed, or reordered in the queue.\n * All queue operations are reflected in the state array returned by the primitive.\n *\n * The queue can be started and stopped to automatically process items at a specified interval,\n * making it useful as a scheduler. When started, it will process one item per tick, with an\n * optional wait time between ticks.\n *\n * The primitive returns a tuple containing:\n * - The current queue state as an array\n * - The queue instance with methods for queue manipulation\n *\n * ## State Management and Selector\n *\n * The primitive uses Solid's reactive state management via the underlying queuer instance.\n * The `selector` parameter allows you to specify which queuer state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary updates when irrelevant 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. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes. Only when you provide a selector will the\n * component track changes to the selected state values.\n *\n * Available queuer state properties:\n * - `executionCount`: Number of items that have been processed by the queuer\n * - `expirationCount`: Number of items that have been removed due to expiration\n * - `isEmpty`: Whether the queuer has no items to process\n * - `isFull`: Whether the queuer has reached its maximum capacity\n * - `isIdle`: Whether the queuer is not currently processing any items\n * - `isRunning`: Whether the queuer is active and will process items automatically\n * - `items`: Array of items currently waiting to be processed\n * - `itemTimestamps`: Timestamps when items were added for expiration tracking\n * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item\n * - `rejectionCount`: Number of items that have been rejected from being added\n * - `size`: Number of items currently in the queue\n * - `status`: Current processing status ('idle' | 'running' | 'stopped')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * {\n * initialItems: ['item1', 'item2'],\n * started: true,\n * wait: 1000,\n * getPriority: (item) => item.priority\n * }\n * );\n *\n * // Opt-in to track queue contents changes (optimized for displaying queue items)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * items: state.items,\n * size: state.size,\n * isEmpty: state.isEmpty\n * })\n * );\n *\n * // Opt-in to track processing state changes (optimized for loading indicators)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * isRunning: state.isRunning,\n * isIdle: state.isIdle,\n * status: state.status,\n * pendingTick: state.pendingTick\n * })\n * );\n *\n * // Opt-in to track execution metrics changes (optimized for stats display)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * expirationCount: state.expirationCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Add items to queue\n * const handleAdd = (item) => {\n * addItem(item);\n * };\n *\n * // Start automatic processing\n * const startProcessing = () => {\n * queue.start();\n * };\n *\n * // Stop automatic processing\n * const stopProcessing = () => {\n * queue.stop();\n * };\n *\n * // Manual processing still available\n * const handleProcess = () => {\n * const nextItem = queue.getNextItem();\n * if (nextItem) {\n * processItem(nextItem);\n * }\n * };\n *\n * // Access the selected queuer state (will be empty object {} unless selector provided)\n * const { size, isRunning, executionCount } = queue.state;\n * ```\n */\nexport function createQueuedSignal<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (item: TValue) => void,\n options: SolidQueuerOptions<TValue, TSelected> = {},\n selector: (state: QueuerState<TValue>) => TSelected = (state) =>\n ({ items: state.items }) as TSelected,\n): [\n () => Array<TValue>,\n SolidQueuer<TValue, TSelected>['addItem'],\n SolidQueuer<TValue, TSelected>,\n] {\n const queue = createQueuer(fn, options, selector)\n\n return [() => queue.state().items, queue.addItem, queue]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsHA,SAAgB,mBAOd,IACA,UAAiD,EAAE,EACnD,YAAuD,WACpD,EAAE,OAAO,MAAM,OAAO,GAKzB;CACA,MAAM,QAAQ,aAAa,IAAI,SAAS,SAAS;CAEjD,OAAO;QAAO,MAAM,OAAO,CAAC;EAAO,MAAM;EAAS;EAAM"}
@@ -1,133 +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_queuer = require("@tanstack/pacer/queuer");
5
-
6
- //#region src/queuer/createQueuer.ts
7
- /**
8
- * Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.
9
- *
10
- * Features:
11
- * - Synchronous processing of items using the provided `fn` function
12
- * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior
13
- * - Priority queueing via `getPriority` or item `priority` property
14
- * - Item expiration and removal of stale items
15
- * - Configurable wait time between processing items
16
- * - Pause/resume processing
17
- * - Callbacks for queue state changes, execution, rejection, and expiration
18
- * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity
19
- *
20
- * The queue processes items synchronously in order, with optional delays between each item. When started, it will process one item per tick, with an optional wait time between ticks. You can pause and resume processing with `stop()` and `start()`.
21
- *
22
- * By default, the queue uses FIFO behavior, but you can configure LIFO or double-ended queueing by specifying the position when adding or removing items.
23
- *
24
- * ## State Management and Selector
25
- *
26
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
27
- * in two ways:
28
- *
29
- * **1. Using `queuer.Subscribe` component (Recommended for component tree subscriptions)**
30
- *
31
- * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
32
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
33
- * in child components.
34
- *
35
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
36
- *
37
- * The `selector` parameter allows you to specify which state changes will trigger reactive updates
38
- * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
39
- * state changes occur.
40
- *
41
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
42
- * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
43
- * updates and gives you full control over when your component tracks state changes.
44
- *
45
- * Available state properties:
46
- * - `executionCount`: Number of items that have been processed
47
- * - `isRunning`: Whether the queuer is currently running (not stopped)
48
- * - `items`: Array of items currently queued for processing
49
- * - `rejectionCount`: Number of items that were rejected (expired or failed validation)
50
- *
51
- * ## Unmount behavior
52
- *
53
- * By default, the primitive stops the queuer when the owning component unmounts.
54
- * Use the `onUnmount` option to customize this. For example, to flush pending items instead:
55
- *
56
- * ```tsx
57
- * const queue = createQueuer(fn, {
58
- * started: true,
59
- * wait: 1000,
60
- * onUnmount: (q) => q.flush()
61
- * });
62
- * ```
63
- *
64
- * Example usage:
65
- * ```tsx
66
- * // Default behavior - no reactive state subscriptions
67
- * const queue = createQueuer(
68
- * (item) => {
69
- * // process item synchronously
70
- * console.log('Processing', item);
71
- * },
72
- * {
73
- * started: true, // Start processing immediately
74
- * wait: 1000, // Process one item every second
75
- * getPriority: (item) => item.priority // Process higher priority items first
76
- * }
77
- * );
78
- *
79
- * // Opt-in to track items or isRunning changes (optimized for UI updates)
80
- * const queue = createQueuer(
81
- * (item) => console.log('Processing', item),
82
- * { started: true, wait: 1000 },
83
- * (state) => ({ items: state.items, isRunning: state.isRunning })
84
- * );
85
- *
86
- * // Opt-in to track execution metrics changes (optimized for tracking progress)
87
- * const queue = createQueuer(
88
- * (item) => console.log('Processing', item),
89
- * { started: true, wait: 1000 },
90
- * (state) => ({
91
- * executionCount: state.executionCount,
92
- * rejectionCount: state.rejectionCount
93
- * })
94
- * );
95
- *
96
- * // Add items to process - they'll be handled automatically
97
- * queue.addItem('task1');
98
- * queue.addItem('task2');
99
- *
100
- * // Control the scheduler
101
- * queue.stop(); // Pause processing
102
- * queue.start(); // Resume processing
103
- *
104
- * // Access the selected state (will be empty object {} unless selector provided)
105
- * const { items, isRunning } = queue.state();
106
- * ```
107
- */
108
- function createQueuer(fn, options = {}, selector = () => ({})) {
109
- const mergedOptions = {
110
- ...require_PacerProvider.useDefaultPacerOptions().queuer,
111
- ...options
112
- };
113
- const queuer = new _tanstack_pacer_queuer.Queuer(fn, mergedOptions);
114
- queuer.Subscribe = function Subscribe(props) {
115
- const selected = (0, _tanstack_solid_store.useSelector)(queuer.store, props.selector, { compare: _tanstack_solid_store.shallow });
116
- return typeof props.children === "function" ? props.children(selected) : props.children;
117
- };
118
- const state = (0, _tanstack_solid_store.useSelector)(queuer.store, selector, { compare: _tanstack_solid_store.shallow });
119
- (0, solid_js.createEffect)(() => {
120
- (0, solid_js.onCleanup)(() => {
121
- if (mergedOptions.onUnmount) mergedOptions.onUnmount(queuer);
122
- else queuer.stop();
123
- });
124
- });
125
- return {
126
- ...queuer,
127
- state
128
- };
129
- }
130
-
131
- //#endregion
132
- exports.createQueuer = createQueuer;
133
- //# sourceMappingURL=createQueuer.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createQueuer.cjs","names":["useDefaultPacerOptions","Queuer","shallow"],"sources":["../../src/queuer/createQueuer.ts"],"sourcesContent":["import { Queuer } from '@tanstack/pacer/queuer'\nimport { shallow, useSelector } from '@tanstack/solid-store'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface SolidQueuerOptions<\n TValue,\n TSelected = {},\n> extends QueuerOptions<TValue> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop); use it to call flush(), flushAsBatch(), stop(), add logging, etc.\n */\n onUnmount?: (queuer: SolidQueuer<TValue, TSelected>) => void\n}\n\nexport interface SolidQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * A Solid component that allows you to subscribe to the queuer state.\n *\n * This is useful for tracking specific parts of the queuer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <queuer.Subscribe selector={(state) => ({ size: state.size, isRunning: state.isRunning })}>\n * {(state) => (\n * <div>Queue: {state().size} items, {state().isRunning ? 'Processing' : 'Idle'}</div>\n * )}\n * </queuer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.\n * Although, you can make the state reactive by using the `useSelector` in your own usage.\n */\n readonly store: Store<Readonly<QueuerState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Synchronous processing of items using the provided `fn` function\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Priority queueing via `getPriority` or item `priority` property\n * - Item expiration and removal of stale items\n * - Configurable wait time between processing items\n * - Pause/resume processing\n * - Callbacks for queue state changes, execution, rejection, and expiration\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The queue processes items synchronously in order, with optional delays between each item. When started, it will process one item per tick, with an optional wait time between ticks. You can pause and resume processing with `stop()` and `start()`.\n *\n * By default, the queue uses FIFO behavior, but you can configure LIFO or double-ended queueing by specifying the position when adding or removing items.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `queuer.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `executionCount`: Number of items that have been processed\n * - `isRunning`: Whether the queuer is currently running (not stopped)\n * - `items`: Array of items currently queued for processing\n * - `rejectionCount`: Number of items that were rejected (expired or failed validation)\n *\n * ## Unmount behavior\n *\n * By default, the primitive stops the queuer when the owning component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending items instead:\n *\n * ```tsx\n * const queue = createQueuer(fn, {\n * started: true,\n * wait: 1000,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const queue = createQueuer(\n * (item) => {\n * // process item synchronously\n * console.log('Processing', item);\n * },\n * {\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * getPriority: (item) => item.priority // Process higher priority items first\n * }\n * );\n *\n * // Opt-in to track items or isRunning changes (optimized for UI updates)\n * const queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\n * (state) => ({ items: state.items, isRunning: state.isRunning })\n * );\n *\n * // Opt-in to track execution metrics changes (optimized for tracking progress)\n * const queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Add items to process - they'll be handled automatically\n * queue.addItem('task1');\n * queue.addItem('task2');\n *\n * // Control the scheduler\n * queue.stop(); // Pause processing\n * queue.start(); // Resume processing\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isRunning } = queue.state();\n * ```\n */\nexport function createQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: SolidQueuerOptions<TValue, TSelected> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): SolidQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().queuer,\n ...options,\n } as SolidQueuerOptions<TValue, TSelected>\n const queuer = new Queuer(fn, mergedOptions) as unknown as SolidQueuer<\n TValue,\n TSelected\n >\n\n queuer.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(queuer.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(queuer.store, selector, { compare: shallow })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(queuer)\n } else {\n queuer.stop()\n }\n })\n })\n\n return {\n ...queuer,\n state,\n } as SolidQueuer<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2JA,SAAgB,aACd,IACA,UAAiD,EAAE,EACnD,kBAA6D,EAAE,GAC/B;CAChC,MAAM,gBAAgB;EACpB,GAAGA,8CAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,SAAS,IAAIC,8BAAO,IAAI,cAAc;CAK5C,OAAO,YAAY,SAAS,UAAqB,OAG9C;EACD,MAAM,kDAAuB,OAAO,OAAO,MAAM,UAAU,EACzD,SAASC,+BACV,CAAC;EAEF,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,+CAAoB,OAAO,OAAO,UAAU,EAAE,SAASA,+BAAS,CAAC;CAEvE,iCAAmB;EACjB,8BAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,OAAO;QAE/B,OAAO,MAAM;IAEf;GACF;CAEF,OAAO;EACL,GAAG;EACH;EACD"}
@@ -1,148 +0,0 @@
1
- import { Store } from "@tanstack/solid-store";
2
- import { Accessor, JSX } from "solid-js";
3
- import { Queuer, QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
4
-
5
- //#region src/queuer/createQueuer.d.ts
6
- interface SolidQueuerOptions<TValue, TSelected = {}> extends QueuerOptions<TValue> {
7
- /**
8
- * Optional callback invoked when the owning component unmounts. Receives the queuer instance.
9
- * When provided, replaces the default cleanup (stop); use it to call flush(), flushAsBatch(), stop(), add logging, etc.
10
- */
11
- onUnmount?: (queuer: SolidQueuer<TValue, TSelected>) => void;
12
- }
13
- interface SolidQueuer<TValue, TSelected = {}> extends Omit<Queuer<TValue>, 'store'> {
14
- /**
15
- * A Solid component that allows you to subscribe to the queuer state.
16
- *
17
- * This is useful for tracking specific parts of the queuer state
18
- * deep in your component tree without needing to pass a selector to the hook.
19
- *
20
- * @example
21
- * <queuer.Subscribe selector={(state) => ({ size: state.size, isRunning: state.isRunning })}>
22
- * {(state) => (
23
- * <div>Queue: {state().size} items, {state().isRunning ? 'Processing' : 'Idle'}</div>
24
- * )}
25
- * </queuer.Subscribe>
26
- */
27
- Subscribe: <TSelected>(props: {
28
- selector: (state: QueuerState<TValue>) => TSelected;
29
- children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
30
- }) => JSX.Element;
31
- /**
32
- * Reactive state that will be updated when the queuer state changes
33
- *
34
- * Use this instead of `queuer.store.state`
35
- */
36
- readonly state: Accessor<Readonly<TSelected>>;
37
- /**
38
- * @deprecated Use `queuer.state` instead of `queuer.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<QueuerState<TValue>>>;
43
- }
44
- /**
45
- * Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.
46
- *
47
- * Features:
48
- * - Synchronous processing of items using the provided `fn` function
49
- * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior
50
- * - Priority queueing via `getPriority` or item `priority` property
51
- * - Item expiration and removal of stale items
52
- * - Configurable wait time between processing items
53
- * - Pause/resume processing
54
- * - Callbacks for queue state changes, execution, rejection, and expiration
55
- * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity
56
- *
57
- * The queue processes items synchronously in order, with optional delays between each item. When started, it will process one item per tick, with an optional wait time between ticks. You can pause and resume processing with `stop()` and `start()`.
58
- *
59
- * By default, the queue uses FIFO behavior, but you can configure LIFO or double-ended queueing by specifying the position when adding or removing items.
60
- *
61
- * ## State Management and Selector
62
- *
63
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
64
- * in two ways:
65
- *
66
- * **1. Using `queuer.Subscribe` component (Recommended for component tree subscriptions)**
67
- *
68
- * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
69
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
70
- * in child components.
71
- *
72
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
73
- *
74
- * The `selector` parameter allows you to specify which state changes will trigger reactive updates
75
- * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
76
- * state changes occur.
77
- *
78
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
79
- * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
80
- * updates and gives you full control over when your component tracks state changes.
81
- *
82
- * Available state properties:
83
- * - `executionCount`: Number of items that have been processed
84
- * - `isRunning`: Whether the queuer is currently running (not stopped)
85
- * - `items`: Array of items currently queued for processing
86
- * - `rejectionCount`: Number of items that were rejected (expired or failed validation)
87
- *
88
- * ## Unmount behavior
89
- *
90
- * By default, the primitive stops the queuer when the owning component unmounts.
91
- * Use the `onUnmount` option to customize this. For example, to flush pending items instead:
92
- *
93
- * ```tsx
94
- * const queue = createQueuer(fn, {
95
- * started: true,
96
- * wait: 1000,
97
- * onUnmount: (q) => q.flush()
98
- * });
99
- * ```
100
- *
101
- * Example usage:
102
- * ```tsx
103
- * // Default behavior - no reactive state subscriptions
104
- * const queue = createQueuer(
105
- * (item) => {
106
- * // process item synchronously
107
- * console.log('Processing', item);
108
- * },
109
- * {
110
- * started: true, // Start processing immediately
111
- * wait: 1000, // Process one item every second
112
- * getPriority: (item) => item.priority // Process higher priority items first
113
- * }
114
- * );
115
- *
116
- * // Opt-in to track items or isRunning changes (optimized for UI updates)
117
- * const queue = createQueuer(
118
- * (item) => console.log('Processing', item),
119
- * { started: true, wait: 1000 },
120
- * (state) => ({ items: state.items, isRunning: state.isRunning })
121
- * );
122
- *
123
- * // Opt-in to track execution metrics changes (optimized for tracking progress)
124
- * const queue = createQueuer(
125
- * (item) => console.log('Processing', item),
126
- * { started: true, wait: 1000 },
127
- * (state) => ({
128
- * executionCount: state.executionCount,
129
- * rejectionCount: state.rejectionCount
130
- * })
131
- * );
132
- *
133
- * // Add items to process - they'll be handled automatically
134
- * queue.addItem('task1');
135
- * queue.addItem('task2');
136
- *
137
- * // Control the scheduler
138
- * queue.stop(); // Pause processing
139
- * queue.start(); // Resume processing
140
- *
141
- * // Access the selected state (will be empty object {} unless selector provided)
142
- * const { items, isRunning } = queue.state();
143
- * ```
144
- */
145
- declare function createQueuer<TValue, TSelected = {}>(fn: (item: TValue) => void, options?: SolidQueuerOptions<TValue, TSelected>, selector?: (state: QueuerState<TValue>) => TSelected): SolidQueuer<TValue, TSelected>;
146
- //#endregion
147
- export { SolidQueuer, SolidQueuerOptions, createQueuer };
148
- //# sourceMappingURL=createQueuer.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createQueuer.js","names":[],"sources":["../../src/queuer/createQueuer.ts"],"sourcesContent":["import { Queuer } from '@tanstack/pacer/queuer'\nimport { shallow, useSelector } from '@tanstack/solid-store'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface SolidQueuerOptions<\n TValue,\n TSelected = {},\n> extends QueuerOptions<TValue> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop); use it to call flush(), flushAsBatch(), stop(), add logging, etc.\n */\n onUnmount?: (queuer: SolidQueuer<TValue, TSelected>) => void\n}\n\nexport interface SolidQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * A Solid component that allows you to subscribe to the queuer state.\n *\n * This is useful for tracking specific parts of the queuer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <queuer.Subscribe selector={(state) => ({ size: state.size, isRunning: state.isRunning })}>\n * {(state) => (\n * <div>Queue: {state().size} items, {state().isRunning ? 'Processing' : 'Idle'}</div>\n * )}\n * </queuer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.\n * Although, you can make the state reactive by using the `useSelector` in your own usage.\n */\n readonly store: Store<Readonly<QueuerState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Synchronous processing of items using the provided `fn` function\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Priority queueing via `getPriority` or item `priority` property\n * - Item expiration and removal of stale items\n * - Configurable wait time between processing items\n * - Pause/resume processing\n * - Callbacks for queue state changes, execution, rejection, and expiration\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The queue processes items synchronously in order, with optional delays between each item. When started, it will process one item per tick, with an optional wait time between ticks. You can pause and resume processing with `stop()` and `start()`.\n *\n * By default, the queue uses FIFO behavior, but you can configure LIFO or double-ended queueing by specifying the position when adding or removing items.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `queuer.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `executionCount`: Number of items that have been processed\n * - `isRunning`: Whether the queuer is currently running (not stopped)\n * - `items`: Array of items currently queued for processing\n * - `rejectionCount`: Number of items that were rejected (expired or failed validation)\n *\n * ## Unmount behavior\n *\n * By default, the primitive stops the queuer when the owning component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending items instead:\n *\n * ```tsx\n * const queue = createQueuer(fn, {\n * started: true,\n * wait: 1000,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const queue = createQueuer(\n * (item) => {\n * // process item synchronously\n * console.log('Processing', item);\n * },\n * {\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * getPriority: (item) => item.priority // Process higher priority items first\n * }\n * );\n *\n * // Opt-in to track items or isRunning changes (optimized for UI updates)\n * const queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\n * (state) => ({ items: state.items, isRunning: state.isRunning })\n * );\n *\n * // Opt-in to track execution metrics changes (optimized for tracking progress)\n * const queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Add items to process - they'll be handled automatically\n * queue.addItem('task1');\n * queue.addItem('task2');\n *\n * // Control the scheduler\n * queue.stop(); // Pause processing\n * queue.start(); // Resume processing\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isRunning } = queue.state();\n * ```\n */\nexport function createQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: SolidQueuerOptions<TValue, TSelected> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): SolidQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().queuer,\n ...options,\n } as SolidQueuerOptions<TValue, TSelected>\n const queuer = new Queuer(fn, mergedOptions) as unknown as SolidQueuer<\n TValue,\n TSelected\n >\n\n queuer.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(queuer.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(queuer.store, selector, { compare: shallow })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(queuer)\n } else {\n queuer.stop()\n }\n })\n })\n\n return {\n ...queuer,\n state,\n } as SolidQueuer<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2JA,SAAgB,aACd,IACA,UAAiD,EAAE,EACnD,kBAA6D,EAAE,GAC/B;CAChC,MAAM,gBAAgB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,SAAS,IAAI,OAAO,IAAI,cAAc;CAK5C,OAAO,YAAY,SAAS,UAAqB,OAG9C;EACD,MAAM,WAAW,YAAY,OAAO,OAAO,MAAM,UAAU,EACzD,SAAS,SACV,CAAC;EAEF,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,QAAQ,YAAY,OAAO,OAAO,UAAU,EAAE,SAAS,SAAS,CAAC;CAEvE,mBAAmB;EACjB,gBAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,OAAO;QAE/B,OAAO,MAAM;IAEf;GACF;CAEF,OAAO;EACL,GAAG;EACH;EACD"}
@@ -1,13 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_createQueuer = require('./createQueuer.cjs');
3
- const require_createQueuedSignal = require('./createQueuedSignal.cjs');
4
-
5
- exports.createQueuedSignal = require_createQueuedSignal.createQueuedSignal;
6
- exports.createQueuer = require_createQueuer.createQueuer;
7
- var _tanstack_pacer_queuer = require("@tanstack/pacer/queuer");
8
- Object.keys(_tanstack_pacer_queuer).forEach(function (k) {
9
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
10
- enumerable: true,
11
- get: function () { return _tanstack_pacer_queuer[k]; }
12
- });
13
- });
@@ -1,4 +0,0 @@
1
- import { SolidQueuer, SolidQueuerOptions, createQueuer } from "./createQueuer.cjs";
2
- import { createQueuedSignal } from "./createQueuedSignal.cjs";
3
- export * from "@tanstack/pacer/queuer";
4
- export { SolidQueuer, SolidQueuerOptions, createQueuedSignal, createQueuer };
@@ -1,102 +0,0 @@
1
- const require_createRateLimiter = require('./createRateLimiter.cjs');
2
- let solid_js = require("solid-js");
3
-
4
- //#region src/rate-limiter/createRateLimitedSignal.ts
5
- /**
6
- * A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.
7
- * This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.
8
- *
9
- * Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks
10
- * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out
11
- * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.
12
- *
13
- * The rate limiter supports two types of windows:
14
- * - 'fixed': A strict window that resets after the window period. All updates within the window count
15
- * towards the limit, and the window resets completely after the period.
16
- * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more
17
- * consistent rate of updates over time.
18
- *
19
- * For smoother update patterns, consider:
20
- * - createThrottledSignal: When you want consistent spacing between updates (e.g. UI changes)
21
- * - createDebouncedSignal: When you want to collapse rapid updates into a single update (e.g. search input)
22
- *
23
- * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.
24
- *
25
- * The hook returns a tuple containing:
26
- * - The rate-limited state value accessor
27
- * - A rate-limited setter function that respects the configured limits
28
- * - The rateLimiter instance for additional control
29
- *
30
- * For more direct control over rate limiting without state management,
31
- * consider using the lower-level createRateLimiter hook instead.
32
- *
33
- * ## State Management and Selector
34
- *
35
- * The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.
36
- * The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,
37
- * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
38
- *
39
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
40
- * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you
41
- * full control over when your component subscribes to state changes. Only when you provide a selector will
42
- * the reactive system track the selected state values.
43
- *
44
- * Available rate limiter state properties:
45
- * - `callsInWindow`: Number of calls made in the current window
46
- * - `remainingInWindow`: Number of calls remaining in the current window
47
- * - `windowStart`: Unix timestamp when the current window started
48
- * - `nextWindowStart`: Unix timestamp when the next window will start
49
- * - `msUntilNextWindow`: Milliseconds until the next window starts
50
- * - `isAtLimit`: Whether the call limit for the current window has been reached
51
- * - `status`: Current status ('disabled' | 'idle' | 'at-limit')
52
- *
53
- * @example
54
- * ```tsx
55
- * // Default behavior - no reactive state subscriptions
56
- * const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {
57
- * limit: 5,
58
- * window: 60000,
59
- * windowType: 'sliding'
60
- * });
61
- *
62
- * // Opt-in to reactive updates when limit state changes (optimized for UI feedback)
63
- * const [value, setValue, rateLimiter] = createRateLimitedSignal(
64
- * 0,
65
- * { limit: 5, window: 60000 },
66
- * (state) => ({ isAtLimit: state.isAtLimit, remainingInWindow: state.remainingInWindow })
67
- * );
68
- *
69
- * // With rejection callback and fixed window
70
- * const [value, setValue] = createRateLimitedSignal(0, {
71
- * limit: 3,
72
- * window: 5000,
73
- * windowType: 'fixed',
74
- * onReject: (rateLimiter) => {
75
- * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
76
- * }
77
- * });
78
- *
79
- * // Access rateLimiter state via signals
80
- * const handleSubmit = () => {
81
- * const remaining = rateLimiter.state().remainingInWindow;
82
- * if (remaining > 0) {
83
- * setValue(newValue);
84
- * } else {
85
- * showRateLimitWarning();
86
- * }
87
- * };
88
- * ```
89
- */
90
- function createRateLimitedSignal(value, initialOptions, selector) {
91
- const [rateLimitedValue, setRateLimitedValue] = (0, solid_js.createSignal)(value);
92
- const rateLimiter = require_createRateLimiter.createRateLimiter(setRateLimitedValue, initialOptions, selector);
93
- return [
94
- rateLimitedValue,
95
- rateLimiter.maybeExecute,
96
- rateLimiter
97
- ];
98
- }
99
-
100
- //#endregion
101
- exports.createRateLimitedSignal = createRateLimitedSignal;
102
- //# sourceMappingURL=createRateLimitedSignal.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createRateLimitedSignal.cjs","names":["createRateLimiter"],"sources":["../../src/rate-limiter/createRateLimitedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createRateLimiter } from './createRateLimiter'\nimport type {\n SolidRateLimiter,\n SolidRateLimiterOptions,\n} from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { RateLimiterState } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.\n * This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\n *\n * For smoother update patterns, consider:\n * - createThrottledSignal: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedSignal: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns a tuple containing:\n * - The rate-limited state value accessor\n * - A rate-limited setter function that respects the configured limits\n * - The rateLimiter instance for additional control\n *\n * For more direct control over rate limiting without state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.\n * The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant 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. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available rate limiter state properties:\n * - `callsInWindow`: Number of calls made in the current window\n * - `remainingInWindow`: Number of calls remaining in the current window\n * - `windowStart`: Unix timestamp when the current window started\n * - `nextWindowStart`: Unix timestamp when the next window will start\n * - `msUntilNextWindow`: Milliseconds until the next window starts\n * - `isAtLimit`: Whether the call limit for the current window has been reached\n * - `status`: Current status ('disabled' | 'idle' | 'at-limit')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to reactive updates when limit state changes (optimized for UI feedback)\n * const [value, setValue, rateLimiter] = createRateLimitedSignal(\n * 0,\n * { limit: 5, window: 60000 },\n * (state) => ({ isAtLimit: state.isAtLimit, remainingInWindow: state.remainingInWindow })\n * );\n *\n * // With rejection callback and fixed window\n * const [value, setValue] = createRateLimitedSignal(0, {\n * limit: 3,\n * window: 5000,\n * windowType: 'fixed',\n * onReject: (rateLimiter) => {\n * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access rateLimiter state via signals\n * const handleSubmit = () => {\n * const remaining = rateLimiter.state().remainingInWindow;\n * if (remaining > 0) {\n * setValue(newValue);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n * ```\n */\nexport function createRateLimitedSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: SolidRateLimiterOptions<Setter<TValue>, TSelected>,\n selector?: (state: RateLimiterState) => TSelected,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidRateLimiter<Setter<TValue>, TSelected>,\n] {\n const [rateLimitedValue, setRateLimitedValue] = createSignal<TValue>(value)\n\n const rateLimiter = createRateLimiter(\n setRateLimitedValue,\n initialOptions,\n selector,\n )\n\n return [\n rateLimitedValue,\n rateLimiter.maybeExecute as Setter<TValue>,\n rateLimiter,\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8FA,SAAgB,wBACd,OACA,gBACA,UAKA;CACA,MAAM,CAAC,kBAAkB,kDAA4C,MAAM;CAE3E,MAAM,cAAcA,4CAClB,qBACA,gBACA,SACD;CAED,OAAO;EACL;EACA,YAAY;EACZ;EACD"}