@tanstack/preact-pacer 0.19.4 → 0.21.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 (199) hide show
  1. package/README.md +6 -6
  2. package/dist/async-batcher/index.cjs +1 -0
  3. package/dist/async-batcher/index.d.cts +2 -2
  4. package/dist/async-batcher/index.d.ts +2 -2
  5. package/dist/async-batcher/useAsyncBatchedCallback.cjs +2 -2
  6. package/dist/async-batcher/useAsyncBatchedCallback.cjs.map +1 -1
  7. package/dist/async-batcher/useAsyncBatchedCallback.d.cts +2 -3
  8. package/dist/async-batcher/useAsyncBatchedCallback.d.ts +2 -3
  9. package/dist/async-batcher/useAsyncBatchedCallback.js +2 -2
  10. package/dist/async-batcher/useAsyncBatchedCallback.js.map +1 -1
  11. package/dist/async-batcher/useAsyncBatcher.cjs +30 -2
  12. package/dist/async-batcher/useAsyncBatcher.cjs.map +1 -1
  13. package/dist/async-batcher/useAsyncBatcher.d.cts +28 -2
  14. package/dist/async-batcher/useAsyncBatcher.d.ts +28 -2
  15. package/dist/async-batcher/useAsyncBatcher.js +32 -4
  16. package/dist/async-batcher/useAsyncBatcher.js.map +1 -1
  17. package/dist/async-debouncer/index.cjs +1 -0
  18. package/dist/async-debouncer/index.d.cts +2 -2
  19. package/dist/async-debouncer/index.d.ts +2 -2
  20. package/dist/async-debouncer/useAsyncDebouncedCallback.cjs.map +1 -1
  21. package/dist/async-debouncer/useAsyncDebouncedCallback.d.cts +2 -2
  22. package/dist/async-debouncer/useAsyncDebouncedCallback.d.ts +2 -2
  23. package/dist/async-debouncer/useAsyncDebouncedCallback.js.map +1 -1
  24. package/dist/async-debouncer/useAsyncDebouncer.cjs +26 -4
  25. package/dist/async-debouncer/useAsyncDebouncer.cjs.map +1 -1
  26. package/dist/async-debouncer/useAsyncDebouncer.d.cts +28 -3
  27. package/dist/async-debouncer/useAsyncDebouncer.d.ts +27 -2
  28. package/dist/async-debouncer/useAsyncDebouncer.js +27 -5
  29. package/dist/async-debouncer/useAsyncDebouncer.js.map +1 -1
  30. package/dist/async-queuer/index.cjs +1 -0
  31. package/dist/async-queuer/index.d.cts +2 -2
  32. package/dist/async-queuer/index.d.ts +2 -2
  33. package/dist/async-queuer/useAsyncQueuedState.cjs.map +1 -1
  34. package/dist/async-queuer/useAsyncQueuedState.d.cts +3 -3
  35. package/dist/async-queuer/useAsyncQueuedState.d.ts +3 -3
  36. package/dist/async-queuer/useAsyncQueuedState.js.map +1 -1
  37. package/dist/async-queuer/useAsyncQueuer.cjs +30 -2
  38. package/dist/async-queuer/useAsyncQueuer.cjs.map +1 -1
  39. package/dist/async-queuer/useAsyncQueuer.d.cts +28 -2
  40. package/dist/async-queuer/useAsyncQueuer.d.ts +28 -2
  41. package/dist/async-queuer/useAsyncQueuer.js +32 -4
  42. package/dist/async-queuer/useAsyncQueuer.js.map +1 -1
  43. package/dist/async-rate-limiter/index.cjs +1 -0
  44. package/dist/async-rate-limiter/index.d.cts +2 -2
  45. package/dist/async-rate-limiter/index.d.ts +2 -2
  46. package/dist/async-rate-limiter/useAsyncRateLimitedCallback.cjs.map +1 -1
  47. package/dist/async-rate-limiter/useAsyncRateLimitedCallback.d.cts +2 -2
  48. package/dist/async-rate-limiter/useAsyncRateLimitedCallback.d.ts +2 -2
  49. package/dist/async-rate-limiter/useAsyncRateLimitedCallback.js.map +1 -1
  50. package/dist/async-rate-limiter/useAsyncRateLimiter.cjs +14 -2
  51. package/dist/async-rate-limiter/useAsyncRateLimiter.cjs.map +1 -1
  52. package/dist/async-rate-limiter/useAsyncRateLimiter.d.cts +15 -2
  53. package/dist/async-rate-limiter/useAsyncRateLimiter.d.ts +15 -2
  54. package/dist/async-rate-limiter/useAsyncRateLimiter.js +16 -4
  55. package/dist/async-rate-limiter/useAsyncRateLimiter.js.map +1 -1
  56. package/dist/async-throttler/index.cjs +1 -0
  57. package/dist/async-throttler/index.d.cts +2 -2
  58. package/dist/async-throttler/index.d.ts +2 -2
  59. package/dist/async-throttler/useAsyncThrottledCallback.cjs.map +1 -1
  60. package/dist/async-throttler/useAsyncThrottledCallback.d.cts +2 -2
  61. package/dist/async-throttler/useAsyncThrottledCallback.d.ts +2 -2
  62. package/dist/async-throttler/useAsyncThrottledCallback.js.map +1 -1
  63. package/dist/async-throttler/useAsyncThrottler.cjs +28 -4
  64. package/dist/async-throttler/useAsyncThrottler.cjs.map +1 -1
  65. package/dist/async-throttler/useAsyncThrottler.d.cts +27 -2
  66. package/dist/async-throttler/useAsyncThrottler.d.ts +27 -2
  67. package/dist/async-throttler/useAsyncThrottler.js +29 -5
  68. package/dist/async-throttler/useAsyncThrottler.js.map +1 -1
  69. package/dist/batcher/index.cjs +1 -0
  70. package/dist/batcher/index.d.cts +2 -2
  71. package/dist/batcher/index.d.ts +2 -2
  72. package/dist/batcher/useBatchedCallback.cjs +1 -1
  73. package/dist/batcher/useBatchedCallback.cjs.map +1 -1
  74. package/dist/batcher/useBatchedCallback.d.cts +2 -3
  75. package/dist/batcher/useBatchedCallback.d.ts +2 -3
  76. package/dist/batcher/useBatchedCallback.js +1 -1
  77. package/dist/batcher/useBatchedCallback.js.map +1 -1
  78. package/dist/batcher/useBatcher.cjs +21 -2
  79. package/dist/batcher/useBatcher.cjs.map +1 -1
  80. package/dist/batcher/useBatcher.d.cts +22 -2
  81. package/dist/batcher/useBatcher.d.ts +22 -2
  82. package/dist/batcher/useBatcher.js +23 -4
  83. package/dist/batcher/useBatcher.js.map +1 -1
  84. package/dist/debouncer/index.cjs +1 -0
  85. package/dist/debouncer/index.d.cts +2 -2
  86. package/dist/debouncer/index.d.ts +2 -2
  87. package/dist/debouncer/useDebouncedCallback.cjs.map +1 -1
  88. package/dist/debouncer/useDebouncedCallback.d.cts +2 -2
  89. package/dist/debouncer/useDebouncedCallback.d.ts +2 -2
  90. package/dist/debouncer/useDebouncedCallback.js.map +1 -1
  91. package/dist/debouncer/useDebouncedState.cjs.map +1 -1
  92. package/dist/debouncer/useDebouncedState.d.cts +3 -3
  93. package/dist/debouncer/useDebouncedState.d.ts +3 -3
  94. package/dist/debouncer/useDebouncedState.js.map +1 -1
  95. package/dist/debouncer/useDebouncedValue.cjs.map +1 -1
  96. package/dist/debouncer/useDebouncedValue.d.cts +3 -3
  97. package/dist/debouncer/useDebouncedValue.d.ts +3 -3
  98. package/dist/debouncer/useDebouncedValue.js.map +1 -1
  99. package/dist/debouncer/useDebouncer.cjs +17 -4
  100. package/dist/debouncer/useDebouncer.cjs.map +1 -1
  101. package/dist/debouncer/useDebouncer.d.cts +21 -2
  102. package/dist/debouncer/useDebouncer.d.ts +21 -2
  103. package/dist/debouncer/useDebouncer.js +18 -5
  104. package/dist/debouncer/useDebouncer.js.map +1 -1
  105. package/dist/index.cjs +1 -0
  106. package/dist/index.d.cts +11 -11
  107. package/dist/index.d.ts +11 -11
  108. package/dist/provider/PacerProvider.cjs.map +1 -1
  109. package/dist/provider/PacerProvider.d.cts +2 -2
  110. package/dist/provider/PacerProvider.d.ts +2 -2
  111. package/dist/provider/PacerProvider.js.map +1 -1
  112. package/dist/provider/index.cjs +1 -0
  113. package/dist/queuer/index.cjs +1 -0
  114. package/dist/queuer/index.d.cts +2 -2
  115. package/dist/queuer/index.d.ts +2 -2
  116. package/dist/queuer/useQueuedState.cjs.map +1 -1
  117. package/dist/queuer/useQueuedState.d.cts +3 -3
  118. package/dist/queuer/useQueuedState.d.ts +3 -3
  119. package/dist/queuer/useQueuedState.js.map +1 -1
  120. package/dist/queuer/useQueuedValue.cjs.map +1 -1
  121. package/dist/queuer/useQueuedValue.d.cts +3 -3
  122. package/dist/queuer/useQueuedValue.d.ts +3 -3
  123. package/dist/queuer/useQueuedValue.js.map +1 -1
  124. package/dist/queuer/useQueuer.cjs +21 -2
  125. package/dist/queuer/useQueuer.cjs.map +1 -1
  126. package/dist/queuer/useQueuer.d.cts +22 -2
  127. package/dist/queuer/useQueuer.d.ts +22 -2
  128. package/dist/queuer/useQueuer.js +23 -4
  129. package/dist/queuer/useQueuer.js.map +1 -1
  130. package/dist/rate-limiter/index.cjs +1 -0
  131. package/dist/rate-limiter/index.d.cts +2 -2
  132. package/dist/rate-limiter/index.d.ts +2 -2
  133. package/dist/rate-limiter/useRateLimitedCallback.cjs.map +1 -1
  134. package/dist/rate-limiter/useRateLimitedCallback.d.cts +2 -2
  135. package/dist/rate-limiter/useRateLimitedCallback.d.ts +2 -2
  136. package/dist/rate-limiter/useRateLimitedCallback.js.map +1 -1
  137. package/dist/rate-limiter/useRateLimitedState.cjs.map +1 -1
  138. package/dist/rate-limiter/useRateLimitedState.d.cts +3 -3
  139. package/dist/rate-limiter/useRateLimitedState.d.ts +3 -3
  140. package/dist/rate-limiter/useRateLimitedState.js.map +1 -1
  141. package/dist/rate-limiter/useRateLimitedValue.cjs.map +1 -1
  142. package/dist/rate-limiter/useRateLimitedValue.d.cts +3 -3
  143. package/dist/rate-limiter/useRateLimitedValue.d.ts +3 -3
  144. package/dist/rate-limiter/useRateLimitedValue.js.map +1 -1
  145. package/dist/rate-limiter/useRateLimiter.cjs +7 -2
  146. package/dist/rate-limiter/useRateLimiter.cjs.map +1 -1
  147. package/dist/rate-limiter/useRateLimiter.d.cts +9 -2
  148. package/dist/rate-limiter/useRateLimiter.d.ts +9 -2
  149. package/dist/rate-limiter/useRateLimiter.js +9 -4
  150. package/dist/rate-limiter/useRateLimiter.js.map +1 -1
  151. package/dist/throttler/index.cjs +1 -0
  152. package/dist/throttler/index.d.cts +2 -2
  153. package/dist/throttler/index.d.ts +2 -2
  154. package/dist/throttler/useThrottledCallback.cjs.map +1 -1
  155. package/dist/throttler/useThrottledCallback.d.cts +2 -2
  156. package/dist/throttler/useThrottledCallback.d.ts +2 -2
  157. package/dist/throttler/useThrottledCallback.js.map +1 -1
  158. package/dist/throttler/useThrottledState.cjs.map +1 -1
  159. package/dist/throttler/useThrottledState.d.cts +3 -3
  160. package/dist/throttler/useThrottledState.d.ts +3 -3
  161. package/dist/throttler/useThrottledState.js.map +1 -1
  162. package/dist/throttler/useThrottledValue.cjs.map +1 -1
  163. package/dist/throttler/useThrottledValue.d.cts +3 -3
  164. package/dist/throttler/useThrottledValue.d.ts +3 -3
  165. package/dist/throttler/useThrottledValue.js.map +1 -1
  166. package/dist/throttler/useThrottler.cjs +17 -4
  167. package/dist/throttler/useThrottler.cjs.map +1 -1
  168. package/dist/throttler/useThrottler.d.cts +21 -2
  169. package/dist/throttler/useThrottler.d.ts +21 -2
  170. package/dist/throttler/useThrottler.js +18 -5
  171. package/dist/throttler/useThrottler.js.map +1 -1
  172. package/package.json +36 -35
  173. package/src/async-batcher/useAsyncBatchedCallback.ts +7 -8
  174. package/src/async-batcher/useAsyncBatcher.ts +51 -7
  175. package/src/async-debouncer/useAsyncDebouncedCallback.ts +2 -2
  176. package/src/async-debouncer/useAsyncDebouncer.ts +45 -8
  177. package/src/async-queuer/useAsyncQueuedState.ts +5 -5
  178. package/src/async-queuer/useAsyncQueuer.ts +51 -7
  179. package/src/async-rate-limiter/useAsyncRateLimitedCallback.ts +2 -2
  180. package/src/async-rate-limiter/useAsyncRateLimiter.ts +37 -6
  181. package/src/async-throttler/useAsyncThrottledCallback.ts +2 -2
  182. package/src/async-throttler/useAsyncThrottler.ts +47 -8
  183. package/src/batcher/useBatchedCallback.ts +6 -10
  184. package/src/batcher/useBatcher.ts +44 -6
  185. package/src/debouncer/useDebouncedCallback.ts +2 -2
  186. package/src/debouncer/useDebouncedState.ts +3 -6
  187. package/src/debouncer/useDebouncedValue.ts +3 -6
  188. package/src/debouncer/useDebouncer.ts +38 -8
  189. package/src/queuer/useQueuedState.ts +3 -3
  190. package/src/queuer/useQueuedValue.ts +3 -3
  191. package/src/queuer/useQueuer.ts +44 -6
  192. package/src/rate-limiter/useRateLimitedCallback.ts +2 -2
  193. package/src/rate-limiter/useRateLimitedState.ts +6 -6
  194. package/src/rate-limiter/useRateLimitedValue.ts +6 -6
  195. package/src/rate-limiter/useRateLimiter.ts +29 -7
  196. package/src/throttler/useThrottledCallback.ts +2 -2
  197. package/src/throttler/useThrottledState.ts +3 -6
  198. package/src/throttler/useThrottledValue.ts +3 -6
  199. package/src/throttler/useThrottler.ts +38 -8
