@tanstack/preact-pacer 0.23.0 → 0.24.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 (242) hide show
  1. package/dist/async-batcher/useAsyncBatchedCallback.d.ts +2 -4
  2. package/dist/async-batcher/useAsyncBatchedCallback.js +1 -2
  3. package/dist/async-batcher/useAsyncBatcher.d.ts +4 -7
  4. package/dist/async-batcher/useAsyncBatcher.js +1 -3
  5. package/dist/async-debouncer/useAsyncDebouncedCallback.d.ts +2 -4
  6. package/dist/async-debouncer/useAsyncDebouncedCallback.js +1 -2
  7. package/dist/async-debouncer/useAsyncDebouncer.d.ts +4 -6
  8. package/dist/async-debouncer/useAsyncDebouncer.js +1 -2
  9. package/dist/async-queuer/useAsyncQueuedState.d.ts +4 -6
  10. package/dist/async-queuer/useAsyncQueuedState.js +3 -4
  11. package/dist/async-queuer/useAsyncQueuer.d.ts +6 -8
  12. package/dist/async-queuer/useAsyncQueuer.js +3 -4
  13. package/dist/async-rate-limiter/useAsyncRateLimitedCallback.d.ts +2 -4
  14. package/dist/async-rate-limiter/useAsyncRateLimitedCallback.js +1 -2
  15. package/dist/async-rate-limiter/useAsyncRateLimiter.d.ts +4 -6
  16. package/dist/async-rate-limiter/useAsyncRateLimiter.js +1 -2
  17. package/dist/async-throttler/useAsyncThrottledCallback.d.ts +2 -4
  18. package/dist/async-throttler/useAsyncThrottledCallback.js +1 -2
  19. package/dist/async-throttler/useAsyncThrottler.d.ts +4 -6
  20. package/dist/async-throttler/useAsyncThrottler.js +1 -2
  21. package/dist/batcher/useBatchedCallback.d.ts +2 -4
  22. package/dist/batcher/useBatchedCallback.js +1 -2
  23. package/dist/batcher/useBatcher.d.ts +6 -10
  24. package/dist/batcher/useBatcher.js +3 -6
  25. package/dist/debouncer/useDebouncedCallback.d.ts +2 -4
  26. package/dist/debouncer/useDebouncedCallback.js +1 -2
  27. package/dist/debouncer/useDebouncedState.d.ts +2 -4
  28. package/dist/debouncer/useDebouncedState.js +1 -2
  29. package/dist/debouncer/useDebouncedValue.d.ts +2 -4
  30. package/dist/debouncer/useDebouncedValue.js +1 -2
  31. package/dist/debouncer/useDebouncer.d.ts +4 -6
  32. package/dist/debouncer/useDebouncer.js +1 -2
  33. package/dist/provider/PacerProvider.d.ts +6 -8
  34. package/dist/provider/PacerProvider.js +1 -2
  35. package/dist/queuer/useQueuedState.d.ts +2 -4
  36. package/dist/queuer/useQueuedState.js +1 -2
  37. package/dist/queuer/useQueuedValue.d.ts +2 -4
  38. package/dist/queuer/useQueuedValue.js +1 -2
  39. package/dist/queuer/useQueuer.d.ts +4 -6
  40. package/dist/queuer/useQueuer.js +1 -2
  41. package/dist/rate-limiter/useRateLimitedCallback.d.ts +2 -4
  42. package/dist/rate-limiter/useRateLimitedCallback.js +1 -2
  43. package/dist/rate-limiter/useRateLimitedState.d.ts +2 -4
  44. package/dist/rate-limiter/useRateLimitedState.js +1 -2
  45. package/dist/rate-limiter/useRateLimitedValue.d.ts +2 -4
  46. package/dist/rate-limiter/useRateLimitedValue.js +1 -2
  47. package/dist/rate-limiter/useRateLimiter.d.ts +4 -6
  48. package/dist/rate-limiter/useRateLimiter.js +1 -2
  49. package/dist/throttler/useThrottledCallback.d.ts +2 -4
  50. package/dist/throttler/useThrottledCallback.js +1 -2
  51. package/dist/throttler/useThrottledState.d.ts +2 -4
  52. package/dist/throttler/useThrottledState.js +1 -2
  53. package/dist/throttler/useThrottledValue.d.ts +2 -4
  54. package/dist/throttler/useThrottledValue.js +1 -2
  55. package/dist/throttler/useThrottler.d.ts +4 -6
  56. package/dist/throttler/useThrottler.js +1 -2
  57. package/package.json +22 -70
  58. package/dist/async-batcher/index.cjs +0 -13
  59. package/dist/async-batcher/index.d.cts +0 -4
  60. package/dist/async-batcher/useAsyncBatchedCallback.cjs +0 -51
  61. package/dist/async-batcher/useAsyncBatchedCallback.cjs.map +0 -1
  62. package/dist/async-batcher/useAsyncBatchedCallback.d.cts +0 -43
  63. package/dist/async-batcher/useAsyncBatchedCallback.js.map +0 -1
  64. package/dist/async-batcher/useAsyncBatcher.cjs +0 -217
  65. package/dist/async-batcher/useAsyncBatcher.cjs.map +0 -1
  66. package/dist/async-batcher/useAsyncBatcher.d.cts +0 -223
  67. package/dist/async-batcher/useAsyncBatcher.js.map +0 -1
  68. package/dist/async-debouncer/index.cjs +0 -13
  69. package/dist/async-debouncer/index.d.cts +0 -4
  70. package/dist/async-debouncer/useAsyncDebouncedCallback.cjs +0 -52
  71. package/dist/async-debouncer/useAsyncDebouncedCallback.cjs.map +0 -1
  72. package/dist/async-debouncer/useAsyncDebouncedCallback.d.cts +0 -47
  73. package/dist/async-debouncer/useAsyncDebouncedCallback.js.map +0 -1
  74. package/dist/async-debouncer/useAsyncDebouncer.cjs +0 -195
  75. package/dist/async-debouncer/useAsyncDebouncer.cjs.map +0 -1
  76. package/dist/async-debouncer/useAsyncDebouncer.d.cts +0 -202
  77. package/dist/async-debouncer/useAsyncDebouncer.js.map +0 -1
  78. package/dist/async-queuer/index.cjs +0 -13
  79. package/dist/async-queuer/index.d.cts +0 -4
  80. package/dist/async-queuer/useAsyncQueuedState.cjs +0 -154
  81. package/dist/async-queuer/useAsyncQueuedState.cjs.map +0 -1
  82. package/dist/async-queuer/useAsyncQueuedState.d.cts +0 -150
  83. package/dist/async-queuer/useAsyncQueuedState.js.map +0 -1
  84. package/dist/async-queuer/useAsyncQueuer.cjs +0 -217
  85. package/dist/async-queuer/useAsyncQueuer.cjs.map +0 -1
  86. package/dist/async-queuer/useAsyncQueuer.d.cts +0 -223
  87. package/dist/async-queuer/useAsyncQueuer.js.map +0 -1
  88. package/dist/async-rate-limiter/index.cjs +0 -13
  89. package/dist/async-rate-limiter/index.d.cts +0 -4
  90. package/dist/async-rate-limiter/useAsyncRateLimitedCallback.cjs +0 -65
  91. package/dist/async-rate-limiter/useAsyncRateLimitedCallback.cjs.map +0 -1
  92. package/dist/async-rate-limiter/useAsyncRateLimitedCallback.d.cts +0 -60
  93. package/dist/async-rate-limiter/useAsyncRateLimitedCallback.js.map +0 -1
  94. package/dist/async-rate-limiter/useAsyncRateLimiter.cjs +0 -209
  95. package/dist/async-rate-limiter/useAsyncRateLimiter.cjs.map +0 -1
  96. package/dist/async-rate-limiter/useAsyncRateLimiter.d.cts +0 -219
  97. package/dist/async-rate-limiter/useAsyncRateLimiter.js.map +0 -1
  98. package/dist/async-retryer/index.cjs +0 -8
  99. package/dist/async-retryer/index.d.cts +0 -1
  100. package/dist/async-throttler/index.cjs +0 -13
  101. package/dist/async-throttler/index.d.cts +0 -4
  102. package/dist/async-throttler/useAsyncThrottledCallback.cjs +0 -49
  103. package/dist/async-throttler/useAsyncThrottledCallback.cjs.map +0 -1
  104. package/dist/async-throttler/useAsyncThrottledCallback.d.cts +0 -44
  105. package/dist/async-throttler/useAsyncThrottledCallback.js.map +0 -1
  106. package/dist/async-throttler/useAsyncThrottler.cjs +0 -206
  107. package/dist/async-throttler/useAsyncThrottler.cjs.map +0 -1
  108. package/dist/async-throttler/useAsyncThrottler.d.cts +0 -213
  109. package/dist/async-throttler/useAsyncThrottler.js.map +0 -1
  110. package/dist/batcher/index.cjs +0 -13
  111. package/dist/batcher/index.d.cts +0 -4
  112. package/dist/batcher/useBatchedCallback.cjs +0 -47
  113. package/dist/batcher/useBatchedCallback.cjs.map +0 -1
  114. package/dist/batcher/useBatchedCallback.d.cts +0 -41
  115. package/dist/batcher/useBatchedCallback.js.map +0 -1
  116. package/dist/batcher/useBatcher.cjs +0 -165
  117. package/dist/batcher/useBatcher.cjs.map +0 -1
  118. package/dist/batcher/useBatcher.d.cts +0 -174
  119. package/dist/batcher/useBatcher.js.map +0 -1
  120. package/dist/debouncer/index.cjs +0 -17
  121. package/dist/debouncer/index.d.cts +0 -6
  122. package/dist/debouncer/useDebouncedCallback.cjs +0 -48
  123. package/dist/debouncer/useDebouncedCallback.cjs.map +0 -1
  124. package/dist/debouncer/useDebouncedCallback.d.cts +0 -43
  125. package/dist/debouncer/useDebouncedCallback.js.map +0 -1
  126. package/dist/debouncer/useDebouncedState.cjs +0 -89
  127. package/dist/debouncer/useDebouncedState.cjs.map +0 -1
  128. package/dist/debouncer/useDebouncedState.d.cts +0 -80
  129. package/dist/debouncer/useDebouncedState.js.map +0 -1
  130. package/dist/debouncer/useDebouncedValue.cjs +0 -96
  131. package/dist/debouncer/useDebouncedValue.cjs.map +0 -1
  132. package/dist/debouncer/useDebouncedValue.d.cts +0 -89
  133. package/dist/debouncer/useDebouncedValue.js.map +0 -1
  134. package/dist/debouncer/useDebouncer.cjs +0 -141
  135. package/dist/debouncer/useDebouncer.cjs.map +0 -1
  136. package/dist/debouncer/useDebouncer.d.cts +0 -151
  137. package/dist/debouncer/useDebouncer.js.map +0 -1
  138. package/dist/index.cjs +0 -67
  139. package/dist/index.d.cts +0 -30
  140. package/dist/provider/PacerProvider.cjs +0 -26
  141. package/dist/provider/PacerProvider.cjs.map +0 -1
  142. package/dist/provider/PacerProvider.d.cts +0 -28
  143. package/dist/provider/PacerProvider.js.map +0 -1
  144. package/dist/provider/index.cjs +0 -6
  145. package/dist/provider/index.d.cts +0 -2
  146. package/dist/queuer/index.cjs +0 -15
  147. package/dist/queuer/index.d.cts +0 -5
  148. package/dist/queuer/useQueuedState.cjs +0 -129
  149. package/dist/queuer/useQueuedState.cjs.map +0 -1
  150. package/dist/queuer/useQueuedState.d.cts +0 -121
  151. package/dist/queuer/useQueuedState.js.map +0 -1
  152. package/dist/queuer/useQueuedValue.cjs +0 -115
  153. package/dist/queuer/useQueuedValue.cjs.map +0 -1
  154. package/dist/queuer/useQueuedValue.d.cts +0 -104
  155. package/dist/queuer/useQueuedValue.js.map +0 -1
  156. package/dist/queuer/useQueuer.cjs +0 -176
  157. package/dist/queuer/useQueuer.cjs.map +0 -1
  158. package/dist/queuer/useQueuer.d.cts +0 -185
  159. package/dist/queuer/useQueuer.js.map +0 -1
  160. package/dist/rate-limiter/index.cjs +0 -17
  161. package/dist/rate-limiter/index.d.cts +0 -6
  162. package/dist/rate-limiter/useRateLimitedCallback.cjs +0 -65
  163. package/dist/rate-limiter/useRateLimitedCallback.cjs.map +0 -1
  164. package/dist/rate-limiter/useRateLimitedCallback.d.cts +0 -60
  165. package/dist/rate-limiter/useRateLimitedCallback.js.map +0 -1
  166. package/dist/rate-limiter/useRateLimitedState.cjs +0 -115
  167. package/dist/rate-limiter/useRateLimitedState.cjs.map +0 -1
  168. package/dist/rate-limiter/useRateLimitedState.d.cts +0 -106
  169. package/dist/rate-limiter/useRateLimitedState.js.map +0 -1
  170. package/dist/rate-limiter/useRateLimitedValue.cjs +0 -102
  171. package/dist/rate-limiter/useRateLimitedValue.cjs.map +0 -1
  172. package/dist/rate-limiter/useRateLimitedValue.d.cts +0 -95
  173. package/dist/rate-limiter/useRateLimitedValue.js.map +0 -1
  174. package/dist/rate-limiter/useRateLimiter.cjs +0 -167
  175. package/dist/rate-limiter/useRateLimiter.cjs.map +0 -1
  176. package/dist/rate-limiter/useRateLimiter.d.cts +0 -178
  177. package/dist/rate-limiter/useRateLimiter.js.map +0 -1
  178. package/dist/throttler/index.cjs +0 -17
  179. package/dist/throttler/index.d.cts +0 -6
  180. package/dist/throttler/useThrottledCallback.cjs +0 -49
  181. package/dist/throttler/useThrottledCallback.cjs.map +0 -1
  182. package/dist/throttler/useThrottledCallback.d.cts +0 -44
  183. package/dist/throttler/useThrottledCallback.js.map +0 -1
  184. package/dist/throttler/useThrottledState.cjs +0 -100
  185. package/dist/throttler/useThrottledState.cjs.map +0 -1
  186. package/dist/throttler/useThrottledState.d.cts +0 -91
  187. package/dist/throttler/useThrottledState.js.map +0 -1
  188. package/dist/throttler/useThrottledValue.cjs +0 -91
  189. package/dist/throttler/useThrottledValue.cjs.map +0 -1
  190. package/dist/throttler/useThrottledValue.d.cts +0 -84
  191. package/dist/throttler/useThrottledValue.js.map +0 -1
  192. package/dist/throttler/useThrottler.cjs +0 -146
  193. package/dist/throttler/useThrottler.cjs.map +0 -1
  194. package/dist/throttler/useThrottler.d.cts +0 -156
  195. package/dist/throttler/useThrottler.js.map +0 -1
  196. package/dist/types/index.cjs +0 -8
  197. package/dist/types/index.d.cts +0 -1
  198. package/dist/utils/index.cjs +0 -8
  199. package/dist/utils/index.d.cts +0 -1
  200. package/src/async-batcher/index.ts +0 -4
  201. package/src/async-batcher/useAsyncBatchedCallback.ts +0 -53
  202. package/src/async-batcher/useAsyncBatcher.ts +0 -293
  203. package/src/async-debouncer/index.ts +0 -5
  204. package/src/async-debouncer/useAsyncDebouncedCallback.ts +0 -55
  205. package/src/async-debouncer/useAsyncDebouncer.ts +0 -274
  206. package/src/async-queuer/index.ts +0 -4
  207. package/src/async-queuer/useAsyncQueuedState.ts +0 -165
  208. package/src/async-queuer/useAsyncQueuer.ts +0 -293
  209. package/src/async-rate-limiter/index.ts +0 -5
  210. package/src/async-rate-limiter/useAsyncRateLimitedCallback.ts +0 -68
  211. package/src/async-rate-limiter/useAsyncRateLimiter.ts +0 -294
  212. package/src/async-retryer/index.ts +0 -2
  213. package/src/async-throttler/index.ts +0 -5
  214. package/src/async-throttler/useAsyncThrottledCallback.ts +0 -52
  215. package/src/async-throttler/useAsyncThrottler.ts +0 -285
  216. package/src/batcher/index.ts +0 -4
  217. package/src/batcher/useBatchedCallback.ts +0 -46
  218. package/src/batcher/useBatcher.ts +0 -241
  219. package/src/debouncer/index.ts +0 -7
  220. package/src/debouncer/useDebouncedCallback.ts +0 -51
  221. package/src/debouncer/useDebouncedState.ts +0 -106
  222. package/src/debouncer/useDebouncedValue.ts +0 -109
  223. package/src/debouncer/useDebouncer.ts +0 -219
  224. package/src/index.ts +0 -56
  225. package/src/provider/PacerProvider.tsx +0 -70
  226. package/src/provider/index.ts +0 -1
  227. package/src/queuer/index.ts +0 -5
  228. package/src/queuer/useQueuedState.ts +0 -133
  229. package/src/queuer/useQueuedValue.ts +0 -129
  230. package/src/queuer/useQueuer.ts +0 -251
  231. package/src/rate-limiter/index.ts +0 -6
  232. package/src/rate-limiter/useRateLimitedCallback.ts +0 -68
  233. package/src/rate-limiter/useRateLimitedState.ts +0 -124
  234. package/src/rate-limiter/useRateLimitedValue.ts +0 -110
  235. package/src/rate-limiter/useRateLimiter.ts +0 -244
  236. package/src/throttler/index.ts +0 -7
  237. package/src/throttler/useThrottledCallback.ts +0 -52
  238. package/src/throttler/useThrottledState.ts +0 -118
  239. package/src/throttler/useThrottledValue.ts +0 -104
  240. package/src/throttler/useThrottler.ts +0 -224
  241. package/src/types/index.ts +0 -1
  242. package/src/utils/index.ts +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"useQueuedState.js","names":[],"sources":["../../src/queuer/useQueuedState.ts"],"sourcesContent":["import { useQueuer } from './useQueuer'\nimport type { PreactQueuer, PreactQueuerOptions } from './useQueuer'\nimport type { Queuer, QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * A Preact hook that creates a queuer with managed state, combining Preact's useState with queuing functionality.\n * This hook 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 hook.\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 hook 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 hook uses TanStack Store for reactive state management via the underlying queuer instance.\n * The `selector` parameter allows you to specify which queuer state changes will trigger a re-render,\n * optimizing performance by preventing unnecessary re-renders 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 re-renders and gives you\n * full control over when your component updates. Only when you provide a selector will the\n * component re-render when the selected state values change.\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] = useQueuedState(\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 re-render when queue contents change (optimized for displaying queue items)\n * const [items, addItem, queue] = useQueuedState(\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 re-render when processing state changes (optimized for loading indicators)\n * const [items, addItem, queue] = useQueuedState(\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 re-render when execution metrics change (optimized for stats display)\n * const [items, addItem, queue] = useQueuedState(\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 useQueuedState<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (item: TValue) => void,\n options: PreactQueuerOptions<TValue, TSelected> = {},\n selector?: (state: QueuerState<TValue>) => TSelected,\n): [Array<TValue>, Queuer<TValue>['addItem'], PreactQueuer<TValue, TSelected>] {\n const queue = useQueuer(fn, options, selector)\n\n return [queue.state.items, queue.addItem, queue]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsHA,SAAgB,eAOd,IACA,UAAkD,CAAC,GACnD,UAC6E;CAC7E,MAAM,QAAQ,UAAU,IAAI,SAAS,QAAQ;CAE7C,OAAO;EAAC,MAAM,MAAM;EAAO,MAAM;EAAS;CAAK;AACjD"}
