@tanstack/solid-pacer 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/README.md +4 -4
  2. package/dist/async-batcher/createAsyncBatcher.d.ts +5 -9
  3. package/dist/async-batcher/createAsyncBatcher.js +2 -5
  4. package/dist/async-debouncer/createAsyncDebouncer.d.ts +8 -11
  5. package/dist/async-debouncer/createAsyncDebouncer.js +5 -7
  6. package/dist/async-queuer/createAsyncQueuer.d.ts +9 -11
  7. package/dist/async-queuer/createAsyncQueuer.js +4 -5
  8. package/dist/async-rate-limiter/createAsyncRateLimiter.d.ts +10 -12
  9. package/dist/async-rate-limiter/createAsyncRateLimiter.js +7 -8
  10. package/dist/async-throttler/createAsyncThrottler.d.ts +8 -13
  11. package/dist/async-throttler/createAsyncThrottler.js +5 -9
  12. package/dist/batcher/createBatcher.d.ts +11 -14
  13. package/dist/batcher/createBatcher.js +6 -8
  14. package/dist/debouncer/createDebouncedSignal.d.ts +2 -4
  15. package/dist/debouncer/createDebouncedSignal.js +1 -2
  16. package/dist/debouncer/createDebouncedValue.d.ts +2 -4
  17. package/dist/debouncer/createDebouncedValue.js +1 -2
  18. package/dist/debouncer/createDebouncer.d.ts +4 -6
  19. package/dist/debouncer/createDebouncer.js +1 -2
  20. package/dist/provider/PacerProvider.d.ts +6 -8
  21. package/dist/provider/PacerProvider.js +1 -2
  22. package/dist/queuer/createQueuedSignal.d.ts +2 -4
  23. package/dist/queuer/createQueuedSignal.js +1 -2
  24. package/dist/queuer/createQueuer.d.ts +4 -6
  25. package/dist/queuer/createQueuer.js +1 -2
  26. package/dist/rate-limiter/createRateLimitedSignal.d.ts +12 -13
  27. package/dist/rate-limiter/createRateLimitedSignal.js +11 -11
  28. package/dist/rate-limiter/createRateLimitedValue.d.ts +2 -4
  29. package/dist/rate-limiter/createRateLimitedValue.js +1 -2
  30. package/dist/rate-limiter/createRateLimiter.d.ts +8 -9
  31. package/dist/rate-limiter/createRateLimiter.js +5 -5
  32. package/dist/throttler/createThrottledSignal.d.ts +2 -6
  33. package/dist/throttler/createThrottledSignal.js +1 -4
  34. package/dist/throttler/createThrottledValue.d.ts +2 -6
  35. package/dist/throttler/createThrottledValue.js +1 -4
  36. package/dist/throttler/createThrottler.d.ts +4 -8
  37. package/dist/throttler/createThrottler.js +1 -4
  38. package/package.json +23 -67
  39. package/dist/async-batcher/createAsyncBatcher.cjs +0 -166
  40. package/dist/async-batcher/createAsyncBatcher.cjs.map +0 -1
  41. package/dist/async-batcher/createAsyncBatcher.d.cts +0 -177
  42. package/dist/async-batcher/createAsyncBatcher.js.map +0 -1
  43. package/dist/async-batcher/index.cjs +0 -11
  44. package/dist/async-batcher/index.d.cts +0 -3
  45. package/dist/async-debouncer/createAsyncDebouncer.cjs +0 -151
  46. package/dist/async-debouncer/createAsyncDebouncer.cjs.map +0 -1
  47. package/dist/async-debouncer/createAsyncDebouncer.d.cts +0 -163
  48. package/dist/async-debouncer/createAsyncDebouncer.js.map +0 -1
  49. package/dist/async-debouncer/index.cjs +0 -11
  50. package/dist/async-debouncer/index.d.cts +0 -3
  51. package/dist/async-queuer/createAsyncQueuer.cjs +0 -158
  52. package/dist/async-queuer/createAsyncQueuer.cjs.map +0 -1
  53. package/dist/async-queuer/createAsyncQueuer.d.cts +0 -169
  54. package/dist/async-queuer/createAsyncQueuer.js.map +0 -1
  55. package/dist/async-queuer/index.cjs +0 -11
  56. package/dist/async-queuer/index.d.cts +0 -3
  57. package/dist/async-rate-limiter/createAsyncRateLimiter.cjs +0 -193
  58. package/dist/async-rate-limiter/createAsyncRateLimiter.cjs.map +0 -1
  59. package/dist/async-rate-limiter/createAsyncRateLimiter.d.cts +0 -208
  60. package/dist/async-rate-limiter/createAsyncRateLimiter.js.map +0 -1
  61. package/dist/async-rate-limiter/index.cjs +0 -11
  62. package/dist/async-rate-limiter/index.d.cts +0 -3
  63. package/dist/async-throttler/createAsyncThrottler.cjs +0 -151
  64. package/dist/async-throttler/createAsyncThrottler.cjs.map +0 -1
  65. package/dist/async-throttler/createAsyncThrottler.d.cts +0 -163
  66. package/dist/async-throttler/createAsyncThrottler.js.map +0 -1
  67. package/dist/async-throttler/index.cjs +0 -11
  68. package/dist/async-throttler/index.d.cts +0 -3
  69. package/dist/batcher/createBatcher.cjs +0 -132
  70. package/dist/batcher/createBatcher.cjs.map +0 -1
  71. package/dist/batcher/createBatcher.d.cts +0 -146
  72. package/dist/batcher/createBatcher.js.map +0 -1
  73. package/dist/batcher/index.cjs +0 -11
  74. package/dist/batcher/index.d.cts +0 -3
  75. package/dist/debouncer/createDebouncedSignal.cjs +0 -88
  76. package/dist/debouncer/createDebouncedSignal.cjs.map +0 -1
  77. package/dist/debouncer/createDebouncedSignal.d.cts +0 -79
  78. package/dist/debouncer/createDebouncedSignal.js.map +0 -1
  79. package/dist/debouncer/createDebouncedValue.cjs +0 -77
  80. package/dist/debouncer/createDebouncedValue.cjs.map +0 -1
  81. package/dist/debouncer/createDebouncedValue.d.cts +0 -70
  82. package/dist/debouncer/createDebouncedValue.js.map +0 -1
  83. package/dist/debouncer/createDebouncer.cjs +0 -129
  84. package/dist/debouncer/createDebouncer.cjs.map +0 -1
  85. package/dist/debouncer/createDebouncer.d.cts +0 -144
  86. package/dist/debouncer/createDebouncer.js.map +0 -1
  87. package/dist/debouncer/index.cjs +0 -15
  88. package/dist/debouncer/index.d.cts +0 -5
  89. package/dist/index.cjs +0 -47
  90. package/dist/index.d.cts +0 -20
  91. package/dist/provider/PacerProvider.cjs +0 -27
  92. package/dist/provider/PacerProvider.cjs.map +0 -1
  93. package/dist/provider/PacerProvider.d.cts +0 -28
  94. package/dist/provider/PacerProvider.js.map +0 -1
  95. package/dist/provider/index.cjs +0 -6
  96. package/dist/provider/index.d.cts +0 -2
  97. package/dist/queuer/createQueuedSignal.cjs +0 -129
  98. package/dist/queuer/createQueuedSignal.cjs.map +0 -1
  99. package/dist/queuer/createQueuedSignal.d.cts +0 -121
  100. package/dist/queuer/createQueuedSignal.js.map +0 -1
  101. package/dist/queuer/createQueuer.cjs +0 -133
  102. package/dist/queuer/createQueuer.cjs.map +0 -1
  103. package/dist/queuer/createQueuer.d.cts +0 -147
  104. package/dist/queuer/createQueuer.js.map +0 -1
  105. package/dist/queuer/index.cjs +0 -13
  106. package/dist/queuer/index.d.cts +0 -4
  107. package/dist/rate-limiter/createRateLimitedSignal.cjs +0 -102
  108. package/dist/rate-limiter/createRateLimitedSignal.cjs.map +0 -1
  109. package/dist/rate-limiter/createRateLimitedSignal.d.cts +0 -93
  110. package/dist/rate-limiter/createRateLimitedSignal.js.map +0 -1
  111. package/dist/rate-limiter/createRateLimitedValue.cjs +0 -102
  112. package/dist/rate-limiter/createRateLimitedValue.cjs.map +0 -1
  113. package/dist/rate-limiter/createRateLimitedValue.d.cts +0 -95
  114. package/dist/rate-limiter/createRateLimitedValue.js.map +0 -1
  115. package/dist/rate-limiter/createRateLimiter.cjs +0 -157
  116. package/dist/rate-limiter/createRateLimiter.cjs.map +0 -1
  117. package/dist/rate-limiter/createRateLimiter.d.cts +0 -173
  118. package/dist/rate-limiter/createRateLimiter.js.map +0 -1
  119. package/dist/rate-limiter/index.cjs +0 -15
  120. package/dist/rate-limiter/index.d.cts +0 -5
  121. package/dist/throttler/createThrottledSignal.cjs +0 -79
  122. package/dist/throttler/createThrottledSignal.cjs.map +0 -1
  123. package/dist/throttler/createThrottledSignal.d.cts +0 -70
  124. package/dist/throttler/createThrottledSignal.js.map +0 -1
  125. package/dist/throttler/createThrottledValue.cjs +0 -74
  126. package/dist/throttler/createThrottledValue.cjs.map +0 -1
  127. package/dist/throttler/createThrottledValue.d.cts +0 -67
  128. package/dist/throttler/createThrottledValue.js.map +0 -1
  129. package/dist/throttler/createThrottler.cjs +0 -132
  130. package/dist/throttler/createThrottler.cjs.map +0 -1
  131. package/dist/throttler/createThrottler.d.cts +0 -147
  132. package/dist/throttler/createThrottler.js.map +0 -1
  133. package/dist/throttler/index.cjs +0 -15
  134. package/dist/throttler/index.d.cts +0 -5
  135. package/dist/types/index.cjs +0 -8
  136. package/dist/types/index.d.cts +0 -1
  137. package/dist/utils/index.cjs +0 -8
  138. package/dist/utils/index.d.cts +0 -1
  139. package/src/async-batcher/createAsyncBatcher.ts +0 -234
  140. package/src/async-batcher/index.ts +0 -3
  141. package/src/async-debouncer/createAsyncDebouncer.ts +0 -225
  142. package/src/async-debouncer/index.ts +0 -4
  143. package/src/async-queuer/createAsyncQueuer.ts +0 -226
  144. package/src/async-queuer/index.ts +0 -3
  145. package/src/async-rate-limiter/createAsyncRateLimiter.ts +0 -269
  146. package/src/async-rate-limiter/index.ts +0 -4
  147. package/src/async-throttler/createAsyncThrottler.ts +0 -225
  148. package/src/async-throttler/index.ts +0 -4
  149. package/src/batcher/createBatcher.ts +0 -199
  150. package/src/batcher/index.ts +0 -3
  151. package/src/debouncer/createDebouncedSignal.ts +0 -92
  152. package/src/debouncer/createDebouncedValue.ts +0 -85
  153. package/src/debouncer/createDebouncer.ts +0 -201
  154. package/src/debouncer/index.ts +0 -6
  155. package/src/index.ts +0 -46
  156. package/src/provider/PacerProvider.tsx +0 -63
  157. package/src/provider/index.ts +0 -1
  158. package/src/queuer/createQueuedSignal.ts +0 -138
  159. package/src/queuer/createQueuer.ts +0 -199
  160. package/src/queuer/index.ts +0 -4
  161. package/src/rate-limiter/createRateLimitedSignal.ts +0 -117
  162. package/src/rate-limiter/createRateLimitedValue.ts +0 -110
  163. package/src/rate-limiter/createRateLimiter.ts +0 -226
  164. package/src/rate-limiter/index.ts +0 -5
  165. package/src/throttler/createThrottledSignal.ts +0 -81
  166. package/src/throttler/createThrottledValue.ts +0 -82
  167. package/src/throttler/createThrottler.ts +0 -204
  168. package/src/throttler/index.ts +0 -6
  169. package/src/types/index.ts +0 -1
  170. package/src/utils/index.ts +0 -1