@@ -3,6 +3,13 @@ import { Store } from "@tanstack/preact-store";
3
3
  import { Batcher, BatcherOptions, BatcherState } from "@tanstack/pacer/batcher";
4
4
 
5
5
  //#region src/batcher/useBatcher.d.ts
6
+ interface PreactBatcherOptions<TValue, TSelected = {}> extends BatcherOptions<TValue> {
7
+ /**
8
+ * Optional callback invoked when the component unmounts. Receives the batcher instance.
9
+ * When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.
10
+ */
11
+ onUnmount?: (batcher: PreactBatcher<TValue, TSelected>) => void;
12
+ }
6
13
  interface PreactBatcher<TValue, TSelected = {}> extends Omit<Batcher<TValue>, 'store'> {
7
14
  /**
8
15
  * A Preact HOC (Higher Order Component) that allows you to subscribe to the batcher state.
@@ -77,6 +84,19 @@ interface PreactBatcher<TValue, TSelected = {}> extends Omit<Batcher<TValue>, 's
77
84
  * - `status`: Current processing status ('idle' | 'pending')
78
85
  * - `totalItemsProcessed`: Total number of items processed across all batches
79
86
  *
87
+ * ## Unmount behavior
88
+ *
89
+ * By default, the hook cancels any pending batch when the component unmounts.
90
+ * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
91
+ *
92
+ * ```tsx
93
+ * const batcher = useBatcher(fn, {
94
+ * maxSize: 10,
95
+ * wait: 2000,
96
+ * onUnmount: (b) => b.flush()
97
+ * });
98
+ * ```
99
+ *
80
100
  * @example
81
101
  * ```tsx
82
102
  * // Default behavior - no reactive state subscriptions
@@ -149,7 +169,7 @@ interface PreactBatcher<TValue, TSelected = {}> extends Omit<Batcher<TValue>, 's
149
169
  * const { size, isPending } = batcher.state;
150
170
  * ```
151
171
  */
152
- declare function useBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => void, options?: BatcherOptions<TValue>, selector?: (state: BatcherState<TValue>) => TSelected): PreactBatcher<TValue, TSelected>;
172
+ declare function useBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => void, options?: PreactBatcherOptions<TValue, TSelected>, selector?: (state: BatcherState<TValue>) => TSelected): PreactBatcher<TValue, TSelected>;
153
173
  //#endregion
154
- export { PreactBatcher, useBatcher };
174
+ export { PreactBatcher, PreactBatcherOptions, useBatcher };
155
175
  //# sourceMappingURL=useBatcher.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { useDefaultPacerOptions } from "../provider/PacerProvider.js";
2
- import { useMemo, useState } from "preact/hooks";
3
- import { useStore } from "@tanstack/preact-store";
2
+ import { useEffect, useMemo, useState } from "preact/hooks";
3
+ import { shallow, useStore } from "@tanstack/preact-store";
4
4
  import { Batcher } from "@tanstack/pacer/batcher";
5
5
 
6
6
  //#region src/batcher/useBatcher.ts
@@ -47,6 +47,19 @@ import { Batcher } from "@tanstack/pacer/batcher";
47
47
  * - `status`: Current processing status ('idle' | 'pending')
48
48
  * - `totalItemsProcessed`: Total number of items processed across all batches
49
49
  *
50
+ * ## Unmount behavior
51
+ *
52
+ * By default, the hook cancels any pending batch when the component unmounts.
53
+ * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
54
+ *
55
+ * ```tsx
56
+ * const batcher = useBatcher(fn, {
57
+ * maxSize: 10,
58
+ * wait: 2000,
59
+ * onUnmount: (b) => b.flush()
60
+ * });
61
+ * ```
62
+ *
50
63
  * @example