@@ -1,115 +0,0 @@
1
- const require_useQueuedState = require('./useQueuedState.cjs');
2
- let preact_hooks = require("preact/hooks");
3
-
4
- //#region src/queuer/useQueuedValue.ts
5
- /**
6
- * A Preact hook that creates a queued value that processes state changes in order with an optional delay.
7
- * This hook uses useQueuer internally to manage a queue of state changes and apply them sequentially.
8
- *
9
- * The queued value will process changes in the order they are received, with optional delays between
10
- * processing each change. This is useful for handling state updates that need to be processed
11
- * in a specific order, like animations or sequential UI updates.
12
- *
13
- * The hook returns a tuple containing:
14
- * - The current queued value
15
- * - The queuer instance with control methods
16
- *
17
- * ## State Management and Selector
18
- *
19
- * The hook uses TanStack Store for reactive state management via the underlying queuer instance.
20
- * The `selector` parameter allows you to specify which queuer state changes will trigger a re-render,
21
- * optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur.
22
- *
23
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
24
- * tracking by providing a selector function. This prevents unnecessary re-renders and gives you
25
- * full control over when your component updates. Only when you provide a selector will the
26
- * component re-render when the selected state values change.
27
- *
28
- * Available queuer state properties:
29
- * - `executionCount`: Number of items that have been processed by the queuer
30
- * - `expirationCount`: Number of items that have been removed due to expiration
31
- * - `isEmpty`: Whether the queuer has no items to process
32
- * - `isFull`: Whether the queuer has reached its maximum capacity
33
- * - `isIdle`: Whether the queuer is not currently processing any items
34
- * - `isRunning`: Whether the queuer is active and will process items automatically
35
- * - `items`: Array of items currently waiting to be processed
36
- * - `itemTimestamps`: Timestamps when items were added for expiration tracking
37
- * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item
38
- * - `rejectionCount`: Number of items that have been rejected from being added
39
- * - `size`: Number of items currently in the queue
40
- * - `status`: Current processing status ('idle' | 'running' | 'stopped')
41
- *
42
- * @example
43
- * ```tsx
44
- * // Default behavior - no reactive state subscriptions
45
- * const [value, queuer] = useQueuedValue(initialValue, {
46
- * wait: 500, // Wait 500ms between processing each change
47
- * started: true // Start processing immediately
48
- * });
49
- *
50
- * // Opt-in to re-render when queue processing state changes (optimized for loading indicators)
51
- * const [value, queuer] = useQueuedValue(
52
- * initialValue,
53
- * { wait: 500, started: true },
54
- * (state) => ({
55
- * isRunning: state.isRunning,
56
- * isIdle: state.isIdle,
57
- * status: state.status,
58
- * pendingTick: state.pendingTick
59
- * })
60
- * );
61
- *
62
- * // Opt-in to re-render when queue contents change (optimized for displaying queue status)
63
- * const [value, queuer] = useQueuedValue(
64
- * initialValue,
65
- * { wait: 500, started: true },
66
- * (state) => ({
67
- * size: state.size,
68
- * isEmpty: state.isEmpty,
69
- * isFull: state.isFull
70
- * })
71
- * );
72
- *
73
- * // Opt-in to re-render when execution metrics change (optimized for stats display)
74
- * const [value, queuer] = useQueuedValue(
75
- * initialValue,
76
- * { wait: 500, started: true },
77
- * (state) => ({
78
- * executionCount: state.executionCount,
79
- * expirationCount: state.expirationCount,
80
- * rejectionCount: state.rejectionCount
81
- * })
82
- * );
83
- *
84
- * // Add changes to the queue
85
- * const handleChange = (newValue) => {
86
- * queuer.addItem(newValue);
87
- * };
88
- *
89
- * // Control the queue
90
- * const pauseProcessing = () => {
91
- * queuer.stop();
92
- * };
93
- *
94
- * const resumeProcessing = () => {
95
- * queuer.start();
96
- * };
97
- *
98
- * // Access the selected queuer state (will be empty object {} unless selector provided)
99
- * const { size, isRunning, executionCount } = queuer.state;
100
- * ```
101
- */
102
- function useQueuedValue(initialValue, options = {}, selector) {
103
- const [value, setValue] = (0, preact_hooks.useState)(initialValue);
104
- const [, addItem, queuer] = require_useQueuedState.useQueuedState((item) => {
105
- setValue(item);
106
- }, options, selector);
107
- (0, preact_hooks.useEffect)(() => {
108
- addItem(initialValue);
109
- }, [initialValue, addItem]);
110
- return [value, queuer];
111
- }
112
-
113
- //#endregion
114
- exports.useQueuedValue = useQueuedValue;
115
- //# sourceMappingURL=useQueuedValue.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useQueuedValue.cjs","names":["useState","useQueuedState"],"sources":["../../src/queuer/useQueuedValue.ts"],"sourcesContent":["import { useEffect, useState } from 'preact/hooks'\nimport { useQueuedState } from './useQueuedState'\nimport type { PreactQueuer, PreactQueuerOptions } from './useQueuer'\nimport type { QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * A Preact hook that creates a queued value that processes state changes in order with an optional delay.\n * This hook uses useQueuer internally to manage a queue of state changes and apply them sequentially.\n *\n * The queued value will process changes in the order they are received, with optional delays between\n * processing each change. This is useful for handling state updates that need to be processed\n * in a specific order, like animations or sequential UI updates.\n *\n * The hook returns a tuple containing:\n * - The current queued value\n * - The queuer instance with control methods\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying queuer instance.\n * The `selector` parameter allows you to specify which queuer state changes will trigger a re-render,\n * optimizing performance by preventing unnecessary re-renders 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 re-renders and gives you\n * full control over when your component updates. Only when you provide a selector will the\n * component re-render when the selected state values change.\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 [value, queuer] = useQueuedValue(initialValue, {\n * wait: 500, // Wait 500ms between processing each change\n * started: true // Start processing immediately\n * });\n *\n * // Opt-in to re-render when queue processing state changes (optimized for loading indicators)\n * const [value, queuer] = useQueuedValue(\n * initialValue,\n * { wait: 500, started: true },\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 re-render when queue contents change (optimized for displaying queue status)\n * const [value, queuer] = useQueuedValue(\n * initialValue,\n * { wait: 500, started: true },\n * (state) => ({\n * size: state.size,\n * isEmpty: state.isEmpty,\n * isFull: state.isFull\n * })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for stats display)\n * const [value, queuer] = useQueuedValue(\n * initialValue,\n * { wait: 500, started: true },\n * (state) => ({\n * executionCount: state.executionCount,\n * expirationCount: state.expirationCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Add changes to the queue\n * const handleChange = (newValue) => {\n * queuer.addItem(newValue);\n * };\n *\n * // Control the queue\n * const pauseProcessing = () => {\n * queuer.stop();\n * };\n *\n * const resumeProcessing = () => {\n * queuer.start();\n * };\n *\n * // Access the selected queuer state (will be empty object {} unless selector provided)\n * const { size, isRunning, executionCount } = queuer.state;\n * ```\n */\nexport function useQueuedValue<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n initialValue: TValue,\n options: PreactQueuerOptions<TValue, TSelected> = {},\n selector?: (state: QueuerState<TValue>) => TSelected,\n): [TValue, PreactQueuer<TValue, TSelected>] {\n const [value, setValue] = useState<TValue>(initialValue)\n\n const [, addItem, queuer] = useQueuedState(\n (item) => {\n setValue(item)\n },\n options,\n selector,\n )\n\n useEffect(() => {\n addItem(initialValue)\n }, [initialValue, addItem])\n\n return [value, queuer]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,SAAgB,eAOd,cACA,UAAkD,CAAC,GACnD,UAC2C;CAC3C,MAAM,CAAC,OAAO,gBAAYA,uBAAiB,YAAY;CAEvD,MAAM,GAAG,SAAS,UAAUC,uCACzB,SAAS;EACR,SAAS,IAAI;CACf,GACA,SACA,QACF;CAEA,kCAAgB;EACd,QAAQ,YAAY;CACtB,GAAG,CAAC,cAAc,OAAO,CAAC;CAE1B,OAAO,CAAC,OAAO,MAAM;AACvB"}
@@ -1,104 +0,0 @@
1
- import { PreactQueuer, PreactQueuerOptions } from "./useQueuer.cjs";
2
- import { QueuerState } from "@tanstack/pacer/queuer";
3
- //#region src/queuer/useQueuedValue.d.ts
4
- /**
5
- * A Preact hook that creates a queued value that processes state changes in order with an optional delay.
6
- * This hook uses useQueuer internally to manage a queue of state changes and apply them sequentially.
7
- *
8
- * The queued value will process changes in the order they are received, with optional delays between
9
- * processing each change. This is useful for handling state updates that need to be processed
10
- * in a specific order, like animations or sequential UI updates.
11
- *
12
- * The hook returns a tuple containing:
13
- * - The current queued value
14
- * - The queuer instance with control methods
15
- *
16
- * ## State Management and Selector
17
- *
18
- * The hook uses TanStack Store for reactive state management via the underlying queuer instance.
19
- * The `selector` parameter allows you to specify which queuer state changes will trigger a re-render,
20
- * optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur.
21
- *
22
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
23
- * tracking by providing a selector function. This prevents unnecessary re-renders and gives you
24
- * full control over when your component updates. Only when you provide a selector will the
25
- * component re-render when the selected state values change.
26
- *
27
- * Available queuer state properties:
28
- * - `executionCount`: Number of items that have been processed by the queuer
29
- * - `expirationCount`: Number of items that have been removed due to expiration
30
- * - `isEmpty`: Whether the queuer has no items to process
31
- * - `isFull`: Whether the queuer has reached its maximum capacity
32
- * - `isIdle`: Whether the queuer is not currently processing any items
33
- * - `isRunning`: Whether the queuer is active and will process items automatically
34
- * - `items`: Array of items currently waiting to be processed
35
- * - `itemTimestamps`: Timestamps when items were added for expiration tracking
36
- * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item
37
- * - `rejectionCount`: Number of items that have been rejected from being added
38
- * - `size`: Number of items currently in the queue
39
- * - `status`: Current processing status ('idle' | 'running' | 'stopped')
40
- *
41
- * @example
42
- * ```tsx
43
- * // Default behavior - no reactive state subscriptions
44
- * const [value, queuer] = useQueuedValue(initialValue, {
45
- * wait: 500, // Wait 500ms between processing each change
46
- * started: true // Start processing immediately
47
- * });
48
- *
49
- * // Opt-in to re-render when queue processing state changes (optimized for loading indicators)
50
- * const [value, queuer] = useQueuedValue(
51
- * initialValue,
52
- * { wait: 500, started: true },
53
- * (state) => ({
54
- * isRunning: state.isRunning,
55
- * isIdle: state.isIdle,
56
- * status: state.status,
57
- * pendingTick: state.pendingTick
58
- * })
59
- * );
60
- *
61
- * // Opt-in to re-render when queue contents change (optimized for displaying queue status)
62
- * const [value, queuer] = useQueuedValue(
63
- * initialValue,
64
- * { wait: 500, started: true },
65
- * (state) => ({
66
- * size: state.size,
67
- * isEmpty: state.isEmpty,
68
- * isFull: state.isFull
69
- * })
70
- * );
71
- *
72
- * // Opt-in to re-render when execution metrics change (optimized for stats display)
73
- * const [value, queuer] = useQueuedValue(
74
- * initialValue,
75
- * { wait: 500, started: true },
76
- * (state) => ({
77
- * executionCount: state.executionCount,
78
- * expirationCount: state.expirationCount,
79
- * rejectionCount: state.rejectionCount
80
- * })
81
- * );
82
- *
83
- * // Add changes to the queue
84
- * const handleChange = (newValue) => {
85
- * queuer.addItem(newValue);
86
- * };
87
- *
88
- * // Control the queue
89
- * const pauseProcessing = () => {
90
- * queuer.stop();
91
- * };
92
- *
93
- * const resumeProcessing = () => {
94
- * queuer.start();
95
- * };
96
- *
97
- * // Access the selected queuer state (will be empty object {} unless selector provided)
98
- * const { size, isRunning, executionCount } = queuer.state;
99
- * ```
100
- */
101
- declare function useQueuedValue<TValue, TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<QueuerState<TValue>, 'items'>>(initialValue: TValue, options?: PreactQueuerOptions<TValue, TSelected>, selector?: (state: QueuerState<TValue>) => TSelected): [TValue, PreactQueuer<TValue, TSelected>];
102
- //#endregion
103
- export { useQueuedValue };
104
- //# sourceMappingURL=useQueuedValue.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useQueuedValue.js","names":[],"sources":["../../src/queuer/useQueuedValue.ts"],"sourcesContent":["import { useEffect, useState } from 'preact/hooks'\nimport { useQueuedState } from './useQueuedState'\nimport type { PreactQueuer, PreactQueuerOptions } from './useQueuer'\nimport type { QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * A Preact hook that creates a queued value that processes state changes in order with an optional delay.\n * This hook uses useQueuer internally to manage a queue of state changes and apply them sequentially.\n *\n * The queued value will process changes in the order they are received, with optional delays between\n * processing each change. This is useful for handling state updates that need to be processed\n * in a specific order, like animations or sequential UI updates.\n *\n * The hook returns a tuple containing:\n * - The current queued value\n * - The queuer instance with control methods\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying queuer instance.\n * The `selector` parameter allows you to specify which queuer state changes will trigger a re-render,\n * optimizing performance by preventing unnecessary re-renders 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 re-renders and gives you\n * full control over when your component updates. Only when you provide a selector will the\n * component re-render when the selected state values change.\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 [value, queuer] = useQueuedValue(initialValue, {\n * wait: 500, // Wait 500ms between processing each change\n * started: true // Start processing immediately\n * });\n *\n * // Opt-in to re-render when queue processing state changes (optimized for loading indicators)\n * const [value, queuer] = useQueuedValue(\n * initialValue,\n * { wait: 500, started: true },\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 re-render when queue contents change (optimized for displaying queue status)\n * const [value, queuer] = useQueuedValue(\n * initialValue,\n * { wait: 500, started: true },\n * (state) => ({\n * size: state.size,\n * isEmpty: state.isEmpty,\n * isFull: state.isFull\n * })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for stats display)\n * const [value, queuer] = useQueuedValue(\n * initialValue,\n * { wait: 500, started: true },\n * (state) => ({\n * executionCount: state.executionCount,\n * expirationCount: state.expirationCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Add changes to the queue\n * const handleChange = (newValue) => {\n * queuer.addItem(newValue);\n * };\n *\n * // Control the queue\n * const pauseProcessing = () => {\n * queuer.stop();\n * };\n *\n * const resumeProcessing = () => {\n * queuer.start();\n * };\n *\n * // Access the selected queuer state (will be empty object {} unless selector provided)\n * const { size, isRunning, executionCount } = queuer.state;\n * ```\n */\nexport function useQueuedValue<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n initialValue: TValue,\n options: PreactQueuerOptions<TValue, TSelected> = {},\n selector?: (state: QueuerState<TValue>) => TSelected,\n): [TValue, PreactQueuer<TValue, TSelected>] {\n const [value, setValue] = useState<TValue>(initialValue)\n\n const [, addItem, queuer] = useQueuedState(\n (item) => {\n setValue(item)\n },\n options,\n selector,\n )\n\n useEffect(() => {\n addItem(initialValue)\n }, [initialValue, addItem])\n\n return [value, queuer]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,SAAgB,eAOd,cACA,UAAkD,CAAC,GACnD,UAC2C;CAC3C,MAAM,CAAC,OAAO,YAAY,SAAiB,YAAY;CAEvD,MAAM,GAAG,SAAS,UAAU,gBACzB,SAAS;EACR,SAAS,IAAI;CACf,GACA,SACA,QACF;CAEA,gBAAgB;EACd,QAAQ,YAAY;CACtB,GAAG,CAAC,cAAc,OAAO,CAAC;CAE1B,OAAO,CAAC,OAAO,MAAM;AACvB"}
@@ -1,176 +0,0 @@
1
- const require_PacerProvider = require('../provider/PacerProvider.cjs');
2
- let preact_hooks = require("preact/hooks");
3
- let _tanstack_preact_store = require("@tanstack/preact-store");
4
- let _tanstack_pacer_queuer = require("@tanstack/pacer/queuer");
5
-
6
- //#region src/queuer/useQueuer.ts
7
- /**
8
- * A Preact hook that creates and manages a Queuer instance.
9
- *
10
- * This is a lower-level hook that provides direct access to the Queuer's functionality without
11
- * any built-in state management. This allows you to integrate it with any state management solution
12
- * you prefer (useState, Redux, Zustand, etc.) by utilizing the onItemsChange callback.
13
- *
14
- * For a hook with built-in state management, see useQueuedState.
15
- *
16
- * The Queuer extends the base Queue to add processing capabilities. Items are processed
17
- * synchronously in order, with optional delays between processing each item. The queuer includes
18
- * an internal tick mechanism that can be started and stopped, making it useful as a scheduler.
19
- * When started, it will process one item per tick, with an optional wait time between ticks.
20
- *
21
- * By default uses FIFO (First In First Out) behavior, but can be configured for LIFO
22
- * (Last In First Out) by specifying 'front' position when adding 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` HOC (Recommended for component tree subscriptions)**
30
- *
31
- * Use the `Subscribe` HOC 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 a re-render
38
- * at the hook level, optimizing performance by preventing unnecessary re-renders 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` HOC. This prevents unnecessary
43
- * re-renders and gives you full control over when your component updates.
44
- *
45
- * Available state properties:
46
- * - `executionCount`: Number of items that have been processed by the queuer
47
- * - `expirationCount`: Number of items that have been removed due to expiration
48
- * - `isEmpty`: Whether the queuer has no items to process
49
- * - `isFull`: Whether the queuer has reached its maximum capacity
50
- * - `isIdle`: Whether the queuer is not currently processing any items
51
- * - `isRunning`: Whether the queuer is active and will process items automatically
52
- * - `items`: Array of items currently waiting to be processed
53
- * - `itemTimestamps`: Timestamps when items were added for expiration tracking
54
- * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item
55
- * - `rejectionCount`: Number of items that have been rejected from being added
56
- * - `size`: Number of items currently in the queue
57
- * - `status`: Current processing status ('idle' | 'running' | 'stopped')
58
- *
59
- * ## Unmount behavior
60
- *
61
- * By default, the hook stops the queuer when the component unmounts.
62
- * Use the `onUnmount` option to customize this. For example, to flush pending items instead:
63
- *
64
- * ```tsx
65
- * const queue = useQueuer(fn, {
66
- * started: true,
67
- * wait: 1000,
68
- * onUnmount: (q) => q.flush()
69
- * });
70
- * ```
71
- *
72
- * @example
73
- * ```tsx
74
- * // Default behavior - no reactive state subscriptions
75
- * const queue = useQueuer(
76
- * (item) => console.log('Processing:', item),
77
- * { started: true, wait: 1000 }
78
- * );
79
- *
80
- * // Subscribe to state changes deep in component tree using Subscribe HOC
81
- * <queue.Subscribe selector={(state) => ({ size: state.size })}>
82
- * {({ size }) => (
83
- * <div>Queue Size: {size}</div>
84
- * )}
85
- * </queue.Subscribe>
86
- *
87
- * // Opt-in to re-render when queue size changes at hook level (optimized for displaying queue length)
88
- * const queue = useQueuer(
89
- * (item) => console.log('Processing:', item),
90
- * { started: true, wait: 1000 },
91
- * (state) => ({
92
- * size: state.size,
93
- * isEmpty: state.isEmpty,
94
- * isFull: state.isFull
95
- * })
96
- * );
97
- *
98
- * // Opt-in to re-render when processing state changes (optimized for loading indicators)
99
- * const queue = useQueuer(
100
- * (item) => console.log('Processing:', item),
101
- * { started: true, wait: 1000 },
102
- * (state) => ({
103
- * isRunning: state.isRunning,
104
- * isIdle: state.isIdle,
105
- * status: state.status,
106
- * pendingTick: state.pendingTick
107
- * })
108
- * );
109
- *
110
- * // Opt-in to re-render when execution metrics change (optimized for stats display)
111
- * const queue = useQueuer(
112
- * (item) => console.log('Processing:', item),
113
- * { started: true, wait: 1000 },
114
- * (state) => ({
115
- * executionCount: state.executionCount,
116
- * expirationCount: state.expirationCount,
117
- * rejectionCount: state.rejectionCount
118
- * })
119
- * );
120
- *
121
- * // Example with custom state management and scheduling
122
- * const [items, setItems] = useState([]);
123
- *
124
- * const queue = useQueuer(
125
- * (item) => console.log('Processing:', item),
126
- * {
127
- * started: true, // Start processing immediately
128
- * wait: 1000, // Process one item every second
129
- * onItemsChange: (queue) => setItems(queue.peekAllItems()),
130
- * getPriority: (item) => item.priority // Process higher priority items first
131
- * }
132
- * );
133
- *
134
- * // Add items to process - they'll be handled automatically
135
- * queue.addItem('task1');
136
- * queue.addItem('task2');
137
- *
138
- * // Control the scheduler
139
- * queue.stop(); // Pause processing
140
- * queue.start(); // Resume processing
141
- *
142
- * // Access the selected state (will be empty object {} unless selector provided)
143
- * const { size, isRunning, executionCount } = queue.state;
144
- * ```
145
- */
146
- function useQueuer(fn, options = {}, selector = () => ({})) {
147
- const mergedOptions = {
148
- ...require_PacerProvider.useDefaultPacerOptions().queuer,
149
- ...options
150
- };
151
- const [queuer] = (0, preact_hooks.useState)(() => {
152
- const queuerInstance = new _tanstack_pacer_queuer.Queuer(fn, mergedOptions);
153
- queuerInstance.Subscribe = function Subscribe(props) {
154
- const selected = (0, _tanstack_preact_store.useSelector)(queuerInstance.store, props.selector, { compare: _tanstack_preact_store.shallow });
155
- return typeof props.children === "function" ? props.children(selected) : props.children;
156
- };
157
- return queuerInstance;
158
- });
159
- queuer.fn = fn;
160
- queuer.setOptions(mergedOptions);
161
- (0, preact_hooks.useEffect)(() => {
162
- return () => {
163
- if (mergedOptions.onUnmount) mergedOptions.onUnmount(queuer);
164
- else queuer.stop();
165
- };
166
- }, []);
167
- const state = (0, _tanstack_preact_store.useSelector)(queuer.store, selector, { compare: _tanstack_preact_store.shallow });
168
- return (0, preact_hooks.useMemo)(() => ({
169
- ...queuer,
170
- state
171
- }), [queuer, state]);
172
- }
173
-
174
- //#endregion
175
- exports.useQueuer = useQueuer;
176
- //# sourceMappingURL=useQueuer.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useQueuer.cjs","names":["useDefaultPacerOptions","useState","Queuer","useSelector","shallow","useMemo"],"sources":["../../src/queuer/useQueuer.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'preact/hooks'\nimport { Queuer } from '@tanstack/pacer/queuer'\nimport { shallow, useSelector } from '@tanstack/preact-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/preact-store'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\nimport type { ComponentChildren } from 'preact'\n\nexport interface PreactQueuerOptions<\n TValue,\n TSelected = {},\n> extends QueuerOptions<TValue> {\n /**\n * Optional callback invoked when the 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: PreactQueuer<TValue, TSelected>) => void\n}\n\nexport interface PreactQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * A Preact HOC (Higher Order Component) that allows you to subscribe to the queuer state.\n *\n * This is useful for opting into state re-renders for 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 })}>\n * {({ size }) => (\n * <div>Queue Size: {size}</div>\n * )}\n * </queuer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) => ComponentChildren\n /**\n * Reactive state that will be updated and re-rendered when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: 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 * A Preact hook that creates and manages a Queuer instance.\n *\n * This is a lower-level hook that provides direct access to the Queuer's functionality without\n * any built-in state management. This allows you to integrate it with any state management solution\n * you prefer (useState, Redux, Zustand, etc.) by utilizing the onItemsChange callback.\n *\n * For a hook with built-in state management, see useQueuedState.\n *\n * The Queuer extends the base Queue to add processing capabilities. Items are processed\n * synchronously in order, with optional delays between processing each item. The queuer includes\n * an internal tick mechanism that can be started and stopped, making it useful as a scheduler.\n * When started, it will process one item per tick, with an optional wait time between ticks.\n *\n * By default uses FIFO (First In First Out) behavior, but can be configured for LIFO\n * (Last In First Out) by specifying 'front' position when adding 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` HOC (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` HOC 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 a re-render\n * at the hook level, optimizing performance by preventing unnecessary re-renders 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` HOC. This prevents unnecessary\n * re-renders and gives you full control over when your component updates.\n *\n * Available 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 * ## Unmount behavior\n *\n * By default, the hook stops the queuer when the component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending items instead:\n *\n * ```tsx\n * const queue = useQueuer(fn, {\n * started: true,\n * wait: 1000,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const queue = useQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 }\n * );\n *\n * // Subscribe to state changes deep in component tree using Subscribe HOC\n * <queue.Subscribe selector={(state) => ({ size: state.size })}>\n * {({ size }) => (\n * <div>Queue Size: {size}</div>\n * )}\n * </queue.Subscribe>\n *\n * // Opt-in to re-render when queue size changes at hook level (optimized for displaying queue length)\n * const queue = useQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * size: state.size,\n * isEmpty: state.isEmpty,\n * isFull: state.isFull\n * })\n * );\n *\n * // Opt-in to re-render when processing state changes (optimized for loading indicators)\n * const queue = useQueuer(\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 re-render when execution metrics change (optimized for stats display)\n * const queue = useQueuer(\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 * // Example with custom state management and scheduling\n * const [items, setItems] = useState([]);\n *\n * const queue = useQueuer(\n * (item) => console.log('Processing:', item),\n * {\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * onItemsChange: (queue) => setItems(queue.peekAllItems()),\n * getPriority: (item) => item.priority // Process higher priority items first\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 { size, isRunning, executionCount } = queue.state;\n * ```\n */\nexport function useQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: PreactQueuerOptions<TValue, TSelected> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): PreactQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().queuer,\n ...options,\n } as PreactQueuerOptions<TValue, TSelected>\n\n const [queuer] = useState(() => {\n const queuerInstance = new Queuer<TValue>(\n fn,\n mergedOptions,\n ) as unknown as PreactQueuer<TValue, TSelected>\n\n queuerInstance.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) {\n const selected = useSelector(queuerInstance.store, props.selector, {\n compare: shallow,\n })\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n return queuerInstance\n })\n\n queuer.fn = fn\n queuer.setOptions(mergedOptions)\n\n /* eslint-disable react-hooks/exhaustive-deps -- cleanup only; runs on unmount */\n useEffect(() => {\n return () => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(queuer)\n } else {\n queuer.stop()\n }\n }\n }, [])\n /* eslint-enable react-hooks/exhaustive-deps */\n\n const state = useSelector(queuer.store, selector, { compare: shallow })\n\n return useMemo(\n () =>\n ({\n ...queuer,\n state,\n }) as PreactQueuer<TValue, TSelected>, // omit `store` in favor of `state`\n [queuer, state],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiMA,SAAgB,UACd,IACA,UAAkD,CAAC,GACnD,kBAA6D,CAAC,IAC7B;CACjC,MAAM,gBAAgB;EACpB,GAAGA,6CAAuB,CAAC,CAAC;EAC5B,GAAG;CACL;CAEA,MAAM,CAAC,cAAUC,6BAAe;EAC9B,MAAM,iBAAiB,IAAIC,8BACzB,IACA,aACF;EAEA,eAAe,YAAY,SAAS,UAAqB,OAGtD;GACD,MAAM,eAAWC,oCAAY,eAAe,OAAO,MAAM,UAAU,EACjE,SAASC,+BACX,CAAC;GAED,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,QAAQ,IACvB,MAAM;EACZ;EAEA,OAAO;CACT,CAAC;CAED,OAAO,KAAK;CACZ,OAAO,WAAW,aAAa;CAG/B,kCAAgB;EACd,aAAa;GACX,IAAI,cAAc,WAChB,cAAc,UAAU,MAAM;QAE9B,OAAO,KAAK;EAEhB;CACF,GAAG,CAAC,CAAC;CAGL,MAAM,YAAQD,oCAAY,OAAO,OAAO,UAAU,EAAE,SAASC,+BAAQ,CAAC;CAEtE,WAAOC,6BAEF;EACC,GAAG;EACH;CACF,IACF,CAAC,QAAQ,KAAK,CAChB;AACF"}
@@ -1,185 +0,0 @@
1
- import { Store } from "@tanstack/preact-store";
2
- import { ComponentChildren } from "preact";
3
- import { Queuer, QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
4
- //#region src/queuer/useQueuer.d.ts
5
- interface PreactQueuerOptions<TValue, TSelected = {}> extends QueuerOptions<TValue> {
6
- /**
7
- * Optional callback invoked when the component unmounts. Receives the queuer instance.
8
- * When provided, replaces the default cleanup (stop); use it to call flush(), flushAsBatch(), stop(), add logging, etc.
9
- */
10
- onUnmount?: (queuer: PreactQueuer<TValue, TSelected>) => void;
11
- }
12
- interface PreactQueuer<TValue, TSelected = {}> extends Omit<Queuer<TValue>, 'store'> {
13
- /**
14
- * A Preact HOC (Higher Order Component) that allows you to subscribe to the queuer state.
15
- *
16
- * This is useful for opting into state re-renders for specific parts of the queuer state
17
- * deep in your component tree without needing to pass a selector to the hook.
18
- *
19
- * @example
20
- * <queuer.Subscribe selector={(state) => ({ size: state.size })}>
21
- * {({ size }) => (
22
- * <div>Queue Size: {size}</div>
23
- * )}
24
- * </queuer.Subscribe>
25
- */
26
- Subscribe: <TSelected>(props: {
27
- selector: (state: QueuerState<TValue>) => TSelected;
28
- children: ((state: TSelected) => ComponentChildren) | ComponentChildren;
29
- }) => ComponentChildren;
30
- /**
31
- * Reactive state that will be updated and re-rendered when the queuer state changes
32
- *
33
- * Use this instead of `queuer.store.state`
34
- */
35
- readonly state: Readonly<TSelected>;
36
- /**
37
- * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.
38
- * The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
39
- * Although, you can make the state reactive by using the `useSelector` in your own usage.
40
- */
41
- readonly store: Store<Readonly<QueuerState<TValue>>>;
42
- }
43
- /**
44
- * A Preact hook that creates and manages a Queuer instance.
45
- *
46
- * This is a lower-level hook that provides direct access to the Queuer's functionality without
47
- * any built-in state management. This allows you to integrate it with any state management solution
48
- * you prefer (useState, Redux, Zustand, etc.) by utilizing the onItemsChange callback.
49
- *
50
- * For a hook with built-in state management, see useQueuedState.
51
- *
52
- * The Queuer extends the base Queue to add processing capabilities. Items are processed
53
- * synchronously in order, with optional delays between processing each item. The queuer includes
54
- * an internal tick mechanism that can be started and stopped, making it useful as a scheduler.
55
- * When started, it will process one item per tick, with an optional wait time between ticks.
56
- *
57
- * By default uses FIFO (First In First Out) behavior, but can be configured for LIFO
58
- * (Last In First Out) by specifying 'front' position when adding items.
59
- *
60
- * ## State Management and Selector
61
- *
62
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
63
- * in two ways:
64
- *
65
- * **1. Using `queuer.Subscribe` HOC (Recommended for component tree subscriptions)**
66
- *
67
- * Use the `Subscribe` HOC to subscribe to state changes deep in your component tree without
68
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
69
- * in child components.
70
- *
71
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
72
- *
73
- * The `selector` parameter allows you to specify which state changes will trigger a re-render
74
- * at the hook level, optimizing performance by preventing unnecessary re-renders when irrelevant
75
- * state changes occur.
76
- *
77
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
78
- * tracking by providing a selector function or using the `Subscribe` HOC. This prevents unnecessary
79
- * re-renders and gives you full control over when your component updates.
80
- *
81
- * Available state properties:
82
- * - `executionCount`: Number of items that have been processed by the queuer
83
- * - `expirationCount`: Number of items that have been removed due to expiration
84
- * - `isEmpty`: Whether the queuer has no items to process
85
- * - `isFull`: Whether the queuer has reached its maximum capacity
86
- * - `isIdle`: Whether the queuer is not currently processing any items
87
- * - `isRunning`: Whether the queuer is active and will process items automatically
88
- * - `items`: Array of items currently waiting to be processed
89
- * - `itemTimestamps`: Timestamps when items were added for expiration tracking
90
- * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item
91
- * - `rejectionCount`: Number of items that have been rejected from being added
92
- * - `size`: Number of items currently in the queue
93
- * - `status`: Current processing status ('idle' | 'running' | 'stopped')
94
- *
95
- * ## Unmount behavior
96
- *
97
- * By default, the hook stops the queuer when the component unmounts.
98
- * Use the `onUnmount` option to customize this. For example, to flush pending items instead:
99
- *
100
- * ```tsx
101
- * const queue = useQueuer(fn, {
102
- * started: true,
103
- * wait: 1000,
104
- * onUnmount: (q) => q.flush()
105
- * });
106
- * ```
107
- *
108
- * @example
109
- * ```tsx
110
- * // Default behavior - no reactive state subscriptions
111
- * const queue = useQueuer(
112
- * (item) => console.log('Processing:', item),
113
- * { started: true, wait: 1000 }
114
- * );
115
- *
116
- * // Subscribe to state changes deep in component tree using Subscribe HOC
117
- * <queue.Subscribe selector={(state) => ({ size: state.size })}>
118
- * {({ size }) => (
119
- * <div>Queue Size: {size}</div>
120
- * )}
121
- * </queue.Subscribe>
122
- *
123
- * // Opt-in to re-render when queue size changes at hook level (optimized for displaying queue length)
124
- * const queue = useQueuer(
125
- * (item) => console.log('Processing:', item),
126
- * { started: true, wait: 1000 },
127
- * (state) => ({
128
- * size: state.size,
129
- * isEmpty: state.isEmpty,
130
- * isFull: state.isFull
131
- * })
132
- * );
133
- *
134
- * // Opt-in to re-render when processing state changes (optimized for loading indicators)
135
- * const queue = useQueuer(
136
- * (item) => console.log('Processing:', item),
137
- * { started: true, wait: 1000 },
138
- * (state) => ({
139
- * isRunning: state.isRunning,
140
- * isIdle: state.isIdle,
141
- * status: state.status,
142
- * pendingTick: state.pendingTick
143
- * })
144
- * );
145
- *
146
- * // Opt-in to re-render when execution metrics change (optimized for stats display)
147
- * const queue = useQueuer(
148
- * (item) => console.log('Processing:', item),
149
- * { started: true, wait: 1000 },
150
- * (state) => ({
151
- * executionCount: state.executionCount,
152
- * expirationCount: state.expirationCount,
153
- * rejectionCount: state.rejectionCount
154
- * })
155
- * );
156
- *
157
- * // Example with custom state management and scheduling
158
- * const [items, setItems] = useState([]);
159
- *
160
- * const queue = useQueuer(
161
- * (item) => console.log('Processing:', item),
162
- * {
163
- * started: true, // Start processing immediately
164
- * wait: 1000, // Process one item every second
165
- * onItemsChange: (queue) => setItems(queue.peekAllItems()),
166
- * getPriority: (item) => item.priority // Process higher priority items first
167
- * }
168
- * );
169
- *
170
- * // Add items to process - they'll be handled automatically
171
- * queue.addItem('task1');
172
- * queue.addItem('task2');
173
- *
174
- * // Control the scheduler
175
- * queue.stop(); // Pause processing
176
- * queue.start(); // Resume processing
177
- *
178
- * // Access the selected state (will be empty object {} unless selector provided)
179
- * const { size, isRunning, executionCount } = queue.state;
180
- * ```
181
- */
182
- declare function useQueuer<TValue, TSelected = {}>(fn: (item: TValue) => void, options?: PreactQueuerOptions<TValue, TSelected>, selector?: (state: QueuerState<TValue>) => TSelected): PreactQueuer<TValue, TSelected>;
183
- //#endregion
184
- export { PreactQueuer, PreactQueuerOptions, useQueuer };
185
- //# sourceMappingURL=useQueuer.d.cts.map