@@ -1,79 +0,0 @@
1
- import { SolidDebouncer, SolidDebouncerOptions } from "./createDebouncer.cjs";
2
- import { Accessor, Setter } from "solid-js";
3
- import { DebouncerState } from "@tanstack/pacer/debouncer";
4
- //#region src/debouncer/createDebouncedSignal.d.ts
5
- /**
6
- * A Solid hook that creates a debounced state value, combining Solid's createSignal with debouncing functionality.
7
- * This hook provides both the current debounced value and methods to update it.
8
- *
9
- * The state value is only updated after the specified wait time has elapsed since the last update attempt.
10
- * If another update is attempted before the wait time expires, the timer resets and starts waiting again.
11
- * This is useful for handling frequent state updates that should be throttled, like search input values
12
- * or window resize dimensions.
13
- *
14
- * The hook returns a tuple containing:
15
- * - The current debounced value accessor
16
- * - A function to update the debounced value
17
- * - The debouncer instance with additional control methods and state signals
18
- *
19
- * ## State Management and Selector
20
- *
21
- * The hook uses TanStack Store for reactive state management via the underlying debouncer instance.
22
- * The `selector` parameter allows you to specify which debouncer state changes will trigger reactive updates,
23
- * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
24
- *
25
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
26
- * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you
27
- * full control over when your component subscribes to state changes. Only when you provide a selector will
28
- * the reactive system track the selected state values.
29
- *
30
- * Available debouncer state properties:
31
- * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
32
- * - `executionCount`: Number of function executions that have been completed
33
- * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
34
- * - `lastArgs`: The arguments from the most recent call to maybeExecute
35
- * - `status`: Current execution status ('disabled' | 'idle' | 'pending')
36
- *
37
- * @example
38
- * ```tsx
39
- * // Default behavior - no reactive state subscriptions
40
- * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {
41
- * wait: 500 // Wait 500ms after last keystroke
42
- * });
43
- *
44
- * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)
45
- * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal(
46
- * '',
47
- * { wait: 500 },
48
- * (state) => ({ isPending: state.isPending })
49
- * );
50
- *
51
- * // Opt-in to reactive updates when execution count changes (optimized for tracking executions)
52
- * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal(
53
- * '',
54
- * { wait: 500 },
55
- * (state) => ({ executionCount: state.executionCount })
56
- * );
57
- *
58
- * // Update value - will be debounced
59
- * const handleChange = (e) => {
60
- * setSearchTerm(e.target.value);
61
- * };
62
- *
63
- * // Access debouncer state via signals
64
- * console.log('Executions:', debouncer.state().executionCount);
65
- * console.log('Is pending:', debouncer.state().isPending);
66
- *
67
- * // In onExecute callback, use get* methods
68
- * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {
69
- * wait: 500,
70
- * onExecute: (debouncer) => {
71
- * console.log('Total executions:', debouncer.getExecutionCount());
72
- * }
73
- * });
74
- * ```
75
- */
76
- declare function createDebouncedSignal<TValue, TSelected = {}>(value: TValue, initialOptions: SolidDebouncerOptions<Setter<TValue>, TSelected>, selector?: (state: DebouncerState<Setter<TValue>>) => TSelected): [Accessor<TValue>, Setter<TValue>, SolidDebouncer<Setter<TValue>, TSelected>];
77
- //#endregion
78
- export { createDebouncedSignal };
79
- //# sourceMappingURL=createDebouncedSignal.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createDebouncedSignal.js","names":[],"sources":["../../src/debouncer/createDebouncedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createDebouncer } from './createDebouncer'\nimport type { SolidDebouncer, SolidDebouncerOptions } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { DebouncerState } from '@tanstack/pacer/debouncer'\n\n/**\n * A Solid hook that creates a debounced state value, combining Solid's createSignal 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 accessor\n * - A function to update the debounced value\n * - The debouncer instance with additional control methods and state signals\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 reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available 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] = createDebouncedSignal('', {\n * wait: 500 // Wait 500ms after last keystroke\n * });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal(\n * '',\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to reactive updates when execution count changes (optimized for tracking executions)\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal(\n * '',\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Update value - will be debounced\n * const handleChange = (e) => {\n * setSearchTerm(e.target.value);\n * };\n *\n * // Access debouncer state via signals\n * console.log('Executions:', debouncer.state().executionCount);\n * console.log('Is pending:', debouncer.state().isPending);\n *\n * // In onExecute callback, use get* methods\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {\n * wait: 500,\n * onExecute: (debouncer) => {\n * console.log('Total executions:', debouncer.getExecutionCount());\n * }\n * });\n * ```\n */\nexport function createDebouncedSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: SolidDebouncerOptions<Setter<TValue>, TSelected>,\n selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidDebouncer<Setter<TValue>, TSelected>,\n] {\n const [debouncedValue, setDebouncedValue] = createSignal<TValue>(value)\n\n const debouncer = createDebouncer(setDebouncedValue, initialOptions, selector)\n\n return [debouncedValue, debouncer.maybeExecute as Setter<TValue>, debouncer]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA,SAAgB,sBACd,OACA,gBACA,UAKA;CACA,MAAM,CAAC,gBAAgB,qBAAqB,aAAqB,KAAK;CAEtE,MAAM,YAAY,gBAAgB,mBAAmB,gBAAgB,QAAQ;CAE7E,OAAO;EAAC;EAAgB,UAAU;EAAgC;CAAS;AAC7E"}
@@ -1,77 +0,0 @@
1
- const require_createDebouncedSignal = require('./createDebouncedSignal.cjs');
2
- let solid_js = require("solid-js");
3
-
4
- //#region src/debouncer/createDebouncedValue.ts
5
- /**
6
- * A Solid hook that creates a debounced value that updates only after a specified delay.
7
- * Unlike createDebouncedSignal, this hook automatically tracks changes to the input value
8
- * and updates the debounced value accordingly.
9
- *
10
- * The debounced value will only update after the specified wait time has elapsed since
11
- * the last change to the input value. If the input value changes again before the wait
12
- * time expires, the timer resets and starts waiting again.
13
- *
14
- * This is useful for deriving debounced values from props or state that change frequently,
15
- * like search queries or form inputs, where you want to limit how often downstream effects
16
- * or calculations occur.
17
- *
18
- * The hook returns a tuple containing:
19
- * - An Accessor that provides the current debounced value
20
- * - The debouncer instance with control methods
21
- *
22
- * ## State Management and Selector
23
- *
24
- * The hook uses TanStack Store for reactive state management via the underlying debouncer instance.
25
- * The `selector` parameter allows you to specify which debouncer state changes will trigger reactive updates,
26
- * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
27
- *
28
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
29
- * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you
30
- * full control over when your component subscribes to state changes. Only when you provide a selector will
31
- * the reactive system track the selected state values.
32
- *
33
- * Available debouncer state properties:
34
- * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
35
- * - `executionCount`: Number of function executions that have been completed
36
- * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
37
- * - `lastArgs`: The arguments from the most recent call to maybeExecute
38
- * - `status`: Current execution status ('disabled' | 'idle' | 'pending')
39
- *
40
- * @example
41
- * ```tsx
42
- * // Default behavior - no reactive state subscriptions
43
- * const [searchQuery, setSearchQuery] = createSignal('');
44
- * const [debouncedQuery, debouncer] = createDebouncedValue(searchQuery, {
45
- * wait: 500 // Wait 500ms after last change
46
- * });
47
- *
48
- * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)
49
- * const [debouncedQuery, debouncer] = createDebouncedValue(
50
- * searchQuery,
51
- * { wait: 500 },
52
- * (state) => ({ isPending: state.isPending })
53
- * );
54
- *
55
- * // debouncedQuery will update 500ms after searchQuery stops changing
56
- * createEffect(() => {
57
- * fetchSearchResults(debouncedQuery());
58
- * });
59
- *
60
- * // Access debouncer state via signals
61
- * console.log('Is pending:', debouncer.state().isPending);
62
- *
63
- * // Control the debouncer
64
- * debouncer.cancel(); // Cancel any pending updates
65
- * ```
66
- */
67
- function createDebouncedValue(value, initialOptions, selector) {
68
- const [debouncedValue, setDebouncedValue, debouncer] = require_createDebouncedSignal.createDebouncedSignal(value(), initialOptions, selector);
69
- (0, solid_js.createEffect)(() => {
70
- setDebouncedValue(value());
71
- });
72
- return [debouncedValue, debouncer];
73
- }
74
-
75
- //#endregion
76
- exports.createDebouncedValue = createDebouncedValue;
77
- //# sourceMappingURL=createDebouncedValue.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createDebouncedValue.cjs","names":["createDebouncedSignal"],"sources":["../../src/debouncer/createDebouncedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createDebouncedSignal } from './createDebouncedSignal'\nimport type { SolidDebouncer, SolidDebouncerOptions } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { DebouncerState } from '@tanstack/pacer/debouncer'\n\n/**\n * A Solid hook that creates a debounced value that updates only after a specified delay.\n * Unlike createDebouncedSignal, 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 a tuple containing:\n * - An Accessor that provides the current debounced value\n * - The debouncer instance with 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 reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available 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] = createSignal('');\n * const [debouncedQuery, debouncer] = createDebouncedValue(searchQuery, {\n * wait: 500 // Wait 500ms after last change\n * });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [debouncedQuery, debouncer] = createDebouncedValue(\n * searchQuery,\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // debouncedQuery will update 500ms after searchQuery stops changing\n * createEffect(() => {\n * fetchSearchResults(debouncedQuery());\n * });\n *\n * // Access debouncer state via signals\n * console.log('Is pending:', debouncer.state().isPending);\n *\n * // Control the debouncer\n * debouncer.cancel(); // Cancel any pending updates\n * ```\n */\nexport function createDebouncedValue<TValue, TSelected = {}>(\n value: Accessor<TValue>,\n initialOptions: SolidDebouncerOptions<Setter<TValue>, TSelected>,\n selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): [Accessor<TValue>, SolidDebouncer<Setter<TValue>, TSelected>] {\n const [debouncedValue, setDebouncedValue, debouncer] = createDebouncedSignal(\n value(),\n initialOptions,\n selector,\n )\n\n createEffect(() => {\n setDebouncedValue(value() as any)\n })\n\n return [debouncedValue, debouncer]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,qBACd,OACA,gBACA,UAC+D;CAC/D,MAAM,CAAC,gBAAgB,mBAAmB,aAAaA,oDACrD,MAAM,GACN,gBACA,QACF;CAEA,iCAAmB;EACjB,kBAAkB,MAAM,CAAQ;CAClC,CAAC;CAED,OAAO,CAAC,gBAAgB,SAAS;AACnC"}
@@ -1,70 +0,0 @@
1
- import { SolidDebouncer, SolidDebouncerOptions } from "./createDebouncer.cjs";
2
- import { Accessor, Setter } from "solid-js";
3
- import { DebouncerState } from "@tanstack/pacer/debouncer";
4
- //#region src/debouncer/createDebouncedValue.d.ts
5
- /**
6
- * A Solid hook that creates a debounced value that updates only after a specified delay.
7
- * Unlike createDebouncedSignal, this hook automatically tracks changes to the input value
8
- * and updates the debounced value accordingly.
9
- *
10
- * The debounced value will only update after the specified wait time has elapsed since
11
- * the last change to the input value. If the input value changes again before the wait
12
- * time expires, the timer resets and starts waiting again.
13
- *
14
- * This is useful for deriving debounced values from props or state that change frequently,
15
- * like search queries or form inputs, where you want to limit how often downstream effects
16
- * or calculations occur.
17
- *
18
- * The hook returns a tuple containing:
19
- * - An Accessor that provides the current debounced value
20
- * - The debouncer instance with control methods
21
- *
22
- * ## State Management and Selector
23
- *
24
- * The hook uses TanStack Store for reactive state management via the underlying debouncer instance.
25
- * The `selector` parameter allows you to specify which debouncer state changes will trigger reactive updates,
26
- * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
27
- *
28
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
29
- * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you
30
- * full control over when your component subscribes to state changes. Only when you provide a selector will
31
- * the reactive system track the selected state values.
32
- *
33
- * Available debouncer state properties:
34
- * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
35
- * - `executionCount`: Number of function executions that have been completed
36
- * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
37
- * - `lastArgs`: The arguments from the most recent call to maybeExecute
38
- * - `status`: Current execution status ('disabled' | 'idle' | 'pending')
39
- *
40
- * @example
41
- * ```tsx
42
- * // Default behavior - no reactive state subscriptions
43
- * const [searchQuery, setSearchQuery] = createSignal('');
44
- * const [debouncedQuery, debouncer] = createDebouncedValue(searchQuery, {
45
- * wait: 500 // Wait 500ms after last change
46
- * });
47
- *
48
- * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)
49
- * const [debouncedQuery, debouncer] = createDebouncedValue(
50
- * searchQuery,
51
- * { wait: 500 },
52
- * (state) => ({ isPending: state.isPending })
53
- * );
54
- *
55
- * // debouncedQuery will update 500ms after searchQuery stops changing
56
- * createEffect(() => {
57
- * fetchSearchResults(debouncedQuery());
58
- * });
59
- *
60
- * // Access debouncer state via signals
61
- * console.log('Is pending:', debouncer.state().isPending);
62
- *
63
- * // Control the debouncer
64
- * debouncer.cancel(); // Cancel any pending updates
65
- * ```
66
- */
67
- declare function createDebouncedValue<TValue, TSelected = {}>(value: Accessor<TValue>, initialOptions: SolidDebouncerOptions<Setter<TValue>, TSelected>, selector?: (state: DebouncerState<Setter<TValue>>) => TSelected): [Accessor<TValue>, SolidDebouncer<Setter<TValue>, TSelected>];
68
- //#endregion
69
- export { createDebouncedValue };
70
- //# sourceMappingURL=createDebouncedValue.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createDebouncedValue.js","names":[],"sources":["../../src/debouncer/createDebouncedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createDebouncedSignal } from './createDebouncedSignal'\nimport type { SolidDebouncer, SolidDebouncerOptions } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { DebouncerState } from '@tanstack/pacer/debouncer'\n\n/**\n * A Solid hook that creates a debounced value that updates only after a specified delay.\n * Unlike createDebouncedSignal, 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 a tuple containing:\n * - An Accessor that provides the current debounced value\n * - The debouncer instance with 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 reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available 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] = createSignal('');\n * const [debouncedQuery, debouncer] = createDebouncedValue(searchQuery, {\n * wait: 500 // Wait 500ms after last change\n * });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [debouncedQuery, debouncer] = createDebouncedValue(\n * searchQuery,\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // debouncedQuery will update 500ms after searchQuery stops changing\n * createEffect(() => {\n * fetchSearchResults(debouncedQuery());\n * });\n *\n * // Access debouncer state via signals\n * console.log('Is pending:', debouncer.state().isPending);\n *\n * // Control the debouncer\n * debouncer.cancel(); // Cancel any pending updates\n * ```\n */\nexport function createDebouncedValue<TValue, TSelected = {}>(\n value: Accessor<TValue>,\n initialOptions: SolidDebouncerOptions<Setter<TValue>, TSelected>,\n selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): [Accessor<TValue>, SolidDebouncer<Setter<TValue>, TSelected>] {\n const [debouncedValue, setDebouncedValue, debouncer] = createDebouncedSignal(\n value(),\n initialOptions,\n selector,\n )\n\n createEffect(() => {\n setDebouncedValue(value() as any)\n })\n\n return [debouncedValue, debouncer]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,qBACd,OACA,gBACA,UAC+D;CAC/D,MAAM,CAAC,gBAAgB,mBAAmB,aAAa,sBACrD,MAAM,GACN,gBACA,QACF;CAEA,mBAAmB;EACjB,kBAAkB,MAAM,CAAQ;CAClC,CAAC;CAED,OAAO,CAAC,gBAAgB,SAAS;AACnC"}
@@ -1,129 +0,0 @@
1
- const require_PacerProvider = require('../provider/PacerProvider.cjs');
2
- let solid_js = require("solid-js");
3
- let _tanstack_solid_store = require("@tanstack/solid-store");
4
- let _tanstack_pacer_debouncer = require("@tanstack/pacer/debouncer");
5
-
6
- //#region src/debouncer/createDebouncer.ts
7
- /**
8
- * A Solid hook that creates and manages a Debouncer instance.
9
- *
10
- * This is a lower-level hook that provides direct access to the Debouncer's functionality without
11
- * any built-in state management. This allows you to integrate it with any state management solution
12
- * you prefer (createSignal, Redux, Zustand, etc.).
13
- *
14
- * This hook provides debouncing functionality to limit how often a function can be called,
15
- * waiting for a specified delay before executing the latest call. This is useful for handling
16
- * frequent events like window resizing, scroll events, or real-time search inputs.
17
- *
18
- * The debouncer will only execute the function after the specified wait time has elapsed
19
- * since the last call. If the function is called again before the wait time expires, the
20
- * timer resets and starts waiting again.
21
- *
22
- * ## State Management and Selector
23
- *
24
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
25
- * in two ways:
26
- *
27
- * **1. Using `debouncer.Subscribe` component (Recommended for component tree subscriptions)**
28
- *
29
- * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
30
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
31
- * in child components.
32
- *
33
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
34
- *
35
- * The `selector` parameter allows you to specify which state changes will trigger reactive updates
36
- * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
37
- * state changes occur.
38
- *
39
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
40
- * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
41
- * updates and gives you full control over when your component tracks state changes.
42
- *
43
- * Available state properties:
44
- * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
45
- * - `executionCount`: Number of function executions that have been completed
46
- * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
47
- * - `lastArgs`: The arguments from the most recent call to maybeExecute
48
- * - `status`: Current execution status ('disabled' | 'idle' | 'pending')
49
- *
50
- * ## Unmount behavior
51
- *
52
- * By default, the primitive cancels any pending execution when the owning component unmounts.
53
- * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
54
- *
55
- * ```tsx
56
- * const debouncer = createDebouncer(fn, {
57
- * wait: 500,
58
- * onUnmount: (d) => d.flush()
59
- * });
60
- * ```
61
- *
62
- * @example
63
- * ```tsx
64
- * // Default behavior - no reactive state subscriptions
65
- * const debouncer = createDebouncer(
66
- * (query: string) => fetchSearchResults(query),
67
- * { wait: 500 }
68
- * );
69
- *
70
- * // Opt-in to track isPending changes (optimized for loading states)
71
- * const debouncer = createDebouncer(
72
- * (query: string) => fetchSearchResults(query),
73
- * { wait: 500 },
74
- * (state) => ({ isPending: state.isPending })
75
- * );
76
- *
77
- * // Opt-in to track executionCount changes (optimized for tracking execution)
78
- * const debouncer = createDebouncer(
79
- * (query: string) => fetchSearchResults(query),
80
- * { wait: 500 },
81
- * (state) => ({ executionCount: state.executionCount })
82
- * );
83
- *
84
- * // Multiple state properties - track when any of these change
85
- * const debouncer = createDebouncer(
86
- * (query: string) => fetchSearchResults(query),
87
- * { wait: 500 },
88
- * (state) => ({
89
- * isPending: state.isPending,
90
- * executionCount: state.executionCount,
91
- * status: state.status
92
- * })
93
- * );
94
- *
95
- * // In an event handler
96
- * const handleChange = (e) => {
97
- * debouncer.maybeExecute(e.target.value);
98
- * };
99
- *
100
- * // Access the selected state (will be empty object {} unless selector provided)
101
- * const { isPending } = debouncer.state();
102
- * ```
103
- */
104
- function createDebouncer(fn, options, selector = () => ({})) {
105
- const mergedOptions = {
106
- ...require_PacerProvider.useDefaultPacerOptions().debouncer,
107
- ...options
108
- };
109
- const asyncDebouncer = new _tanstack_pacer_debouncer.Debouncer(fn, mergedOptions);
110
- asyncDebouncer.Subscribe = function Subscribe(props) {
111
- const selected = (0, _tanstack_solid_store.useSelector)(asyncDebouncer.store, props.selector, { compare: _tanstack_solid_store.shallow });
112
- return typeof props.children === "function" ? props.children(selected) : props.children;
113
- };
114
- const state = (0, _tanstack_solid_store.useSelector)(asyncDebouncer.store, selector, { compare: _tanstack_solid_store.shallow });
115
- (0, solid_js.createEffect)(() => {
116
- (0, solid_js.onCleanup)(() => {
117
- if (mergedOptions.onUnmount) mergedOptions.onUnmount(asyncDebouncer);
118
- else asyncDebouncer.cancel();
119
- });
120
- });
121
- return {
122
- ...asyncDebouncer,
123
- state
124
- };
125
- }
126
-
127
- //#endregion
128
- exports.createDebouncer = createDebouncer;
129
- //# sourceMappingURL=createDebouncer.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createDebouncer.cjs","names":["useDefaultPacerOptions","Debouncer","useSelector","shallow"],"sources":["../../src/debouncer/createDebouncer.ts"],"sourcesContent":["import { Debouncer } from '@tanstack/pacer/debouncer'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { shallow, useSelector } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\nexport interface SolidDebouncerOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends DebouncerOptions<TFn> {\n /**\n * Optional callback invoked when the owning 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: SolidDebouncer<TFn, TSelected>) => void\n}\n\nexport interface SolidDebouncer<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Debouncer<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the debouncer state.\n *\n * This is useful for tracking specific parts of the debouncer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <debouncer.Subscribe selector={(state) => ({ isPending: state.isPending })}>\n * {(state) => (\n * <div>{state().isPending ? 'Waiting...' : 'Ready'}</div>\n * )}\n * </debouncer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: DebouncerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the debouncer state changes\n *\n * Use this instead of `debouncer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.\n * Although, you can make the state reactive by using the `useSelector` in your own usage.\n */\n readonly store: Store<Readonly<DebouncerState<TFn>>>\n}\n\n/**\n * A Solid 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 (createSignal, 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` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `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 primitive cancels any pending execution when the owning component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```tsx\n * const debouncer = createDebouncer(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 debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 }\n * );\n *\n * // Opt-in to track isPending changes (optimized for loading states)\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to track executionCount changes (optimized for tracking execution)\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Multiple state properties - track when any of these change\n * const debouncer = createDebouncer(\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 * debouncer.maybeExecute(e.target.value);\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = debouncer.state();\n * ```\n */\nexport function createDebouncer<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: SolidDebouncerOptions<TFn, TSelected>,\n selector: (state: DebouncerState<TFn>) => TSelected = () => ({}) as TSelected,\n): SolidDebouncer<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().debouncer,\n ...options,\n } as SolidDebouncerOptions<TFn, TSelected>\n const asyncDebouncer = new Debouncer<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidDebouncer<TFn, TSelected>\n\n asyncDebouncer.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: DebouncerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(asyncDebouncer.store, props.selector, {\n compare: shallow,\n })\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useSelector(asyncDebouncer.store, selector, {\n compare: shallow,\n })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(asyncDebouncer)\n } else {\n asyncDebouncer.cancel()\n }\n })\n })\n\n return {\n ...asyncDebouncer,\n state,\n } as SolidDebouncer<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2JA,SAAgB,gBACd,IACA,SACA,kBAA6D,CAAC,IAC9B;CAChC,MAAM,gBAAgB;EACpB,GAAGA,6CAAuB,CAAC,CAAC;EAC5B,GAAG;CACL;CACA,MAAM,iBAAiB,IAAIC,oCACzB,IACA,aACF;CAEA,eAAe,YAAY,SAAS,UAAqB,OAGtD;EACD,MAAM,eAAWC,mCAAY,eAAe,OAAO,MAAM,UAAU,EACjE,SAASC,8BACX,CAAC;EAED,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,QAAQ,IACvB,MAAM;CACZ;CAEA,MAAM,YAAQD,mCAAY,eAAe,OAAO,UAAU,EACxD,SAASC,8BACX,CAAC;CAED,iCAAmB;EACjB,8BAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,cAAc;QAEtC,eAAe,OAAO;EAE1B,CAAC;CACH,CAAC;CAED,OAAO;EACL,GAAG;EACH;CACF;AACF"}
@@ -1,144 +0,0 @@
1
- import { Store } from "@tanstack/solid-store";
2
- import { Accessor, JSX } from "solid-js";
3
- import { AnyFunction } from "@tanstack/pacer/types";
4
- import { Debouncer, DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
5
- //#region src/debouncer/createDebouncer.d.ts
6
- interface SolidDebouncerOptions<TFn extends AnyFunction, TSelected = {}> extends DebouncerOptions<TFn> {
7
- /**
8
- * Optional callback invoked when the owning component unmounts. Receives the debouncer instance.
9
- * When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.
10
- */
11
- onUnmount?: (debouncer: SolidDebouncer<TFn, TSelected>) => void;
12
- }
13
- interface SolidDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<Debouncer<TFn>, 'store'> {
14
- /**
15
- * A Solid component that allows you to subscribe to the debouncer state.
16
- *
17
- * This is useful for tracking specific parts of the debouncer state
18
- * deep in your component tree without needing to pass a selector to the hook.
19
- *
20
- * @example
21
- * <debouncer.Subscribe selector={(state) => ({ isPending: state.isPending })}>
22
- * {(state) => (
23
- * <div>{state().isPending ? 'Waiting...' : 'Ready'}</div>
24
- * )}
25
- * </debouncer.Subscribe>
26
- */
27
- Subscribe: <TSelected>(props: {
28
- selector: (state: DebouncerState<TFn>) => TSelected;
29
- children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
30
- }) => JSX.Element;
31
- /**
32
- * Reactive state that will be updated when the debouncer state changes
33
- *
34
- * Use this instead of `debouncer.store.state`
35
- */
36
- readonly state: Accessor<Readonly<TSelected>>;
37
- /**
38
- * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.
39
- * The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
40
- * Although, you can make the state reactive by using the `useSelector` in your own usage.
41
- */
42
- readonly store: Store<Readonly<DebouncerState<TFn>>>;
43
- }
44
- /**
45
- * A Solid hook that creates and manages a Debouncer instance.
46
- *
47
- * This is a lower-level hook that provides direct access to the Debouncer's functionality without
48
- * any built-in state management. This allows you to integrate it with any state management solution
49
- * you prefer (createSignal, Redux, Zustand, etc.).
50
- *
51
- * This hook provides debouncing functionality to limit how often a function can be called,
52
- * waiting for a specified delay before executing the latest call. This is useful for handling
53
- * frequent events like window resizing, scroll events, or real-time search inputs.
54
- *
55
- * The debouncer will only execute the function after the specified wait time has elapsed
56
- * since the last call. If the function is called again before the wait time expires, the
57
- * timer resets and starts waiting again.
58
- *
59
- * ## State Management and Selector
60
- *
61
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
62
- * in two ways:
63
- *
64
- * **1. Using `debouncer.Subscribe` component (Recommended for component tree subscriptions)**
65
- *
66
- * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
67
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
68
- * in child components.
69
- *
70
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
71
- *
72
- * The `selector` parameter allows you to specify which state changes will trigger reactive updates
73
- * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
74
- * state changes occur.
75
- *
76
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
77
- * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
78
- * updates and gives you full control over when your component tracks state changes.
79
- *
80
- * Available state properties:
81
- * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
82
- * - `executionCount`: Number of function executions that have been completed
83
- * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
84
- * - `lastArgs`: The arguments from the most recent call to maybeExecute
85
- * - `status`: Current execution status ('disabled' | 'idle' | 'pending')
86
- *
87
- * ## Unmount behavior
88
- *
89
- * By default, the primitive cancels any pending execution when the owning component unmounts.
90
- * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
91
- *
92
- * ```tsx
93
- * const debouncer = createDebouncer(fn, {
94
- * wait: 500,
95
- * onUnmount: (d) => d.flush()
96
- * });
97
- * ```
98
- *
99
- * @example
100
- * ```tsx
101
- * // Default behavior - no reactive state subscriptions
102
- * const debouncer = createDebouncer(
103
- * (query: string) => fetchSearchResults(query),
104
- * { wait: 500 }
105
- * );
106
- *
107
- * // Opt-in to track isPending changes (optimized for loading states)
108
- * const debouncer = createDebouncer(
109
- * (query: string) => fetchSearchResults(query),
110
- * { wait: 500 },
111
- * (state) => ({ isPending: state.isPending })
112
- * );
113
- *
114
- * // Opt-in to track executionCount changes (optimized for tracking execution)
115
- * const debouncer = createDebouncer(
116
- * (query: string) => fetchSearchResults(query),
117
- * { wait: 500 },
118
- * (state) => ({ executionCount: state.executionCount })
119
- * );
120
- *
121
- * // Multiple state properties - track when any of these change
122
- * const debouncer = createDebouncer(
123
- * (query: string) => fetchSearchResults(query),
124
- * { wait: 500 },
125
- * (state) => ({
126
- * isPending: state.isPending,
127
- * executionCount: state.executionCount,
128
- * status: state.status
129
- * })
130
- * );
131
- *
132
- * // In an event handler
133
- * const handleChange = (e) => {
134
- * debouncer.maybeExecute(e.target.value);
135
- * };
136
- *
137
- * // Access the selected state (will be empty object {} unless selector provided)
138
- * const { isPending } = debouncer.state();
139
- * ```
140
- */
141
- declare function createDebouncer<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: SolidDebouncerOptions<TFn, TSelected>, selector?: (state: DebouncerState<TFn>) => TSelected): SolidDebouncer<TFn, TSelected>;
142
- //#endregion
143
- export { SolidDebouncer, SolidDebouncerOptions, createDebouncer };
144
- //# sourceMappingURL=createDebouncer.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createDebouncer.js","names":[],"sources":["../../src/debouncer/createDebouncer.ts"],"sourcesContent":["import { Debouncer } from '@tanstack/pacer/debouncer'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { shallow, useSelector } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\nexport interface SolidDebouncerOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends DebouncerOptions<TFn> {\n /**\n * Optional callback invoked when the owning 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: SolidDebouncer<TFn, TSelected>) => void\n}\n\nexport interface SolidDebouncer<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Debouncer<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the debouncer state.\n *\n * This is useful for tracking specific parts of the debouncer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <debouncer.Subscribe selector={(state) => ({ isPending: state.isPending })}>\n * {(state) => (\n * <div>{state().isPending ? 'Waiting...' : 'Ready'}</div>\n * )}\n * </debouncer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: DebouncerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the debouncer state changes\n *\n * Use this instead of `debouncer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.\n * Although, you can make the state reactive by using the `useSelector` in your own usage.\n */\n readonly store: Store<Readonly<DebouncerState<TFn>>>\n}\n\n/**\n * A Solid 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 (createSignal, 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` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `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 primitive cancels any pending execution when the owning component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```tsx\n * const debouncer = createDebouncer(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 debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 }\n * );\n *\n * // Opt-in to track isPending changes (optimized for loading states)\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to track executionCount changes (optimized for tracking execution)\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Multiple state properties - track when any of these change\n * const debouncer = createDebouncer(\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 * debouncer.maybeExecute(e.target.value);\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = debouncer.state();\n * ```\n */\nexport function createDebouncer<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: SolidDebouncerOptions<TFn, TSelected>,\n selector: (state: DebouncerState<TFn>) => TSelected = () => ({}) as TSelected,\n): SolidDebouncer<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().debouncer,\n ...options,\n } as SolidDebouncerOptions<TFn, TSelected>\n const asyncDebouncer = new Debouncer<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidDebouncer<TFn, TSelected>\n\n asyncDebouncer.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: DebouncerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(asyncDebouncer.store, props.selector, {\n compare: shallow,\n })\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useSelector(asyncDebouncer.store, selector, {\n compare: shallow,\n })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(asyncDebouncer)\n } else {\n asyncDebouncer.cancel()\n }\n })\n })\n\n return {\n ...asyncDebouncer,\n state,\n } as SolidDebouncer<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2JA,SAAgB,gBACd,IACA,SACA,kBAA6D,CAAC,IAC9B;CAChC,MAAM,gBAAgB;EACpB,GAAG,uBAAuB,CAAC,CAAC;EAC5B,GAAG;CACL;CACA,MAAM,iBAAiB,IAAI,UACzB,IACA,aACF;CAEA,eAAe,YAAY,SAAS,UAAqB,OAGtD;EACD,MAAM,WAAW,YAAY,eAAe,OAAO,MAAM,UAAU,EACjE,SAAS,QACX,CAAC;EAED,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,QAAQ,IACvB,MAAM;CACZ;CAEA,MAAM,QAAQ,YAAY,eAAe,OAAO,UAAU,EACxD,SAAS,QACX,CAAC;CAED,mBAAmB;EACjB,gBAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,cAAc;QAEtC,eAAe,OAAO;EAE1B,CAAC;CACH,CAAC;CAED,OAAO;EACL,GAAG;EACH;CACF;AACF"}
@@ -1,15 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_createDebouncer = require('./createDebouncer.cjs');
3
- const require_createDebouncedSignal = require('./createDebouncedSignal.cjs');
4
- const require_createDebouncedValue = require('./createDebouncedValue.cjs');
5
-
6
- exports.createDebouncedSignal = require_createDebouncedSignal.createDebouncedSignal;
7
- exports.createDebouncedValue = require_createDebouncedValue.createDebouncedValue;
8
- exports.createDebouncer = require_createDebouncer.createDebouncer;
9
- var _tanstack_pacer_debouncer = require("@tanstack/pacer/debouncer");
10
- Object.keys(_tanstack_pacer_debouncer).forEach(function (k) {
11
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
12
- enumerable: true,
13
- get: function () { return _tanstack_pacer_debouncer[k]; }
14
- });
15
- });
@@ -1,5 +0,0 @@
1
- import { SolidDebouncer, SolidDebouncerOptions, createDebouncer } from "./createDebouncer.cjs";
2
- import { createDebouncedSignal } from "./createDebouncedSignal.cjs";
3
- import { createDebouncedValue } from "./createDebouncedValue.cjs";
4
- export * from "@tanstack/pacer/debouncer";
5
- export { SolidDebouncer, SolidDebouncerOptions, createDebouncedSignal, createDebouncedValue, createDebouncer };