51
64
  * ```tsx
52
65
  * // Default behavior - no reactive state subscriptions
@@ -127,14 +140,20 @@ function useBatcher(fn, options = {}, selector = () => ({})) {
127
140
  const [batcher] = useState(() => {
128
141
  const batcherInstance = new Batcher(fn, mergedOptions);
129
142
  batcherInstance.Subscribe = function Subscribe(props) {
130
- const selected = useStore(batcherInstance.store, props.selector);
143
+ const selected = useStore(batcherInstance.store, props.selector, { equal: shallow });
131
144
  return typeof props.children === "function" ? props.children(selected) : props.children;
132
145
  };
133
146
  return batcherInstance;
134
147
  });
135
148
  batcher.fn = fn;
136
149
  batcher.setOptions(mergedOptions);
137
- const state = useStore(batcher.store, selector);
150
+ useEffect(() => {
151
+ return () => {
152
+ if (mergedOptions.onUnmount) mergedOptions.onUnmount(batcher);
153
+ else batcher.cancel();
154
+ };
155
+ }, []);
156
+ const state = useStore(batcher.store, selector, { equal: shallow });
138
157
  return useMemo(() => ({
139
158
  ...batcher,
140
159
  state
@@ -1 +1 @@
1
- {"version":3,"file":"useBatcher.js","names":[],"sources":["../../src/batcher/useBatcher.ts"],"sourcesContent":["import { useMemo, useState } from 'preact/hooks'\nimport { Batcher } from '@tanstack/pacer/batcher'\nimport { useStore } from '@tanstack/preact-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/preact-store'\nimport type { BatcherOptions, BatcherState } from '@tanstack/pacer/batcher'\nimport type { ComponentChildren } from 'preact'\n\nexport interface PreactBatcher<TValue, TSelected = {}> extends Omit<\n Batcher<TValue>,\n 'store'\n> {\n /**\n * A Preact HOC (Higher Order Component) that allows you to subscribe to the batcher state.\n *\n * This is useful for opting into state re-renders for specific parts of the batcher state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <batcher.Subscribe selector={(state) => ({ size: state.size })}>\n * {({ size }) => (\n * <div>Batch Size: {size}</div>\n * )}\n * </batcher.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: BatcherState<TValue>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) => ComponentChildren\n /**\n * Reactive state that will be updated and re-rendered when the batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Readonly<TSelected>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<BatcherState<TValue>>>\n}\n\n/**\n * A Preact hook that creates and manages a Batcher instance.\n *\n * This is a lower-level hook that provides direct access to the Batcher'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 * The Batcher collects items and processes them in batches based on configurable conditions:\n * - Maximum batch size\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `batcher.Subscribe` 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 batch executions that have been completed\n * - `isEmpty`: Whether the batcher has no items to process\n * - `isPending`: Whether the batcher is waiting for the timeout to trigger batch processing\n * - `isRunning`: Whether the batcher is active and will process items automatically\n * - `items`: Array of items currently queued for batch processing\n * - `size`: Number of items currently in the batch queue\n * - `status`: Current processing status ('idle' | 'pending')\n * - `totalItemsProcessed`: Total number of items processed across all batches\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const batcher = useBatcher<number>(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 }\n * );\n *\n * // Subscribe to state changes deep in component tree using Subscribe HOC\n * <batcher.Subscribe selector={(state) => ({ size: state.size })}>\n * {({ size }) => (\n * <div>Batch Size: {size}</div>\n * )}\n * </batcher.Subscribe>\n *\n * // Opt-in to re-render when batch size changes at hook level (optimized for displaying queue size)\n * const batcher = useBatcher<number>(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({\n * size: state.size,\n * isEmpty: state.isEmpty\n * })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for stats display)\n * const batcher = useBatcher<number>(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * totalItemsProcessed: state.totalItemsProcessed\n * })\n * );\n *\n * // Opt-in to re-render when processing state changes (optimized for loading indicators)\n * const batcher = useBatcher<number>(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({\n * isPending: state.isPending,\n * isRunning: state.isRunning,\n * status: state.status\n * })\n * );\n *\n * // Example with custom state management and batching\n * const [items, setItems] = useState([]);\n *\n * const batcher = useBatcher<number>(\n * (items) => console.log('Processing batch:', items),\n * {\n * maxSize: 5,\n * wait: 2000,\n * onItemsChange: (batcher) => setItems(batcher.peekAllItems()),\n * getShouldExecute: (items) => items.length >= 3\n * }\n * );\n *\n * // Add items to batch - they'll be processed when conditions are met\n * batcher.addItem(1);\n * batcher.addItem(2);\n * batcher.addItem(3); // Triggers batch processing\n *\n * // Control the batcher\n * batcher.stop(); // Pause batching\n * batcher.start(); // Resume batching\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { size, isPending } = batcher.state;\n * ```\n */\nexport function useBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => void,\n options: BatcherOptions<TValue> = {},\n selector: (state: BatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): PreactBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().batcher,\n ...options,\n } as BatcherOptions<TValue>\n\n const [batcher] = useState(() => {\n const batcherInstance = new Batcher<TValue>(\n fn,\n mergedOptions,\n ) as unknown as PreactBatcher<TValue, TSelected>\n\n batcherInstance.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: BatcherState<TValue>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) {\n const selected = useStore(batcherInstance.store, props.selector)\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n return batcherInstance\n })\n\n batcher.fn = fn\n batcher.setOptions(mergedOptions)\n\n const state = useStore(batcher.store, selector)\n\n return useMemo(\n () =>\n ({\n ...batcher,\n state,\n }) as PreactBatcher<TValue, TSelected>, // omit `store` in favor of `state`\n [batcher, state],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8JA,SAAgB,WACd,IACA,UAAkC,EAAE,EACpC,kBACG,EAAE,GAC6B;CAClC,MAAM,gBAAgB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ;CAED,MAAM,CAAC,WAAW,eAAe;EAC/B,MAAM,kBAAkB,IAAI,QAC1B,IACA,cACD;AAED,kBAAgB,YAAY,SAAS,UAAqB,OAGvD;GACD,MAAM,WAAW,SAAS,gBAAgB,OAAO,MAAM,SAAS;AAEhE,UAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;AAGZ,SAAO;GACP;AAEF,SAAQ,KAAK;AACb,SAAQ,WAAW,cAAc;CAEjC,MAAM,QAAQ,SAAS,QAAQ,OAAO,SAAS;AAE/C,QAAO,eAEF;EACC,GAAG;EACH;EACD,GACH,CAAC,SAAS,MAAM,CACjB"}
1
+ {"version":3,"file":"useBatcher.js","names":[],"sources":["../../src/batcher/useBatcher.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'preact/hooks'\nimport { Batcher } from '@tanstack/pacer/batcher'\nimport { shallow, useStore } from '@tanstack/preact-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/preact-store'\nimport type { BatcherOptions, BatcherState } from '@tanstack/pacer/batcher'\nimport type { ComponentChildren } from 'preact'\n\nexport interface PreactBatcherOptions<\n TValue,\n TSelected = {},\n> extends BatcherOptions<TValue> {\n /**\n * Optional callback invoked when the component unmounts. Receives the batcher instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.\n */\n onUnmount?: (batcher: PreactBatcher<TValue, TSelected>) => void\n}\n\nexport interface PreactBatcher<TValue, TSelected = {}> extends Omit<\n Batcher<TValue>,\n 'store'\n> {\n /**\n * A Preact HOC (Higher Order Component) that allows you to subscribe to the batcher state.\n *\n * This is useful for opting into state re-renders for specific parts of the batcher state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <batcher.Subscribe selector={(state) => ({ size: state.size })}>\n * {({ size }) => (\n * <div>Batch Size: {size}</div>\n * )}\n * </batcher.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: BatcherState<TValue>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) => ComponentChildren\n /**\n * Reactive state that will be updated and re-rendered when the batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Readonly<TSelected>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<BatcherState<TValue>>>\n}\n\n/**\n * A Preact hook that creates and manages a Batcher instance.\n *\n * This is a lower-level hook that provides direct access to the Batcher'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 * The Batcher collects items and processes them in batches based on configurable conditions:\n * - Maximum batch size\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `batcher.Subscribe` 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 batch executions that have been completed\n * - `isEmpty`: Whether the batcher has no items to process\n * - `isPending`: Whether the batcher is waiting for the timeout to trigger batch processing\n * - `isRunning`: Whether the batcher is active and will process items automatically\n * - `items`: Array of items currently queued for batch processing\n * - `size`: Number of items currently in the batch queue\n * - `status`: Current processing status ('idle' | 'pending')\n * - `totalItemsProcessed`: Total number of items processed across all batches\n *\n * ## Unmount behavior\n *\n * By default, the hook cancels any pending batch when the component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```tsx\n * const batcher = useBatcher(fn, {\n * maxSize: 10,\n * wait: 2000,\n * onUnmount: (b) => b.flush()\n * });\n * ```\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const batcher = useBatcher<number>(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 }\n * );\n *\n * // Subscribe to state changes deep in component tree using Subscribe HOC\n * <batcher.Subscribe selector={(state) => ({ size: state.size })}>\n * {({ size }) => (\n * <div>Batch Size: {size}</div>\n * )}\n * </batcher.Subscribe>\n *\n * // Opt-in to re-render when batch size changes at hook level (optimized for displaying queue size)\n * const batcher = useBatcher<number>(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({\n * size: state.size,\n * isEmpty: state.isEmpty\n * })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for stats display)\n * const batcher = useBatcher<number>(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * totalItemsProcessed: state.totalItemsProcessed\n * })\n * );\n *\n * // Opt-in to re-render when processing state changes (optimized for loading indicators)\n * const batcher = useBatcher<number>(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({\n * isPending: state.isPending,\n * isRunning: state.isRunning,\n * status: state.status\n * })\n * );\n *\n * // Example with custom state management and batching\n * const [items, setItems] = useState([]);\n *\n * const batcher = useBatcher<number>(\n * (items) => console.log('Processing batch:', items),\n * {\n * maxSize: 5,\n * wait: 2000,\n * onItemsChange: (batcher) => setItems(batcher.peekAllItems()),\n * getShouldExecute: (items) => items.length >= 3\n * }\n * );\n *\n * // Add items to batch - they'll be processed when conditions are met\n * batcher.addItem(1);\n * batcher.addItem(2);\n * batcher.addItem(3); // Triggers batch processing\n *\n * // Control the batcher\n * batcher.stop(); // Pause batching\n * batcher.start(); // Resume batching\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { size, isPending } = batcher.state;\n * ```\n */\nexport function useBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => void,\n options: PreactBatcherOptions<TValue, TSelected> = {},\n selector: (state: BatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): PreactBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().batcher,\n ...options,\n } as PreactBatcherOptions<TValue, TSelected>\n\n const [batcher] = useState(() => {\n const batcherInstance = new Batcher<TValue>(\n fn,\n mergedOptions,\n ) as unknown as PreactBatcher<TValue, TSelected>\n\n batcherInstance.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: BatcherState<TValue>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) {\n const selected = useStore(batcherInstance.store, props.selector, {\n equal: shallow,\n })\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n return batcherInstance\n })\n\n batcher.fn = fn\n batcher.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(batcher)\n } else {\n batcher.cancel()\n }\n }\n }, [])\n /* eslint-enable react-hooks/exhaustive-deps */\n\n const state = useStore(batcher.store, selector, { equal: shallow })\n\n return useMemo(\n () =>\n ({\n ...batcher,\n state,\n }) as PreactBatcher<TValue, TSelected>, // omit `store` in favor of `state`\n [batcher, state],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsLA,SAAgB,WACd,IACA,UAAmD,EAAE,EACrD,kBACG,EAAE,GAC6B;CAClC,MAAM,gBAAgB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ;CAED,MAAM,CAAC,WAAW,eAAe;EAC/B,MAAM,kBAAkB,IAAI,QAC1B,IACA,cACD;AAED,kBAAgB,YAAY,SAAS,UAAqB,OAGvD;GACD,MAAM,WAAW,SAAS,gBAAgB,OAAO,MAAM,UAAU,EAC/D,OAAO,SACR,CAAC;AAEF,UAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;AAGZ,SAAO;GACP;AAEF,SAAQ,KAAK;AACb,SAAQ,WAAW,cAAc;AAGjC,iBAAgB;AACd,eAAa;AACX,OAAI,cAAc,UAChB,eAAc,UAAU,QAAQ;OAEhC,SAAQ,QAAQ;;IAGnB,EAAE,CAAC;CAGN,MAAM,QAAQ,SAAS,QAAQ,OAAO,UAAU,EAAE,OAAO,SAAS,CAAC;AAEnE,QAAO,eAEF;EACC,GAAG;EACH;EACD,GACH,CAAC,SAAS,MAAM,CACjB"}
@@ -1,3 +1,4 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1
2
  const require_useDebouncer = require('./useDebouncer.cjs');
2
3
  const require_useDebouncedCallback = require('./useDebouncedCallback.cjs');
3
4
  const require_useDebouncedState = require('./useDebouncedState.cjs');
@@ -1,6 +1,6 @@
1
+ import { PreactDebouncer, PreactDebouncerOptions, useDebouncer } from "./useDebouncer.cjs";
1
2
  import { useDebouncedCallback } from "./useDebouncedCallback.cjs";
2
- import { PreactDebouncer, useDebouncer } from "./useDebouncer.cjs";
3
3
  import { useDebouncedState } from "./useDebouncedState.cjs";
4
4
  import { useDebouncedValue } from "./useDebouncedValue.cjs";
5
5
  export * from "@tanstack/pacer/debouncer";
6
- export { PreactDebouncer, useDebouncedCallback, useDebouncedState, useDebouncedValue, useDebouncer };
6
+ export { PreactDebouncer, PreactDebouncerOptions, useDebouncedCallback, useDebouncedState, useDebouncedValue, useDebouncer };
@@ -1,6 +1,6 @@
1
+ import { PreactDebouncer, PreactDebouncerOptions, useDebouncer } from "./useDebouncer.js";
1
2
  import { useDebouncedCallback } from "./useDebouncedCallback.js";
2
- import { PreactDebouncer, useDebouncer } from "./useDebouncer.js";
3
3
  import { useDebouncedState } from "./useDebouncedState.js";
4
4
  import { useDebouncedValue } from "./useDebouncedValue.js";
5
5
  export * from "@tanstack/pacer/debouncer";
6
- export { PreactDebouncer, useDebouncedCallback, useDebouncedState, useDebouncedValue, useDebouncer };
6
+ export { PreactDebouncer, PreactDebouncerOptions, useDebouncedCallback, useDebouncedState, useDebouncedValue, useDebouncer };
@@ -1 +1 @@
1
- {"version":3,"file":"useDebouncedCallback.cjs","names":["useDebouncer"],"sources":["../../src/debouncer/useDebouncedCallback.ts"],"sourcesContent":["import { useCallback } from 'preact/hooks'\nimport { useDebouncer } from './useDebouncer'\nimport type { DebouncerOptions } from '@tanstack/pacer/debouncer'\nimport type { AnyFunction } from '@tanstack/pacer/types'\n\n/**\n * A Preact hook that creates a debounced version of a callback function.\n * This hook is essentially a wrapper around the basic `debounce` function\n * that is exported from `@tanstack/pacer`,\n * but optimized for Preact with reactive options and a stable function reference.\n *\n * The debounced function will only execute after the specified wait time has elapsed\n * since its last invocation. If called again before the wait time expires, the timer\n * resets and starts waiting again.\n *\n * This hook provides a simpler API compared to `useDebouncer`, making it ideal for basic\n * debouncing needs. However, it does not expose the underlying Debouncer instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - Custom useCallback dependencies\n *\n * Consider using the `useDebouncer` hook instead.\n *\n * @example\n * ```tsx\n * // Debounce a search handler\n * const handleSearch = useDebouncedCallback((query: string) => {\n * fetchSearchResults(query);\n * }, {\n * wait: 500 // Wait 500ms between executions\n * });\n *\n * // Use in an input\n * <input\n * type=\"search\"\n * onChange={(e) => handleSearch(e.target.value)}\n * />\n * ```\n */\nexport function useDebouncedCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: DebouncerOptions<TFn>,\n): (...args: Parameters<TFn>) => void {\n const debouncedFn = useDebouncer(fn, options).maybeExecute\n return useCallback(\n (...args: Parameters<TFn>) => debouncedFn(...args),\n [debouncedFn],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,qBACd,IACA,SACoC;CACpC,MAAM,cAAcA,kCAAa,IAAI,QAAQ,CAAC;AAC9C,uCACG,GAAG,SAA0B,YAAY,GAAG,KAAK,EAClD,CAAC,YAAY,CACd"}
1
+ {"version":3,"file":"useDebouncedCallback.cjs","names":["useDebouncer"],"sources":["../../src/debouncer/useDebouncedCallback.ts"],"sourcesContent":["import { useCallback } from 'preact/hooks'\nimport { useDebouncer } from './useDebouncer'\nimport type { PreactDebouncerOptions } from './useDebouncer'\nimport type { AnyFunction } from '@tanstack/pacer/types'\n\n/**\n * A Preact hook that creates a debounced version of a callback function.\n * This hook is essentially a wrapper around the basic `debounce` function\n * that is exported from `@tanstack/pacer`,\n * but optimized for Preact with reactive options and a stable function reference.\n *\n * The debounced function will only execute after the specified wait time has elapsed\n * since its last invocation. If called again before the wait time expires, the timer\n * resets and starts waiting again.\n *\n * This hook provides a simpler API compared to `useDebouncer`, making it ideal for basic\n * debouncing needs. However, it does not expose the underlying Debouncer instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - Custom useCallback dependencies\n *\n * Consider using the `useDebouncer` hook instead.\n *\n * @example\n * ```tsx\n * // Debounce a search handler\n * const handleSearch = useDebouncedCallback((query: string) => {\n * fetchSearchResults(query);\n * }, {\n * wait: 500 // Wait 500ms between executions\n * });\n *\n * // Use in an input\n * <input\n * type=\"search\"\n * onChange={(e) => handleSearch(e.target.value)}\n * />\n * ```\n */\nexport function useDebouncedCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: PreactDebouncerOptions<TFn, {}>,\n): (...args: Parameters<TFn>) => void {\n const debouncedFn = useDebouncer(fn, options).maybeExecute\n return useCallback(\n (...args: Parameters<TFn>) => debouncedFn(...args),\n [debouncedFn],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,qBACd,IACA,SACoC;CACpC,MAAM,cAAcA,kCAAa,IAAI,QAAQ,CAAC;AAC9C,uCACG,GAAG,SAA0B,YAAY,GAAG,KAAK,EAClD,CAAC,YAAY,CACd"}
@@ -1,5 +1,5 @@
1
+ import { PreactDebouncerOptions } from "./useDebouncer.cjs";
1
2
  import { AnyFunction } from "@tanstack/pacer/types";
2
- import { DebouncerOptions } from "@tanstack/pacer/debouncer";
3
3
 
4
4
  //#region src/debouncer/useDebouncedCallback.d.ts
5
5
  /**
@@ -38,7 +38,7 @@ import { DebouncerOptions } from "@tanstack/pacer/debouncer";
38
38
  * />
39
39
  * ```
40
40
  */
41
- declare function useDebouncedCallback<TFn extends AnyFunction>(fn: TFn, options: DebouncerOptions<TFn>): (...args: Parameters<TFn>) => void;
41
+ declare function useDebouncedCallback<TFn extends AnyFunction>(fn: TFn, options: PreactDebouncerOptions<TFn, {}>): (...args: Parameters<TFn>) => void;
42
42
  //#endregion
43
43
  export { useDebouncedCallback };
44
44
  //# sourceMappingURL=useDebouncedCallback.d.cts.map
@@ -1,4 +1,4 @@
1
- import { DebouncerOptions } from "@tanstack/pacer/debouncer";
1
+ import { PreactDebouncerOptions } from "./useDebouncer.js";
2
2
  import { AnyFunction } from "@tanstack/pacer/types";
3
3
 
4
4
  //#region src/debouncer/useDebouncedCallback.d.ts
@@ -38,7 +38,7 @@ import { AnyFunction } from "@tanstack/pacer/types";
38
38
  * />
39
39
  * ```
40
40
  */
41
- declare function useDebouncedCallback<TFn extends AnyFunction>(fn: TFn, options: DebouncerOptions<TFn>): (...args: Parameters<TFn>) => void;
41
+ declare function useDebouncedCallback<TFn extends AnyFunction>(fn: TFn, options: PreactDebouncerOptions<TFn, {}>): (...args: Parameters<TFn>) => void;
42
42
  //#endregion
43
43
  export { useDebouncedCallback };
44
44
  //# sourceMappingURL=useDebouncedCallback.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDebouncedCallback.js","names":[],"sources":["../../src/debouncer/useDebouncedCallback.ts"],"sourcesContent":["import { useCallback } from 'preact/hooks'\nimport { useDebouncer } from './useDebouncer'\nimport type { DebouncerOptions } from '@tanstack/pacer/debouncer'\nimport type { AnyFunction } from '@tanstack/pacer/types'\n\n/**\n * A Preact hook that creates a debounced version of a callback function.\n * This hook is essentially a wrapper around the basic `debounce` function\n * that is exported from `@tanstack/pacer`,\n * but optimized for Preact with reactive options and a stable function reference.\n *\n * The debounced function will only execute after the specified wait time has elapsed\n * since its last invocation. If called again before the wait time expires, the timer\n * resets and starts waiting again.\n *\n * This hook provides a simpler API compared to `useDebouncer`, making it ideal for basic\n * debouncing needs. However, it does not expose the underlying Debouncer instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - Custom useCallback dependencies\n *\n * Consider using the `useDebouncer` hook instead.\n *\n * @example\n * ```tsx\n * // Debounce a search handler\n * const handleSearch = useDebouncedCallback((query: string) => {\n * fetchSearchResults(query);\n * }, {\n * wait: 500 // Wait 500ms between executions\n * });\n *\n * // Use in an input\n * <input\n * type=\"search\"\n * onChange={(e) => handleSearch(e.target.value)}\n * />\n * ```\n */\nexport function useDebouncedCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: DebouncerOptions<TFn>,\n): (...args: Parameters<TFn>) => void {\n const debouncedFn = useDebouncer(fn, options).maybeExecute\n return useCallback(\n (...args: Parameters<TFn>) => debouncedFn(...args),\n [debouncedFn],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,qBACd,IACA,SACoC;CACpC,MAAM,cAAc,aAAa,IAAI,QAAQ,CAAC;AAC9C,QAAO,aACJ,GAAG,SAA0B,YAAY,GAAG,KAAK,EAClD,CAAC,YAAY,CACd"}
1
+ {"version":3,"file":"useDebouncedCallback.js","names":[],"sources":["../../src/debouncer/useDebouncedCallback.ts"],"sourcesContent":["import { useCallback } from 'preact/hooks'\nimport { useDebouncer } from './useDebouncer'\nimport type { PreactDebouncerOptions } from './useDebouncer'\nimport type { AnyFunction } from '@tanstack/pacer/types'\n\n/**\n * A Preact hook that creates a debounced version of a callback function.\n * This hook is essentially a wrapper around the basic `debounce` function\n * that is exported from `@tanstack/pacer`,\n * but optimized for Preact with reactive options and a stable function reference.\n *\n * The debounced function will only execute after the specified wait time has elapsed\n * since its last invocation. If called again before the wait time expires, the timer\n * resets and starts waiting again.\n *\n * This hook provides a simpler API compared to `useDebouncer`, making it ideal for basic\n * debouncing needs. However, it does not expose the underlying Debouncer instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - Custom useCallback dependencies\n *\n * Consider using the `useDebouncer` hook instead.\n *\n * @example\n * ```tsx\n * // Debounce a search handler\n * const handleSearch = useDebouncedCallback((query: string) => {\n * fetchSearchResults(query);\n * }, {\n * wait: 500 // Wait 500ms between executions\n * });\n *\n * // Use in an input\n * <input\n * type=\"search\"\n * onChange={(e) => handleSearch(e.target.value)}\n * />\n * ```\n */\nexport function useDebouncedCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: PreactDebouncerOptions<TFn, {}>,\n): (...args: Parameters<TFn>) => void {\n const debouncedFn = useDebouncer(fn, options).maybeExecute\n return useCallback(\n (...args: Parameters<TFn>) => debouncedFn(...args),\n [debouncedFn],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,qBACd,IACA,SACoC;CACpC,MAAM,cAAc,aAAa,IAAI,QAAQ,CAAC;AAC9C,QAAO,aACJ,GAAG,SAA0B,YAAY,GAAG,KAAK,EAClD,CAAC,YAAY,CACd"}
@@ -1 +1 @@
1
- {"version":3,"file":"useDebouncedState.cjs","names":["useDebouncer"],"sources":["../../src/debouncer/useDebouncedState.ts"],"sourcesContent":["import { useState } from 'preact/hooks'\nimport { useDebouncer } from './useDebouncer'\nimport type { Dispatch, StateUpdater } from 'preact/hooks'\nimport type { PreactDebouncer } from './useDebouncer'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\n/**\n * A Preact hook that creates a debounced state value, combining Preact's useState with debouncing functionality.\n * This hook provides both the current debounced value and methods to update it.\n *\n * The state value is only updated after the specified wait time has elapsed since the last update attempt.\n * If another update is attempted before the wait time expires, the timer resets and starts waiting again.\n * This is useful for handling frequent state updates that should be throttled, like search input values\n * or window resize dimensions.\n *\n * The hook returns a tuple containing:\n * - The current debounced value\n * - A function to update the debounced value\n * - The debouncer instance with additional control methods\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer 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 debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState('', {\n * wait: 500 // Wait 500ms after last keystroke\n * });\n *\n * // Opt-in to re-render when pending state changes (optimized for loading indicators)\n * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState(\n * '',\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to re-render when execution count changes (optimized for tracking executions)\n * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState(\n * '',\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to re-render when debouncing status changes (optimized for status display)\n * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState(\n * '',\n * { wait: 500 },\n * (state) => ({\n * status: state.status,\n * canLeadingExecute: state.canLeadingExecute\n * })\n * );\n *\n * // Update value - will be debounced\n * const handleChange = (e) => {\n * setSearchTerm(e.target.value);\n * };\n *\n * // Access the selected debouncer state (will be empty object {} unless selector provided)\n * const { isPending, executionCount } = debouncer.state;\n * ```\n */\nexport function useDebouncedState<\n TValue,\n TSelected = DebouncerState<Dispatch<StateUpdater<TValue>>>,\n>(\n value: TValue,\n options: DebouncerOptions<Dispatch<StateUpdater<TValue>>>,\n selector?: (\n state: DebouncerState<Dispatch<StateUpdater<TValue>>>,\n ) => TSelected,\n): [\n TValue,\n Dispatch<StateUpdater<TValue>>,\n PreactDebouncer<Dispatch<StateUpdater<TValue>>, TSelected>,\n] {\n const [debouncedValue, setDebouncedValue] = useState(value)\n const debouncer = useDebouncer(\n setDebouncedValue,\n options,\n selector as (\n state: DebouncerState<Dispatch<StateUpdater<TValue>>>,\n ) => TSelected,\n )\n return [\n debouncedValue,\n debouncer.maybeExecute as Dispatch<StateUpdater<TValue>>,\n debouncer,\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,SAAgB,kBAId,OACA,SACA,UAOA;CACA,MAAM,CAAC,gBAAgB,gDAA8B,MAAM;CAC3D,MAAM,YAAYA,kCAChB,mBACA,SACA,SAGD;AACD,QAAO;EACL;EACA,UAAU;EACV;EACD"}
1
+ {"version":3,"file":"useDebouncedState.cjs","names":["useDebouncer"],"sources":["../../src/debouncer/useDebouncedState.ts"],"sourcesContent":["import { useState } from 'preact/hooks'\nimport { useDebouncer } from './useDebouncer'\nimport type { PreactDebouncer, PreactDebouncerOptions } from './useDebouncer'\nimport type { Dispatch, StateUpdater } from 'preact/hooks'\nimport type { DebouncerState } from '@tanstack/pacer/debouncer'\n\n/**\n * A Preact hook that creates a debounced state value, combining Preact's useState with debouncing functionality.\n * This hook provides both the current debounced value and methods to update it.\n *\n * The state value is only updated after the specified wait time has elapsed since the last update attempt.\n * If another update is attempted before the wait time expires, the timer resets and starts waiting again.\n * This is useful for handling frequent state updates that should be throttled, like search input values\n * or window resize dimensions.\n *\n * The hook returns a tuple containing:\n * - The current debounced value\n * - A function to update the debounced value\n * - The debouncer instance with additional control methods\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer 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 debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState('', {\n * wait: 500 // Wait 500ms after last keystroke\n * });\n *\n * // Opt-in to re-render when pending state changes (optimized for loading indicators)\n * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState(\n * '',\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to re-render when execution count changes (optimized for tracking executions)\n * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState(\n * '',\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to re-render when debouncing status changes (optimized for status display)\n * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState(\n * '',\n * { wait: 500 },\n * (state) => ({\n * status: state.status,\n * canLeadingExecute: state.canLeadingExecute\n * })\n * );\n *\n * // Update value - will be debounced\n * const handleChange = (e) => {\n * setSearchTerm(e.target.value);\n * };\n *\n * // Access the selected debouncer state (will be empty object {} unless selector provided)\n * const { isPending, executionCount } = debouncer.state;\n * ```\n */\nexport function useDebouncedState<\n TValue,\n TSelected = DebouncerState<Dispatch<StateUpdater<TValue>>>,\n>(\n value: TValue,\n options: PreactDebouncerOptions<Dispatch<StateUpdater<TValue>>, TSelected>,\n selector?: (\n state: DebouncerState<Dispatch<StateUpdater<TValue>>>,\n ) => TSelected,\n): [\n TValue,\n Dispatch<StateUpdater<TValue>>,\n PreactDebouncer<Dispatch<StateUpdater<TValue>>, TSelected>,\n] {\n const [debouncedValue, setDebouncedValue] = useState(value)\n const debouncer = useDebouncer(\n setDebouncedValue,\n options,\n selector as (\n state: DebouncerState<Dispatch<StateUpdater<TValue>>>,\n ) => TSelected,\n )\n return [\n debouncedValue,\n debouncer.maybeExecute as Dispatch<StateUpdater<TValue>>,\n debouncer,\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8EA,SAAgB,kBAId,OACA,SACA,UAOA;CACA,MAAM,CAAC,gBAAgB,gDAA8B,MAAM;CAC3D,MAAM,YAAYA,kCAChB,mBACA,SACA,SAGD;AACD,QAAO;EACL;EACA,UAAU;EACV;EACD"}
@@ -1,5 +1,5 @@
1
- import { PreactDebouncer } from "./useDebouncer.cjs";
2
- import { DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
1
+ import { PreactDebouncer, PreactDebouncerOptions } from "./useDebouncer.cjs";
2
+ import { DebouncerState } from "@tanstack/pacer/debouncer";
3
3
  import { Dispatch, StateUpdater } from "preact/hooks";
4
4
 
5
5
  //#region src/debouncer/useDebouncedState.d.ts
@@ -75,7 +75,7 @@ import { Dispatch, StateUpdater } from "preact/hooks";
75
75
  * const { isPending, executionCount } = debouncer.state;
76
76
  * ```
77
77
  */
78
- declare function useDebouncedState<TValue, TSelected = DebouncerState<Dispatch<StateUpdater<TValue>>>>(value: TValue, options: DebouncerOptions<Dispatch<StateUpdater<TValue>>>, selector?: (state: DebouncerState<Dispatch<StateUpdater<TValue>>>) => TSelected): [TValue, Dispatch<StateUpdater<TValue>>, PreactDebouncer<Dispatch<StateUpdater<TValue>>, TSelected>];
78
+ declare function useDebouncedState<TValue, TSelected = DebouncerState<Dispatch<StateUpdater<TValue>>>>(value: TValue, options: PreactDebouncerOptions<Dispatch<StateUpdater<TValue>>, TSelected>, selector?: (state: DebouncerState<Dispatch<StateUpdater<TValue>>>) => TSelected): [TValue, Dispatch<StateUpdater<TValue>>, PreactDebouncer<Dispatch<StateUpdater<TValue>>, TSelected>];
79
79
  //#endregion
80
80
  export { useDebouncedState };
81
81
  //# sourceMappingURL=useDebouncedState.d.cts.map
@@ -1,6 +1,6 @@
1
- import { PreactDebouncer } from "./useDebouncer.js";
1
+ import { PreactDebouncer, PreactDebouncerOptions } from "./useDebouncer.js";
2
2
  import { Dispatch, StateUpdater } from "preact/hooks";
3
- import { DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
3
+ import { DebouncerState } from "@tanstack/pacer/debouncer";
4
4
 
5
5
  //#region src/debouncer/useDebouncedState.d.ts
6
6
  /**
@@ -75,7 +75,7 @@ import { DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
75
75
  * const { isPending, executionCount } = debouncer.state;
76
76
  * ```
77
77
  */
78
- declare function useDebouncedState<TValue, TSelected = DebouncerState<Dispatch<StateUpdater<TValue>>>>(value: TValue, options: DebouncerOptions<Dispatch<StateUpdater<TValue>>>, selector?: (state: DebouncerState<Dispatch<StateUpdater<TValue>>>) => TSelected): [TValue, Dispatch<StateUpdater<TValue>>, PreactDebouncer<Dispatch<StateUpdater<TValue>>, TSelected>];
78
+ declare function useDebouncedState<TValue, TSelected = DebouncerState<Dispatch<StateUpdater<TValue>>>>(value: TValue, options: PreactDebouncerOptions<Dispatch<StateUpdater<TValue>>, TSelected>, selector?: (state: DebouncerState<Dispatch<StateUpdater<TValue>>>) => TSelected): [TValue, Dispatch<StateUpdater<TValue>>, PreactDebouncer<Dispatch<StateUpdater<TValue>>, TSelected>];
79
79
  //#endregion
80
80
  export { useDebouncedState };
81
81
  //# sourceMappingURL=useDebouncedState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDebouncedState.js","names":[],"sources":["../../src/debouncer/useDebouncedState.ts"],"sourcesContent":["import { useState } from 'preact/hooks'\nimport { useDebouncer } from './useDebouncer'\nimport type { Dispatch, StateUpdater } from 'preact/hooks'\nimport type { PreactDebouncer } from './useDebouncer'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\n/**\n * A Preact hook that creates a debounced state value, combining Preact's useState with debouncing functionality.\n * This hook provides both the current debounced value and methods to update it.\n *\n * The state value is only updated after the specified wait time has elapsed since the last update attempt.\n * If another update is attempted before the wait time expires, the timer resets and starts waiting again.\n * This is useful for handling frequent state updates that should be throttled, like search input values\n * or window resize dimensions.\n *\n * The hook returns a tuple containing:\n * - The current debounced value\n * - A function to update the debounced value\n * - The debouncer instance with additional control methods\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer 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 debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState('', {\n * wait: 500 // Wait 500ms after last keystroke\n * });\n *\n * // Opt-in to re-render when pending state changes (optimized for loading indicators)\n * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState(\n * '',\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to re-render when execution count changes (optimized for tracking executions)\n * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState(\n * '',\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to re-render when debouncing status changes (optimized for status display)\n * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState(\n * '',\n * { wait: 500 },\n * (state) => ({\n * status: state.status,\n * canLeadingExecute: state.canLeadingExecute\n * })\n * );\n *\n * // Update value - will be debounced\n * const handleChange = (e) => {\n * setSearchTerm(e.target.value);\n * };\n *\n * // Access the selected debouncer state (will be empty object {} unless selector provided)\n * const { isPending, executionCount } = debouncer.state;\n * ```\n */\nexport function useDebouncedState<\n TValue,\n TSelected = DebouncerState<Dispatch<StateUpdater<TValue>>>,\n>(\n value: TValue,\n options: DebouncerOptions<Dispatch<StateUpdater<TValue>>>,\n selector?: (\n state: DebouncerState<Dispatch<StateUpdater<TValue>>>,\n ) => TSelected,\n): [\n TValue,\n Dispatch<StateUpdater<TValue>>,\n PreactDebouncer<Dispatch<StateUpdater<TValue>>, TSelected>,\n] {\n const [debouncedValue, setDebouncedValue] = useState(value)\n const debouncer = useDebouncer(\n setDebouncedValue,\n options,\n selector as (\n state: DebouncerState<Dispatch<StateUpdater<TValue>>>,\n ) => TSelected,\n )\n return [\n debouncedValue,\n debouncer.maybeExecute as Dispatch<StateUpdater<TValue>>,\n debouncer,\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,SAAgB,kBAId,OACA,SACA,UAOA;CACA,MAAM,CAAC,gBAAgB,qBAAqB,SAAS,MAAM;CAC3D,MAAM,YAAY,aAChB,mBACA,SACA,SAGD;AACD,QAAO;EACL;EACA,UAAU;EACV;EACD"}
1
+ {"version":3,"file":"useDebouncedState.js","names":[],"sources":["../../src/debouncer/useDebouncedState.ts"],"sourcesContent":["import { useState } from 'preact/hooks'\nimport { useDebouncer } from './useDebouncer'\nimport type { PreactDebouncer, PreactDebouncerOptions } from './useDebouncer'\nimport type { Dispatch, StateUpdater } from 'preact/hooks'\nimport type { DebouncerState } from '@tanstack/pacer/debouncer'\n\n/**\n * A Preact hook that creates a debounced state value, combining Preact's useState with debouncing functionality.\n * This hook provides both the current debounced value and methods to update it.\n *\n * The state value is only updated after the specified wait time has elapsed since the last update attempt.\n * If another update is attempted before the wait time expires, the timer resets and starts waiting again.\n * This is useful for handling frequent state updates that should be throttled, like search input values\n * or window resize dimensions.\n *\n * The hook returns a tuple containing:\n * - The current debounced value\n * - A function to update the debounced value\n * - The debouncer instance with additional control methods\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer 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 debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState('', {\n * wait: 500 // Wait 500ms after last keystroke\n * });\n *\n * // Opt-in to re-render when pending state changes (optimized for loading indicators)\n * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState(\n * '',\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to re-render when execution count changes (optimized for tracking executions)\n * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState(\n * '',\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to re-render when debouncing status changes (optimized for status display)\n * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState(\n * '',\n * { wait: 500 },\n * (state) => ({\n * status: state.status,\n * canLeadingExecute: state.canLeadingExecute\n * })\n * );\n *\n * // Update value - will be debounced\n * const handleChange = (e) => {\n * setSearchTerm(e.target.value);\n * };\n *\n * // Access the selected debouncer state (will be empty object {} unless selector provided)\n * const { isPending, executionCount } = debouncer.state;\n * ```\n */\nexport function useDebouncedState<\n TValue,\n TSelected = DebouncerState<Dispatch<StateUpdater<TValue>>>,\n>(\n value: TValue,\n options: PreactDebouncerOptions<Dispatch<StateUpdater<TValue>>, TSelected>,\n selector?: (\n state: DebouncerState<Dispatch<StateUpdater<TValue>>>,\n ) => TSelected,\n): [\n TValue,\n Dispatch<StateUpdater<TValue>>,\n PreactDebouncer<Dispatch<StateUpdater<TValue>>, TSelected>,\n] {\n const [debouncedValue, setDebouncedValue] = useState(value)\n const debouncer = useDebouncer(\n setDebouncedValue,\n options,\n selector as (\n state: DebouncerState<Dispatch<StateUpdater<TValue>>>,\n ) => TSelected,\n )\n return [\n debouncedValue,\n debouncer.maybeExecute as Dispatch<StateUpdater<TValue>>,\n debouncer,\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8EA,SAAgB,kBAId,OACA,SACA,UAOA;CACA,MAAM,CAAC,gBAAgB,qBAAqB,SAAS,MAAM;CAC3D,MAAM,YAAY,aAChB,mBACA,SACA,SAGD;AACD,QAAO;EACL;EACA,UAAU;EACV;EACD"}
@@ -1 +1 @@
1
- {"version":3,"file":"useDebouncedValue.cjs","names":["useDebouncedState"],"sources":["../../src/debouncer/useDebouncedValue.ts"],"sourcesContent":["import { useEffect } from 'preact/hooks'\nimport { useDebouncedState } from './useDebouncedState'\nimport type { Dispatch, StateUpdater } from 'preact/hooks'\nimport type { PreactDebouncer } from './useDebouncer'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\n/**\n * A Preact hook that creates a debounced value that updates only after a specified delay.\n * Unlike useDebouncedState, this hook automatically tracks changes to the input value\n * and updates the debounced value accordingly.\n *\n * The debounced value will only update after the specified wait time has elapsed since\n * the last change to the input value. If the input value changes again before the wait\n * time expires, the timer resets and starts waiting again.\n *\n * This is useful for deriving debounced values from props or state that change frequently,\n * like search queries or form inputs, where you want to limit how often downstream effects\n * or calculations occur.\n *\n * The hook returns the current debounced value and the underlying debouncer instance.\n * The debouncer instance can be used to access additional functionality like cancellation\n * and execution counts.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer 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 debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [searchQuery, setSearchQuery] = useState('');\n * const [debouncedQuery, debouncer] = useDebouncedValue(searchQuery, {\n * wait: 500 // Wait 500ms after last change\n * });\n *\n * // Opt-in to re-render when pending state changes (optimized for loading indicators)\n * const [debouncedQuery, debouncer] = useDebouncedValue(\n * searchQuery,\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to re-render when execution count changes (optimized for tracking executions)\n * const [debouncedQuery, debouncer] = useDebouncedValue(\n * searchQuery,\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to re-render when debouncing status changes (optimized for status display)\n * const [debouncedQuery, debouncer] = useDebouncedValue(\n * searchQuery,\n * { wait: 500 },\n * (state) => ({\n * status: state.status,\n * canLeadingExecute: state.canLeadingExecute\n * })\n * );\n *\n * // debouncedQuery will update 500ms after searchQuery stops changing\n * useEffect(() => {\n * fetchSearchResults(debouncedQuery);\n * }, [debouncedQuery]);\n *\n * // Handle input changes\n * const handleChange = (e) => {\n * setSearchQuery(e.target.value);\n * };\n *\n * // Access the selected debouncer state (will be empty object {} unless selector provided)\n * const { isPending, executionCount } = debouncer.state;\n * ```\n */\nexport function useDebouncedValue<\n TValue,\n TSelected = DebouncerState<Dispatch<StateUpdater<TValue>>>,\n>(\n value: TValue,\n options: DebouncerOptions<Dispatch<StateUpdater<TValue>>>,\n selector?: (\n state: DebouncerState<Dispatch<StateUpdater<TValue>>>,\n ) => TSelected,\n): [TValue, PreactDebouncer<Dispatch<StateUpdater<TValue>>, TSelected>] {\n const [debouncedValue, setDebouncedValue, debouncer] = useDebouncedState(\n value,\n options,\n selector,\n )\n\n useEffect(() => {\n ;(setDebouncedValue as (value: TValue) => void)(value)\n }, [value, setDebouncedValue])\n\n return [debouncedValue, debouncer]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0FA,SAAgB,kBAId,OACA,SACA,UAGsE;CACtE,MAAM,CAAC,gBAAgB,mBAAmB,aAAaA,4CACrD,OACA,SACA,SACD;AAED,mCAAgB;AACb,EAAC,kBAA8C,MAAM;IACrD,CAAC,OAAO,kBAAkB,CAAC;AAE9B,QAAO,CAAC,gBAAgB,UAAU"}
1
+ {"version":3,"file":"useDebouncedValue.cjs","names":["useDebouncedState"],"sources":["../../src/debouncer/useDebouncedValue.ts"],"sourcesContent":["import { useEffect } from 'preact/hooks'\nimport { useDebouncedState } from './useDebouncedState'\nimport type { PreactDebouncer, PreactDebouncerOptions } from './useDebouncer'\nimport type { Dispatch, StateUpdater } from 'preact/hooks'\nimport type { DebouncerState } from '@tanstack/pacer/debouncer'\n\n/**\n * A Preact hook that creates a debounced value that updates only after a specified delay.\n * Unlike useDebouncedState, this hook automatically tracks changes to the input value\n * and updates the debounced value accordingly.\n *\n * The debounced value will only update after the specified wait time has elapsed since\n * the last change to the input value. If the input value changes again before the wait\n * time expires, the timer resets and starts waiting again.\n *\n * This is useful for deriving debounced values from props or state that change frequently,\n * like search queries or form inputs, where you want to limit how often downstream effects\n * or calculations occur.\n *\n * The hook returns the current debounced value and the underlying debouncer instance.\n * The debouncer instance can be used to access additional functionality like cancellation\n * and execution counts.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer 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 debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [searchQuery, setSearchQuery] = useState('');\n * const [debouncedQuery, debouncer] = useDebouncedValue(searchQuery, {\n * wait: 500 // Wait 500ms after last change\n * });\n *\n * // Opt-in to re-render when pending state changes (optimized for loading indicators)\n * const [debouncedQuery, debouncer] = useDebouncedValue(\n * searchQuery,\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to re-render when execution count changes (optimized for tracking executions)\n * const [debouncedQuery, debouncer] = useDebouncedValue(\n * searchQuery,\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to re-render when debouncing status changes (optimized for status display)\n * const [debouncedQuery, debouncer] = useDebouncedValue(\n * searchQuery,\n * { wait: 500 },\n * (state) => ({\n * status: state.status,\n * canLeadingExecute: state.canLeadingExecute\n * })\n * );\n *\n * // debouncedQuery will update 500ms after searchQuery stops changing\n * useEffect(() => {\n * fetchSearchResults(debouncedQuery);\n * }, [debouncedQuery]);\n *\n * // Handle input changes\n * const handleChange = (e) => {\n * setSearchQuery(e.target.value);\n * };\n *\n * // Access the selected debouncer state (will be empty object {} unless selector provided)\n * const { isPending, executionCount } = debouncer.state;\n * ```\n */\nexport function useDebouncedValue<\n TValue,\n TSelected = DebouncerState<Dispatch<StateUpdater<TValue>>>,\n>(\n value: TValue,\n options: PreactDebouncerOptions<Dispatch<StateUpdater<TValue>>, TSelected>,\n selector?: (\n state: DebouncerState<Dispatch<StateUpdater<TValue>>>,\n ) => TSelected,\n): [TValue, PreactDebouncer<Dispatch<StateUpdater<TValue>>, TSelected>] {\n const [debouncedValue, setDebouncedValue, debouncer] = useDebouncedState(\n value,\n options,\n selector,\n )\n\n useEffect(() => {\n ;(setDebouncedValue as (value: TValue) => void)(value)\n }, [value, setDebouncedValue])\n\n return [debouncedValue, debouncer]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuFA,SAAgB,kBAId,OACA,SACA,UAGsE;CACtE,MAAM,CAAC,gBAAgB,mBAAmB,aAAaA,4CACrD,OACA,SACA,SACD;AAED,mCAAgB;AACb,EAAC,kBAA8C,MAAM;IACrD,CAAC,OAAO,kBAAkB,CAAC;AAE9B,QAAO,CAAC,gBAAgB,UAAU"}
@@ -1,5 +1,5 @@
1
- import { PreactDebouncer } from "./useDebouncer.cjs";
2
- import { DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
1
+ import { PreactDebouncer, PreactDebouncerOptions } from "./useDebouncer.cjs";
2
+ import { DebouncerState } from "@tanstack/pacer/debouncer";
3
3
  import { Dispatch, StateUpdater } from "preact/hooks";
4
4
 
5
5
  //#region src/debouncer/useDebouncedValue.d.ts
@@ -84,7 +84,7 @@ import { Dispatch, StateUpdater } from "preact/hooks";
84
84
  * const { isPending, executionCount } = debouncer.state;
85
85
  * ```
86
86
  */
87
- declare function useDebouncedValue<TValue, TSelected = DebouncerState<Dispatch<StateUpdater<TValue>>>>(value: TValue, options: DebouncerOptions<Dispatch<StateUpdater<TValue>>>, selector?: (state: DebouncerState<Dispatch<StateUpdater<TValue>>>) => TSelected): [TValue, PreactDebouncer<Dispatch<StateUpdater<TValue>>, TSelected>];
87
+ declare function useDebouncedValue<TValue, TSelected = DebouncerState<Dispatch<StateUpdater<TValue>>>>(value: TValue, options: PreactDebouncerOptions<Dispatch<StateUpdater<TValue>>, TSelected>, selector?: (state: DebouncerState<Dispatch<StateUpdater<TValue>>>) => TSelected): [TValue, PreactDebouncer<Dispatch<StateUpdater<TValue>>, TSelected>];
88
88
  //#endregion
89
89
  export { useDebouncedValue };
90
90
  //# sourceMappingURL=useDebouncedValue.d.cts.map
@@ -1,6 +1,6 @@
1
- import { PreactDebouncer } from "./useDebouncer.js";
1
+ import { PreactDebouncer, PreactDebouncerOptions } from "./useDebouncer.js";
2
2
  import { Dispatch, StateUpdater } from "preact/hooks";
3
- import { DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
3
+ import { DebouncerState } from "@tanstack/pacer/debouncer";
4
4
 
5
5
  //#region src/debouncer/useDebouncedValue.d.ts
6
6
  /**
@@ -84,7 +84,7 @@ import { DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
84
84
  * const { isPending, executionCount } = debouncer.state;
85
85
  * ```
86
86
  */
87
- declare function useDebouncedValue<TValue, TSelected = DebouncerState<Dispatch<StateUpdater<TValue>>>>(value: TValue, options: DebouncerOptions<Dispatch<StateUpdater<TValue>>>, selector?: (state: DebouncerState<Dispatch<StateUpdater<TValue>>>) => TSelected): [TValue, PreactDebouncer<Dispatch<StateUpdater<TValue>>, TSelected>];
87
+ declare function useDebouncedValue<TValue, TSelected = DebouncerState<Dispatch<StateUpdater<TValue>>>>(value: TValue, options: PreactDebouncerOptions<Dispatch<StateUpdater<TValue>>, TSelected>, selector?: (state: DebouncerState<Dispatch<StateUpdater<TValue>>>) => TSelected): [TValue, PreactDebouncer<Dispatch<StateUpdater<TValue>>, TSelected>];
88
88
  //#endregion
89
89
  export { useDebouncedValue };
90
90
  //# sourceMappingURL=useDebouncedValue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDebouncedValue.js","names":[],"sources":["../../src/debouncer/useDebouncedValue.ts"],"sourcesContent":["import { useEffect } from 'preact/hooks'\nimport { useDebouncedState } from './useDebouncedState'\nimport type { Dispatch, StateUpdater } from 'preact/hooks'\nimport type { PreactDebouncer } from './useDebouncer'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\n/**\n * A Preact hook that creates a debounced value that updates only after a specified delay.\n * Unlike useDebouncedState, this hook automatically tracks changes to the input value\n * and updates the debounced value accordingly.\n *\n * The debounced value will only update after the specified wait time has elapsed since\n * the last change to the input value. If the input value changes again before the wait\n * time expires, the timer resets and starts waiting again.\n *\n * This is useful for deriving debounced values from props or state that change frequently,\n * like search queries or form inputs, where you want to limit how often downstream effects\n * or calculations occur.\n *\n * The hook returns the current debounced value and the underlying debouncer instance.\n * The debouncer instance can be used to access additional functionality like cancellation\n * and execution counts.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer 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 debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [searchQuery, setSearchQuery] = useState('');\n * const [debouncedQuery, debouncer] = useDebouncedValue(searchQuery, {\n * wait: 500 // Wait 500ms after last change\n * });\n *\n * // Opt-in to re-render when pending state changes (optimized for loading indicators)\n * const [debouncedQuery, debouncer] = useDebouncedValue(\n * searchQuery,\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to re-render when execution count changes (optimized for tracking executions)\n * const [debouncedQuery, debouncer] = useDebouncedValue(\n * searchQuery,\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to re-render when debouncing status changes (optimized for status display)\n * const [debouncedQuery, debouncer] = useDebouncedValue(\n * searchQuery,\n * { wait: 500 },\n * (state) => ({\n * status: state.status,\n * canLeadingExecute: state.canLeadingExecute\n * })\n * );\n *\n * // debouncedQuery will update 500ms after searchQuery stops changing\n * useEffect(() => {\n * fetchSearchResults(debouncedQuery);\n * }, [debouncedQuery]);\n *\n * // Handle input changes\n * const handleChange = (e) => {\n * setSearchQuery(e.target.value);\n * };\n *\n * // Access the selected debouncer state (will be empty object {} unless selector provided)\n * const { isPending, executionCount } = debouncer.state;\n * ```\n */\nexport function useDebouncedValue<\n TValue,\n TSelected = DebouncerState<Dispatch<StateUpdater<TValue>>>,\n>(\n value: TValue,\n options: DebouncerOptions<Dispatch<StateUpdater<TValue>>>,\n selector?: (\n state: DebouncerState<Dispatch<StateUpdater<TValue>>>,\n ) => TSelected,\n): [TValue, PreactDebouncer<Dispatch<StateUpdater<TValue>>, TSelected>] {\n const [debouncedValue, setDebouncedValue, debouncer] = useDebouncedState(\n value,\n options,\n selector,\n )\n\n useEffect(() => {\n ;(setDebouncedValue as (value: TValue) => void)(value)\n }, [value, setDebouncedValue])\n\n return [debouncedValue, debouncer]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0FA,SAAgB,kBAId,OACA,SACA,UAGsE;CACtE,MAAM,CAAC,gBAAgB,mBAAmB,aAAa,kBACrD,OACA,SACA,SACD;AAED,iBAAgB;AACb,EAAC,kBAA8C,MAAM;IACrD,CAAC,OAAO,kBAAkB,CAAC;AAE9B,QAAO,CAAC,gBAAgB,UAAU"}
1
+ {"version":3,"file":"useDebouncedValue.js","names":[],"sources":["../../src/debouncer/useDebouncedValue.ts"],"sourcesContent":["import { useEffect } from 'preact/hooks'\nimport { useDebouncedState } from './useDebouncedState'\nimport type { PreactDebouncer, PreactDebouncerOptions } from './useDebouncer'\nimport type { Dispatch, StateUpdater } from 'preact/hooks'\nimport type { DebouncerState } from '@tanstack/pacer/debouncer'\n\n/**\n * A Preact hook that creates a debounced value that updates only after a specified delay.\n * Unlike useDebouncedState, this hook automatically tracks changes to the input value\n * and updates the debounced value accordingly.\n *\n * The debounced value will only update after the specified wait time has elapsed since\n * the last change to the input value. If the input value changes again before the wait\n * time expires, the timer resets and starts waiting again.\n *\n * This is useful for deriving debounced values from props or state that change frequently,\n * like search queries or form inputs, where you want to limit how often downstream effects\n * or calculations occur.\n *\n * The hook returns the current debounced value and the underlying debouncer instance.\n * The debouncer instance can be used to access additional functionality like cancellation\n * and execution counts.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer 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 debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [searchQuery, setSearchQuery] = useState('');\n * const [debouncedQuery, debouncer] = useDebouncedValue(searchQuery, {\n * wait: 500 // Wait 500ms after last change\n * });\n *\n * // Opt-in to re-render when pending state changes (optimized for loading indicators)\n * const [debouncedQuery, debouncer] = useDebouncedValue(\n * searchQuery,\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to re-render when execution count changes (optimized for tracking executions)\n * const [debouncedQuery, debouncer] = useDebouncedValue(\n * searchQuery,\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to re-render when debouncing status changes (optimized for status display)\n * const [debouncedQuery, debouncer] = useDebouncedValue(\n * searchQuery,\n * { wait: 500 },\n * (state) => ({\n * status: state.status,\n * canLeadingExecute: state.canLeadingExecute\n * })\n * );\n *\n * // debouncedQuery will update 500ms after searchQuery stops changing\n * useEffect(() => {\n * fetchSearchResults(debouncedQuery);\n * }, [debouncedQuery]);\n *\n * // Handle input changes\n * const handleChange = (e) => {\n * setSearchQuery(e.target.value);\n * };\n *\n * // Access the selected debouncer state (will be empty object {} unless selector provided)\n * const { isPending, executionCount } = debouncer.state;\n * ```\n */\nexport function useDebouncedValue<\n TValue,\n TSelected = DebouncerState<Dispatch<StateUpdater<TValue>>>,\n>(\n value: TValue,\n options: PreactDebouncerOptions<Dispatch<StateUpdater<TValue>>, TSelected>,\n selector?: (\n state: DebouncerState<Dispatch<StateUpdater<TValue>>>,\n ) => TSelected,\n): [TValue, PreactDebouncer<Dispatch<StateUpdater<TValue>>, TSelected>] {\n const [debouncedValue, setDebouncedValue, debouncer] = useDebouncedState(\n value,\n options,\n selector,\n )\n\n useEffect(() => {\n ;(setDebouncedValue as (value: TValue) => void)(value)\n }, [value, setDebouncedValue])\n\n return [debouncedValue, debouncer]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuFA,SAAgB,kBAId,OACA,SACA,UAGsE;CACtE,MAAM,CAAC,gBAAgB,mBAAmB,aAAa,kBACrD,OACA,SACA,SACD;AAED,iBAAgB;AACb,EAAC,kBAA8C,MAAM;IACrD,CAAC,OAAO,kBAAkB,CAAC;AAE9B,QAAO,CAAC,gBAAgB,UAAU"}
@@ -47,6 +47,18 @@ let _tanstack_pacer_debouncer = require("@tanstack/pacer/debouncer");
47
47
  * - `lastArgs`: The arguments from the most recent call to maybeExecute
48
48
  * - `status`: Current execution status ('disabled' | 'idle' | 'pending')
49
49
  *
50
+ * ## Unmount behavior
51
+ *
52
+ * By default, the hook cancels any pending execution when the component unmounts.
53
+ * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
54
+ *
55
+ * ```tsx
56
+ * const debouncer = useDebouncer(fn, {
57
+ * wait: 500,
58
+ * onUnmount: (d) => d.flush()
59
+ * });
60
+ * ```
61
+ *
50
62
  * @example
51
63
  * ```tsx
52
64
  * // Default behavior - no reactive state subscriptions
@@ -104,7 +116,7 @@ function useDebouncer(fn, options, selector = () => ({})) {
104
116
  const [debouncer] = (0, preact_hooks.useState)(() => {
105
117
  const debouncerInstance = new _tanstack_pacer_debouncer.Debouncer(fn, mergedOptions);
106
118
  debouncerInstance.Subscribe = function Subscribe(props) {
107
- const selected = (0, _tanstack_preact_store.useStore)(debouncerInstance.store, props.selector);
119
+ const selected = (0, _tanstack_preact_store.useStore)(debouncerInstance.store, props.selector, { equal: _tanstack_preact_store.shallow });
108
120
  return typeof props.children === "function" ? props.children(selected) : props.children;
109
121
  };
110
122
  return debouncerInstance;
@@ -113,10 +125,11 @@ function useDebouncer(fn, options, selector = () => ({})) {
113
125
  debouncer.setOptions(mergedOptions);
114
126
  (0, preact_hooks.useEffect)(() => {
115
127
  return () => {
116
- debouncer.cancel();
128
+ if (mergedOptions.onUnmount) mergedOptions.onUnmount(debouncer);
129
+ else debouncer.cancel();
117
130
  };
118
- }, [debouncer]);
119
- const state = (0, _tanstack_preact_store.useStore)(debouncer.store, selector);
131
+ }, []);
132
+ const state = (0, _tanstack_preact_store.useStore)(debouncer.store, selector, { equal: _tanstack_preact_store.shallow });
120
133
  return (0, preact_hooks.useMemo)(() => ({
121
134
  ...debouncer,
122
135
  state
@@ -1 +1 @@
1
- {"version":3,"file":"useDebouncer.cjs","names":["useDefaultPacerOptions","Debouncer"],"sources":["../../src/debouncer/useDebouncer.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'preact/hooks'\nimport { Debouncer } from '@tanstack/pacer/debouncer'\nimport { useStore } from '@tanstack/preact-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/preact-store'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { ComponentChildren } from 'preact'\n\nexport interface PreactDebouncer<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Debouncer<TFn>, 'store'> {\n /**\n * A Preact HOC (Higher Order Component) that allows you to subscribe to the debouncer state.\n *\n * This is useful for opting into state re-renders for specific parts of the debouncer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <debouncer.Subscribe selector={(state) => ({ isPending: state.isPending })}>\n * {({ isPending }) => (\n * <div>{isPending ? 'Loading...' : 'Ready'}</div>\n * )}\n * </debouncer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: DebouncerState<TFn>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) => ComponentChildren\n /**\n * Reactive state that will be updated and re-rendered when the debouncer state changes\n *\n * Use this instead of `debouncer.store.state`\n */\n readonly state: Readonly<TSelected>\n /**\n * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<DebouncerState<TFn>>>\n}\n\n/**\n * A Preact hook that creates and manages a Debouncer instance.\n *\n * This is a lower-level hook that provides direct access to the Debouncer'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.).\n *\n * This hook provides debouncing functionality to limit how often a function can be called,\n * waiting for a specified delay before executing the latest call. This is useful for handling\n * frequent events like window resizing, scroll events, or real-time search inputs.\n *\n * The debouncer will only execute the function after the specified wait time has elapsed\n * since the last call. If the function is called again before the wait time expires, the\n * timer resets and starts waiting again.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `debouncer.Subscribe` 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 * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const searchDebouncer = useDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 }\n * );\n *\n * // Subscribe to state changes deep in component tree using Subscribe HOC\n * <searchDebouncer.Subscribe selector={(state) => ({ isPending: state.isPending })}>\n * {({ isPending }) => (\n * <div>{isPending ? 'Searching...' : 'Ready'}</div>\n * )}\n * </searchDebouncer.Subscribe>\n *\n * // Opt-in to re-render when isPending changes at hook level (optimized for loading states)\n * const searchDebouncer = useDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to re-render when executionCount changes (optimized for tracking execution)\n * const searchDebouncer = useDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Multiple state properties - re-render when any of these change\n * const searchDebouncer = useDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({\n * isPending: state.isPending,\n * executionCount: state.executionCount,\n * status: state.status\n * })\n * );\n *\n * // In an event handler\n * const handleChange = (e) => {\n * searchDebouncer.maybeExecute(e.target.value);\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = searchDebouncer.state;\n * ```\n */\nexport function useDebouncer<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: DebouncerOptions<TFn>,\n selector: (state: DebouncerState<TFn>) => TSelected = () => ({}) as TSelected,\n): PreactDebouncer<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().debouncer,\n ...options,\n } as DebouncerOptions<TFn>\n\n const [debouncer] = useState(() => {\n const debouncerInstance = new Debouncer(\n fn,\n mergedOptions,\n ) as unknown as PreactDebouncer<TFn, TSelected>\n\n debouncerInstance.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: DebouncerState<TFn>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) {\n const selected = useStore(debouncerInstance.store, props.selector)\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n return debouncerInstance\n })\n\n debouncer.fn = fn\n debouncer.setOptions(mergedOptions)\n\n useEffect(() => {\n return () => {\n debouncer.cancel()\n }\n }, [debouncer])\n\n const state = useStore(debouncer.store, selector)\n\n return useMemo(\n () =>\n ({\n ...debouncer,\n state,\n }) as PreactDebouncer<TFn, TSelected>, // omit `store` in favor of `state`\n [debouncer, state],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2IA,SAAgB,aACd,IACA,SACA,kBAA6D,EAAE,GAC9B;CACjC,MAAM,gBAAgB;EACpB,GAAGA,8CAAwB,CAAC;EAC5B,GAAG;EACJ;CAED,MAAM,CAAC,8CAA4B;EACjC,MAAM,oBAAoB,IAAIC,oCAC5B,IACA,cACD;AAED,oBAAkB,YAAY,SAAS,UAAqB,OAGzD;GACD,MAAM,gDAAoB,kBAAkB,OAAO,MAAM,SAAS;AAElE,UAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;AAGZ,SAAO;GACP;AAEF,WAAU,KAAK;AACf,WAAU,WAAW,cAAc;AAEnC,mCAAgB;AACd,eAAa;AACX,aAAU,QAAQ;;IAEnB,CAAC,UAAU,CAAC;CAEf,MAAM,6CAAiB,UAAU,OAAO,SAAS;AAEjD,yCAEK;EACC,GAAG;EACH;EACD,GACH,CAAC,WAAW,MAAM,CACnB"}
1
+ {"version":3,"file":"useDebouncer.cjs","names":["useDefaultPacerOptions","Debouncer","shallow"],"sources":["../../src/debouncer/useDebouncer.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'preact/hooks'\nimport { Debouncer } from '@tanstack/pacer/debouncer'\nimport { shallow, useStore } from '@tanstack/preact-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/preact-store'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { ComponentChildren } from 'preact'\n\nexport interface PreactDebouncerOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends DebouncerOptions<TFn> {\n /**\n * Optional callback invoked when the component unmounts. Receives the debouncer instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.\n */\n onUnmount?: (debouncer: PreactDebouncer<TFn, TSelected>) => void\n}\n\nexport interface PreactDebouncer<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Debouncer<TFn>, 'store'> {\n /**\n * A Preact HOC (Higher Order Component) that allows you to subscribe to the debouncer state.\n *\n * This is useful for opting into state re-renders for specific parts of the debouncer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <debouncer.Subscribe selector={(state) => ({ isPending: state.isPending })}>\n * {({ isPending }) => (\n * <div>{isPending ? 'Loading...' : 'Ready'}</div>\n * )}\n * </debouncer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: DebouncerState<TFn>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) => ComponentChildren\n /**\n * Reactive state that will be updated and re-rendered when the debouncer state changes\n *\n * Use this instead of `debouncer.store.state`\n */\n readonly state: Readonly<TSelected>\n /**\n * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<DebouncerState<TFn>>>\n}\n\n/**\n * A Preact hook that creates and manages a Debouncer instance.\n *\n * This is a lower-level hook that provides direct access to the Debouncer'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.).\n *\n * This hook provides debouncing functionality to limit how often a function can be called,\n * waiting for a specified delay before executing the latest call. This is useful for handling\n * frequent events like window resizing, scroll events, or real-time search inputs.\n *\n * The debouncer will only execute the function after the specified wait time has elapsed\n * since the last call. If the function is called again before the wait time expires, the\n * timer resets and starts waiting again.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `debouncer.Subscribe` 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 * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * ## Unmount behavior\n *\n * By default, the hook cancels any pending execution when the component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```tsx\n * const debouncer = useDebouncer(fn, {\n * wait: 500,\n * onUnmount: (d) => d.flush()\n * });\n * ```\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const searchDebouncer = useDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 }\n * );\n *\n * // Subscribe to state changes deep in component tree using Subscribe HOC\n * <searchDebouncer.Subscribe selector={(state) => ({ isPending: state.isPending })}>\n * {({ isPending }) => (\n * <div>{isPending ? 'Searching...' : 'Ready'}</div>\n * )}\n * </searchDebouncer.Subscribe>\n *\n * // Opt-in to re-render when isPending changes at hook level (optimized for loading states)\n * const searchDebouncer = useDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to re-render when executionCount changes (optimized for tracking execution)\n * const searchDebouncer = useDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Multiple state properties - re-render when any of these change\n * const searchDebouncer = useDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({\n * isPending: state.isPending,\n * executionCount: state.executionCount,\n * status: state.status\n * })\n * );\n *\n * // In an event handler\n * const handleChange = (e) => {\n * searchDebouncer.maybeExecute(e.target.value);\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = searchDebouncer.state;\n * ```\n */\nexport function useDebouncer<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: PreactDebouncerOptions<TFn, TSelected>,\n selector: (state: DebouncerState<TFn>) => TSelected = () => ({}) as TSelected,\n): PreactDebouncer<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().debouncer,\n ...options,\n } as PreactDebouncerOptions<TFn, TSelected>\n const [debouncer] = useState(() => {\n const debouncerInstance = new Debouncer(\n fn,\n mergedOptions,\n ) as unknown as PreactDebouncer<TFn, TSelected>\n\n debouncerInstance.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: DebouncerState<TFn>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) {\n const selected = useStore(debouncerInstance.store, props.selector, {\n equal: shallow,\n })\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n return debouncerInstance\n })\n\n debouncer.fn = fn\n debouncer.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(debouncer)\n } else {\n debouncer.cancel()\n }\n }\n }, [])\n /* eslint-enable react-hooks/exhaustive-deps */\n\n const state = useStore(debouncer.store, selector, { equal: shallow })\n\n return useMemo(\n () =>\n ({\n ...debouncer,\n state,\n }) as PreactDebouncer<TFn, TSelected>, // omit `store` in favor of `state`\n [debouncer, state],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkKA,SAAgB,aACd,IACA,SACA,kBAA6D,EAAE,GAC9B;CACjC,MAAM,gBAAgB;EACpB,GAAGA,8CAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,CAAC,8CAA4B;EACjC,MAAM,oBAAoB,IAAIC,oCAC5B,IACA,cACD;AAED,oBAAkB,YAAY,SAAS,UAAqB,OAGzD;GACD,MAAM,gDAAoB,kBAAkB,OAAO,MAAM,UAAU,EACjE,OAAOC,gCACR,CAAC;AAEF,UAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;AAGZ,SAAO;GACP;AAEF,WAAU,KAAK;AACf,WAAU,WAAW,cAAc;AAGnC,mCAAgB;AACd,eAAa;AACX,OAAI,cAAc,UAChB,eAAc,UAAU,UAAU;OAElC,WAAU,QAAQ;;IAGrB,EAAE,CAAC;CAGN,MAAM,6CAAiB,UAAU,OAAO,UAAU,EAAE,OAAOA,gCAAS,CAAC;AAErE,yCAEK;EACC,GAAG;EACH;EACD,GACH,CAAC,WAAW,MAAM,CACnB"}
@@ -4,6 +4,13 @@ import { AnyFunction } from "@tanstack/pacer/types";
4
4
  import { Debouncer, DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
5
5
 
6
6
  //#region src/debouncer/useDebouncer.d.ts
7
+ interface PreactDebouncerOptions<TFn extends AnyFunction, TSelected = {}> extends DebouncerOptions<TFn> {
8
+ /**
9
+ * Optional callback invoked when the component unmounts. Receives the debouncer instance.
10
+ * When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.
11
+ */
12
+ onUnmount?: (debouncer: PreactDebouncer<TFn, TSelected>) => void;
13
+ }
7
14
  interface PreactDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<Debouncer<TFn>, 'store'> {
8
15
  /**
9
16
  * A Preact HOC (Higher Order Component) that allows you to subscribe to the debouncer state.
@@ -78,6 +85,18 @@ interface PreactDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<
78
85
  * - `lastArgs`: The arguments from the most recent call to maybeExecute
79
86
  * - `status`: Current execution status ('disabled' | 'idle' | 'pending')
80
87
  *
88
+ * ## Unmount behavior
89
+ *
90
+ * By default, the hook cancels any pending execution when the component unmounts.
91
+ * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
92
+ *
93
+ * ```tsx
94
+ * const debouncer = useDebouncer(fn, {
95
+ * wait: 500,
96
+ * onUnmount: (d) => d.flush()
97
+ * });
98
+ * ```
99
+ *
81
100
  * @example
82
101
  * ```tsx
83
102
  * // Default behavior - no reactive state subscriptions
@@ -127,7 +146,7 @@ interface PreactDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<
127
146
  * const { isPending } = searchDebouncer.state;
128
147
  * ```
129
148
  */
130
- declare function useDebouncer<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: DebouncerOptions<TFn>, selector?: (state: DebouncerState<TFn>) => TSelected): PreactDebouncer<TFn, TSelected>;
149
+ declare function useDebouncer<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: PreactDebouncerOptions<TFn, TSelected>, selector?: (state: DebouncerState<TFn>) => TSelected): PreactDebouncer<TFn, TSelected>;
131
150
  //#endregion
132
- export { PreactDebouncer, useDebouncer };
151
+ export { PreactDebouncer, PreactDebouncerOptions, useDebouncer };
133
152
  //# sourceMappingURL=useDebouncer.d.cts.map
@@ -4,6 +4,13 @@ import { Debouncer, DebouncerOptions, DebouncerState } from "@tanstack/pacer/deb
4
4
  import { AnyFunction } from "@tanstack/pacer/types";
5
5
 
6
6
  //#region src/debouncer/useDebouncer.d.ts
7
+ interface PreactDebouncerOptions<TFn extends AnyFunction, TSelected = {}> extends DebouncerOptions<TFn> {
8
+ /**
9
+ * Optional callback invoked when the component unmounts. Receives the debouncer instance.
10
+ * When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.
11
+ */
12
+ onUnmount?: (debouncer: PreactDebouncer<TFn, TSelected>) => void;
13
+ }
7
14
  interface PreactDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<Debouncer<TFn>, 'store'> {
8
15
  /**
9
16
  * A Preact HOC (Higher Order Component) that allows you to subscribe to the debouncer state.
@@ -78,6 +85,18 @@ interface PreactDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<
78
85
  * - `lastArgs`: The arguments from the most recent call to maybeExecute
79
86
  * - `status`: Current execution status ('disabled' | 'idle' | 'pending')
80
87
  *
88
+ * ## Unmount behavior
89
+ *
90
+ * By default, the hook cancels any pending execution when the component unmounts.
91
+ * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
92
+ *
93
+ * ```tsx
94
+ * const debouncer = useDebouncer(fn, {
95
+ * wait: 500,
96
+ * onUnmount: (d) => d.flush()
97
+ * });
98
+ * ```
99
+ *
81
100
  * @example
82
101
  * ```tsx
83
102
  * // Default behavior - no reactive state subscriptions
@@ -127,7 +146,7 @@ interface PreactDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<
127
146
  * const { isPending } = searchDebouncer.state;
128
147
  * ```
129
148
  */
130
- declare function useDebouncer<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: DebouncerOptions<TFn>, selector?: (state: DebouncerState<TFn>) => TSelected): PreactDebouncer<TFn, TSelected>;
149
+ declare function useDebouncer<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: PreactDebouncerOptions<TFn, TSelected>, selector?: (state: DebouncerState<TFn>) => TSelected): PreactDebouncer<TFn, TSelected>;
131
150
  //#endregion
132
- export { PreactDebouncer, useDebouncer };
151
+ export { PreactDebouncer, PreactDebouncerOptions, useDebouncer };
133
152
  //# sourceMappingURL=useDebouncer.d.ts.map