@tanstack/solid-pacer 0.2.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 (184) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs +32 -0
  3. package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs.map +1 -0
  4. package/dist/cjs/async-debouncer/createAsyncDebouncer.d.cts +42 -0
  5. package/dist/cjs/async-debouncer/index.cjs +12 -0
  6. package/dist/cjs/async-debouncer/index.cjs.map +1 -0
  7. package/dist/cjs/async-debouncer/index.d.cts +2 -0
  8. package/dist/cjs/async-queuer/createAsyncQueuer.cjs +69 -0
  9. package/dist/cjs/async-queuer/createAsyncQueuer.cjs.map +1 -0
  10. package/dist/cjs/async-queuer/createAsyncQueuer.d.cts +90 -0
  11. package/dist/cjs/async-queuer/index.cjs +12 -0
  12. package/dist/cjs/async-queuer/index.cjs.map +1 -0
  13. package/dist/cjs/async-queuer/index.d.cts +2 -0
  14. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs +50 -0
  15. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs.map +1 -0
  16. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.d.cts +46 -0
  17. package/dist/cjs/async-rate-limiter/index.cjs +12 -0
  18. package/dist/cjs/async-rate-limiter/index.cjs.map +1 -0
  19. package/dist/cjs/async-rate-limiter/index.d.cts +2 -0
  20. package/dist/cjs/async-throttler/createAsyncThrottler.cjs +42 -0
  21. package/dist/cjs/async-throttler/createAsyncThrottler.cjs.map +1 -0
  22. package/dist/cjs/async-throttler/createAsyncThrottler.d.cts +46 -0
  23. package/dist/cjs/async-throttler/index.cjs +12 -0
  24. package/dist/cjs/async-throttler/index.cjs.map +1 -0
  25. package/dist/cjs/async-throttler/index.d.cts +2 -0
  26. package/dist/cjs/compare/index.cjs +10 -0
  27. package/dist/cjs/compare/index.cjs.map +1 -0
  28. package/dist/cjs/compare/index.d.cts +1 -0
  29. package/dist/cjs/debouncer/createDebouncedSignal.cjs +11 -0
  30. package/dist/cjs/debouncer/createDebouncedSignal.cjs.map +1 -0
  31. package/dist/cjs/debouncer/createDebouncedSignal.d.cts +47 -0
  32. package/dist/cjs/debouncer/createDebouncedValue.cjs +19 -0
  33. package/dist/cjs/debouncer/createDebouncedValue.cjs.map +1 -0
  34. package/dist/cjs/debouncer/createDebouncedValue.d.cts +44 -0
  35. package/dist/cjs/debouncer/createDebouncer.cjs +32 -0
  36. package/dist/cjs/debouncer/createDebouncer.cjs.map +1 -0
  37. package/dist/cjs/debouncer/createDebouncer.d.cts +47 -0
  38. package/dist/cjs/debouncer/index.cjs +16 -0
  39. package/dist/cjs/debouncer/index.cjs.map +1 -0
  40. package/dist/cjs/debouncer/index.d.cts +4 -0
  41. package/dist/cjs/index.cjs +38 -0
  42. package/dist/cjs/index.cjs.map +1 -0
  43. package/dist/cjs/index.d.cts +18 -0
  44. package/dist/cjs/queuer/createQueuer.cjs +66 -0
  45. package/dist/cjs/queuer/createQueuer.cjs.map +1 -0
  46. package/dist/cjs/queuer/createQueuer.d.cts +82 -0
  47. package/dist/cjs/queuer/index.cjs +12 -0
  48. package/dist/cjs/queuer/index.cjs.map +1 -0
  49. package/dist/cjs/queuer/index.d.cts +2 -0
  50. package/dist/cjs/rate-limiter/createRateLimitedSignal.cjs +15 -0
  51. package/dist/cjs/rate-limiter/createRateLimitedSignal.cjs.map +1 -0
  52. package/dist/cjs/rate-limiter/createRateLimitedSignal.d.cts +58 -0
  53. package/dist/cjs/rate-limiter/createRateLimitedValue.cjs +13 -0
  54. package/dist/cjs/rate-limiter/createRateLimitedValue.cjs.map +1 -0
  55. package/dist/cjs/rate-limiter/createRateLimitedValue.d.cts +51 -0
  56. package/dist/cjs/rate-limiter/createRateLimiter.cjs +50 -0
  57. package/dist/cjs/rate-limiter/createRateLimiter.cjs.map +1 -0
  58. package/dist/cjs/rate-limiter/createRateLimiter.d.cts +49 -0
  59. package/dist/cjs/rate-limiter/index.cjs +16 -0
  60. package/dist/cjs/rate-limiter/index.cjs.map +1 -0
  61. package/dist/cjs/rate-limiter/index.d.cts +4 -0
  62. package/dist/cjs/throttler/createThrottledSignal.cjs +11 -0
  63. package/dist/cjs/throttler/createThrottledSignal.cjs.map +1 -0
  64. package/dist/cjs/throttler/createThrottledSignal.d.cts +42 -0
  65. package/dist/cjs/throttler/createThrottledValue.cjs +19 -0
  66. package/dist/cjs/throttler/createThrottledValue.cjs.map +1 -0
  67. package/dist/cjs/throttler/createThrottledValue.d.cts +36 -0
  68. package/dist/cjs/throttler/createThrottler.cjs +42 -0
  69. package/dist/cjs/throttler/createThrottler.cjs.map +1 -0
  70. package/dist/cjs/throttler/createThrottler.d.cts +47 -0
  71. package/dist/cjs/throttler/index.cjs +16 -0
  72. package/dist/cjs/throttler/index.cjs.map +1 -0
  73. package/dist/cjs/throttler/index.d.cts +4 -0
  74. package/dist/cjs/types/index.cjs +10 -0
  75. package/dist/cjs/types/index.cjs.map +1 -0
  76. package/dist/cjs/types/index.d.cts +1 -0
  77. package/dist/cjs/utils/index.cjs +10 -0
  78. package/dist/cjs/utils/index.cjs.map +1 -0
  79. package/dist/cjs/utils/index.d.cts +1 -0
  80. package/dist/esm/async-debouncer/createAsyncDebouncer.d.ts +42 -0
  81. package/dist/esm/async-debouncer/createAsyncDebouncer.js +32 -0
  82. package/dist/esm/async-debouncer/createAsyncDebouncer.js.map +1 -0
  83. package/dist/esm/async-debouncer/index.d.ts +2 -0
  84. package/dist/esm/async-debouncer/index.js +6 -0
  85. package/dist/esm/async-debouncer/index.js.map +1 -0
  86. package/dist/esm/async-queuer/createAsyncQueuer.d.ts +90 -0
  87. package/dist/esm/async-queuer/createAsyncQueuer.js +69 -0
  88. package/dist/esm/async-queuer/createAsyncQueuer.js.map +1 -0
  89. package/dist/esm/async-queuer/index.d.ts +2 -0
  90. package/dist/esm/async-queuer/index.js +6 -0
  91. package/dist/esm/async-queuer/index.js.map +1 -0
  92. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.d.ts +46 -0
  93. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js +50 -0
  94. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js.map +1 -0
  95. package/dist/esm/async-rate-limiter/index.d.ts +2 -0
  96. package/dist/esm/async-rate-limiter/index.js +6 -0
  97. package/dist/esm/async-rate-limiter/index.js.map +1 -0
  98. package/dist/esm/async-throttler/createAsyncThrottler.d.ts +46 -0
  99. package/dist/esm/async-throttler/createAsyncThrottler.js +42 -0
  100. package/dist/esm/async-throttler/createAsyncThrottler.js.map +1 -0
  101. package/dist/esm/async-throttler/index.d.ts +2 -0
  102. package/dist/esm/async-throttler/index.js +6 -0
  103. package/dist/esm/async-throttler/index.js.map +1 -0
  104. package/dist/esm/compare/index.d.ts +1 -0
  105. package/dist/esm/compare/index.js +2 -0
  106. package/dist/esm/compare/index.js.map +1 -0
  107. package/dist/esm/debouncer/createDebouncedSignal.d.ts +47 -0
  108. package/dist/esm/debouncer/createDebouncedSignal.js +11 -0
  109. package/dist/esm/debouncer/createDebouncedSignal.js.map +1 -0
  110. package/dist/esm/debouncer/createDebouncedValue.d.ts +44 -0
  111. package/dist/esm/debouncer/createDebouncedValue.js +19 -0
  112. package/dist/esm/debouncer/createDebouncedValue.js.map +1 -0
  113. package/dist/esm/debouncer/createDebouncer.d.ts +47 -0
  114. package/dist/esm/debouncer/createDebouncer.js +32 -0
  115. package/dist/esm/debouncer/createDebouncer.js.map +1 -0
  116. package/dist/esm/debouncer/index.d.ts +4 -0
  117. package/dist/esm/debouncer/index.js +10 -0
  118. package/dist/esm/debouncer/index.js.map +1 -0
  119. package/dist/esm/index.d.ts +18 -0
  120. package/dist/esm/index.js +32 -0
  121. package/dist/esm/index.js.map +1 -0
  122. package/dist/esm/queuer/createQueuer.d.ts +82 -0
  123. package/dist/esm/queuer/createQueuer.js +66 -0
  124. package/dist/esm/queuer/createQueuer.js.map +1 -0
  125. package/dist/esm/queuer/index.d.ts +2 -0
  126. package/dist/esm/queuer/index.js +6 -0
  127. package/dist/esm/queuer/index.js.map +1 -0
  128. package/dist/esm/rate-limiter/createRateLimitedSignal.d.ts +58 -0
  129. package/dist/esm/rate-limiter/createRateLimitedSignal.js +15 -0
  130. package/dist/esm/rate-limiter/createRateLimitedSignal.js.map +1 -0
  131. package/dist/esm/rate-limiter/createRateLimitedValue.d.ts +51 -0
  132. package/dist/esm/rate-limiter/createRateLimitedValue.js +13 -0
  133. package/dist/esm/rate-limiter/createRateLimitedValue.js.map +1 -0
  134. package/dist/esm/rate-limiter/createRateLimiter.d.ts +49 -0
  135. package/dist/esm/rate-limiter/createRateLimiter.js +50 -0
  136. package/dist/esm/rate-limiter/createRateLimiter.js.map +1 -0
  137. package/dist/esm/rate-limiter/index.d.ts +4 -0
  138. package/dist/esm/rate-limiter/index.js +10 -0
  139. package/dist/esm/rate-limiter/index.js.map +1 -0
  140. package/dist/esm/throttler/createThrottledSignal.d.ts +42 -0
  141. package/dist/esm/throttler/createThrottledSignal.js +11 -0
  142. package/dist/esm/throttler/createThrottledSignal.js.map +1 -0
  143. package/dist/esm/throttler/createThrottledValue.d.ts +36 -0
  144. package/dist/esm/throttler/createThrottledValue.js +19 -0
  145. package/dist/esm/throttler/createThrottledValue.js.map +1 -0
  146. package/dist/esm/throttler/createThrottler.d.ts +47 -0
  147. package/dist/esm/throttler/createThrottler.js +42 -0
  148. package/dist/esm/throttler/createThrottler.js.map +1 -0
  149. package/dist/esm/throttler/index.d.ts +4 -0
  150. package/dist/esm/throttler/index.js +10 -0
  151. package/dist/esm/throttler/index.js.map +1 -0
  152. package/dist/esm/types/index.d.ts +1 -0
  153. package/dist/esm/types/index.js +2 -0
  154. package/dist/esm/types/index.js.map +1 -0
  155. package/dist/esm/utils/index.d.ts +1 -0
  156. package/dist/esm/utils/index.js +2 -0
  157. package/dist/esm/utils/index.js.map +1 -0
  158. package/package.json +163 -0
  159. package/src/async-debouncer/createAsyncDebouncer.ts +89 -0
  160. package/src/async-debouncer/index.ts +4 -0
  161. package/src/async-queuer/createAsyncQueuer.ts +175 -0
  162. package/src/async-queuer/index.ts +3 -0
  163. package/src/async-rate-limiter/createAsyncRateLimiter.ts +116 -0
  164. package/src/async-rate-limiter/index.ts +4 -0
  165. package/src/async-throttler/createAsyncThrottler.ts +106 -0
  166. package/src/async-throttler/index.ts +4 -0
  167. package/src/compare/index.ts +1 -0
  168. package/src/debouncer/createDebouncedSignal.ts +59 -0
  169. package/src/debouncer/createDebouncedValue.ts +64 -0
  170. package/src/debouncer/createDebouncer.ts +90 -0
  171. package/src/debouncer/index.ts +6 -0
  172. package/src/index.ts +36 -0
  173. package/src/queuer/createQueuer.ts +167 -0
  174. package/src/queuer/index.ts +3 -0
  175. package/src/rate-limiter/createRateLimitedSignal.ts +74 -0
  176. package/src/rate-limiter/createRateLimitedValue.ts +66 -0
  177. package/src/rate-limiter/createRateLimiter.ts +115 -0
  178. package/src/rate-limiter/index.ts +5 -0
  179. package/src/throttler/createThrottledSignal.ts +52 -0
  180. package/src/throttler/createThrottledValue.ts +56 -0
  181. package/src/throttler/createThrottler.ts +106 -0
  182. package/src/throttler/index.ts +6 -0
  183. package/src/types/index.ts +1 -0
  184. package/src/utils/index.ts +1 -0
@@ -0,0 +1,32 @@
1
+ import { Debouncer } from "@tanstack/pacer/debouncer";
2
+ import { createSignal } from "solid-js";
3
+ import { bindInstanceMethods } from "@tanstack/pacer/utils";
4
+ function createDebouncer(fn, initialOptions) {
5
+ const debouncer = new Debouncer(fn, initialOptions);
6
+ const [executionCount, setExecutionCount] = createSignal(
7
+ debouncer.getExecutionCount()
8
+ );
9
+ const [isPending, setIsPending] = createSignal(debouncer.getIsPending());
10
+ function setOptions(newOptions) {
11
+ debouncer.setOptions({
12
+ ...newOptions,
13
+ onExecute: (debouncer2) => {
14
+ setExecutionCount(debouncer2.getExecutionCount());
15
+ setIsPending(debouncer2.getIsPending());
16
+ const onExecute = newOptions.onExecute ?? initialOptions.onExecute;
17
+ onExecute == null ? void 0 : onExecute(debouncer2);
18
+ }
19
+ });
20
+ }
21
+ setOptions(initialOptions);
22
+ return {
23
+ ...bindInstanceMethods(debouncer),
24
+ executionCount,
25
+ isPending,
26
+ setOptions
27
+ };
28
+ }
29
+ export {
30
+ createDebouncer
31
+ };
32
+ //# sourceMappingURL=createDebouncer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createDebouncer.js","sources":["../../../src/debouncer/createDebouncer.ts"],"sourcesContent":["import { Debouncer } from '@tanstack/pacer/debouncer'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { DebouncerOptions } from '@tanstack/pacer/debouncer'\n\n/**\n * An extension of the Debouncer class that adds Solid signals to access the internal state of the debouncer\n */\nexport interface SolidDebouncer<\n TFn extends AnyFunction,\n TArgs extends Parameters<TFn>,\n> extends Omit<Debouncer<TFn, TArgs>, 'getExecutionCount' | 'getIsPending'> {\n executionCount: Accessor<number>\n isPending: Accessor<boolean>\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 * @example\n * ```tsx\n * // Debounce a search function to limit API calls\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 } // Wait 500ms after last keystroke\n * );\n *\n * // In an event handler\n * const handleChange = (e) => {\n * debouncer.maybeExecute(e.target.value);\n * };\n *\n * // Access debouncer state via signals\n * console.log('Executions:', debouncer.executionCount());\n * console.log('Is pending:', debouncer.isPending());\n *\n * // Update options\n * debouncer.setOptions({ wait: 1000 });\n * ```\n */\nexport function createDebouncer<\n TFn extends AnyFunction,\n TArgs extends Parameters<TFn>,\n>(\n fn: TFn,\n initialOptions: DebouncerOptions<TFn, TArgs>,\n): SolidDebouncer<TFn, TArgs> {\n const debouncer = new Debouncer<TFn, TArgs>(fn, initialOptions)\n\n const [executionCount, setExecutionCount] = createSignal(\n debouncer.getExecutionCount(),\n )\n const [isPending, setIsPending] = createSignal(debouncer.getIsPending())\n\n function setOptions(newOptions: Partial<DebouncerOptions<TFn, TArgs>>) {\n debouncer.setOptions({\n ...newOptions,\n onExecute: (debouncer) => {\n setExecutionCount(debouncer.getExecutionCount())\n setIsPending(debouncer.getIsPending())\n\n const onExecute = newOptions.onExecute ?? initialOptions.onExecute\n onExecute?.(debouncer)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...bindInstanceMethods(debouncer),\n executionCount,\n isPending,\n setOptions,\n }\n}\n"],"names":["debouncer"],"mappings":";;;AAsDgB,SAAA,gBAId,IACA,gBAC4B;AAC5B,QAAM,YAAY,IAAI,UAAsB,IAAI,cAAc;AAExD,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,UAAU,kBAAkB;AAAA,EAC9B;AACA,QAAM,CAAC,WAAW,YAAY,IAAI,aAAa,UAAU,cAAc;AAEvE,WAAS,WAAW,YAAmD;AACrE,cAAU,WAAW;AAAA,MACnB,GAAG;AAAA,MACH,WAAW,CAACA,eAAc;AACNA,0BAAAA,WAAU,mBAAmB;AAClCA,qBAAAA,WAAU,cAAc;AAE/B,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MAAS;AAAA,IACvB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAG,oBAAoB,SAAS;AAAA,IAChC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
@@ -0,0 +1,4 @@
1
+ export * from '@tanstack/pacer/debouncer';
2
+ export * from './createDebouncedSignal.js';
3
+ export * from './createDebouncedValue.js';
4
+ export * from './createDebouncer.js';
@@ -0,0 +1,10 @@
1
+ export * from "@tanstack/pacer/debouncer";
2
+ import { createDebouncedSignal } from "./createDebouncedSignal.js";
3
+ import { createDebouncedValue } from "./createDebouncedValue.js";
4
+ import { createDebouncer } from "./createDebouncer.js";
5
+ export {
6
+ createDebouncedSignal,
7
+ createDebouncedValue,
8
+ createDebouncer
9
+ };
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -0,0 +1,18 @@
1
+ export * from '@tanstack/pacer';
2
+ /**
3
+ * Export every hook individually - DON'T export from barrel files
4
+ */
5
+ export * from './async-debouncer/createAsyncDebouncer.js';
6
+ export * from './async-queuer/createAsyncQueuer.js';
7
+ export * from './async-rate-limiter/createAsyncRateLimiter.js';
8
+ export * from './async-throttler/createAsyncThrottler.js';
9
+ export * from './debouncer/createDebouncedSignal.js';
10
+ export * from './debouncer/createDebouncedValue.js';
11
+ export * from './debouncer/createDebouncer.js';
12
+ export * from './queuer/createQueuer.js';
13
+ export * from './rate-limiter/createRateLimiter.js';
14
+ export * from './rate-limiter/createRateLimitedSignal.js';
15
+ export * from './rate-limiter/createRateLimitedValue.js';
16
+ export * from './throttler/createThrottledSignal.js';
17
+ export * from './throttler/createThrottledValue.js';
18
+ export * from './throttler/createThrottler.js';
@@ -0,0 +1,32 @@
1
+ export * from "@tanstack/pacer";
2
+ import { createAsyncDebouncer } from "./async-debouncer/createAsyncDebouncer.js";
3
+ import { createAsyncQueuer } from "./async-queuer/createAsyncQueuer.js";
4
+ import { createAsyncRateLimiter } from "./async-rate-limiter/createAsyncRateLimiter.js";
5
+ import { createAsyncThrottler } from "./async-throttler/createAsyncThrottler.js";
6
+ import { createDebouncedSignal } from "./debouncer/createDebouncedSignal.js";
7
+ import { createDebouncedValue } from "./debouncer/createDebouncedValue.js";
8
+ import { createDebouncer } from "./debouncer/createDebouncer.js";
9
+ import { createQueuer } from "./queuer/createQueuer.js";
10
+ import { createRateLimiter } from "./rate-limiter/createRateLimiter.js";
11
+ import { createRateLimitedSignal } from "./rate-limiter/createRateLimitedSignal.js";
12
+ import { createRateLimitedValue } from "./rate-limiter/createRateLimitedValue.js";
13
+ import { createThrottledSignal } from "./throttler/createThrottledSignal.js";
14
+ import { createThrottledValue } from "./throttler/createThrottledValue.js";
15
+ import { createThrottler } from "./throttler/createThrottler.js";
16
+ export {
17
+ createAsyncDebouncer,
18
+ createAsyncQueuer,
19
+ createAsyncRateLimiter,
20
+ createAsyncThrottler,
21
+ createDebouncedSignal,
22
+ createDebouncedValue,
23
+ createDebouncer,
24
+ createQueuer,
25
+ createRateLimitedSignal,
26
+ createRateLimitedValue,
27
+ createRateLimiter,
28
+ createThrottledSignal,
29
+ createThrottledValue,
30
+ createThrottler
31
+ };
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
@@ -0,0 +1,82 @@
1
+ import { Queuer, QueuerOptions } from '@tanstack/pacer/queuer';
2
+ import { Accessor } from 'solid-js';
3
+ export interface SolidQueuer<TValue> extends Omit<Queuer<TValue>, 'getAllItems' | 'getExecutionCount' | 'getIsEmpty' | 'getIsFull' | 'getIsIdle' | 'getIsRunning' | 'getPeek' | 'getSize'> {
4
+ /**
5
+ * Signal version of `getAllItems`
6
+ */
7
+ allItems: Accessor<Array<TValue>>;
8
+ /**
9
+ * Signal version of `getExecutionCount`
10
+ */
11
+ executionCount: Accessor<number>;
12
+ /**
13
+ * Signal version of `getIsEmpty`
14
+ */
15
+ isEmpty: Accessor<boolean>;
16
+ /**
17
+ * Signal version of `getIsFull`
18
+ */
19
+ isFull: Accessor<boolean>;
20
+ /**
21
+ * Signal version of `getIsIdle`
22
+ */
23
+ isIdle: Accessor<boolean>;
24
+ /**
25
+ * Signal version of `getIsRunning`
26
+ */
27
+ isRunning: Accessor<boolean>;
28
+ /**
29
+ * Signal version of `getPeek`
30
+ */
31
+ peek: Accessor<TValue | undefined>;
32
+ /**
33
+ * Signal version of `getSize`
34
+ */
35
+ size: Accessor<number>;
36
+ }
37
+ /**
38
+ * A Solid hook that creates and manages a Queuer instance.
39
+ *
40
+ * This is a lower-level hook that provides direct access to the Queuer's functionality without
41
+ * any built-in state management. This allows you to integrate it with any state management solution
42
+ * you prefer (createSignal, Redux, Zustand, etc.) by utilizing the onItemsChange callback.
43
+ *
44
+ * For a hook with built-in state management, see createQueuerSignal.
45
+ *
46
+ * The Queuer extends the base Queue to add processing capabilities. Items are processed
47
+ * synchronously in order, with optional delays between processing each item. The queuer includes
48
+ * an internal tick mechanism that can be started and stopped, making it useful as a scheduler.
49
+ * When started, it will process one item per tick, with an optional wait time between ticks.
50
+ *
51
+ * By default uses FIFO (First In First Out) behavior, but can be configured for LIFO
52
+ * (Last In First Out) by specifying 'front' position when adding items.
53
+ *
54
+ * @example
55
+ * ```tsx
56
+ * // Example with custom state management and scheduling
57
+ * const [items, setItems] = createSignal([]);
58
+ *
59
+ * const queue = createQueuer({
60
+ * started: true, // Start processing immediately
61
+ * wait: 1000, // Process one item every second
62
+ * onItemsChange: (queue) => setItems(queue.getAllItems()),
63
+ * getPriority: (item) => item.priority // Process higher priority items first
64
+ * });
65
+ *
66
+ * // Add items to process - they'll be handled automatically
67
+ * queue.addItem('task1');
68
+ * queue.addItem('task2');
69
+ *
70
+ * // Control the scheduler
71
+ * queue.stop(); // Pause processing
72
+ * queue.start(); // Resume processing
73
+ *
74
+ * // Access queue state via signals
75
+ * console.log('Items:', queue.allItems());
76
+ * console.log('Size:', queue.size());
77
+ * console.log('Is empty:', queue.isEmpty());
78
+ * console.log('Is running:', queue.isRunning());
79
+ * console.log('Next item:', queue.peek());
80
+ * ```
81
+ */
82
+ export declare function createQueuer<TValue>(initialOptions?: QueuerOptions<TValue>): SolidQueuer<TValue>;
@@ -0,0 +1,66 @@
1
+ import { Queuer } from "@tanstack/pacer/queuer";
2
+ import { createSignal } from "solid-js";
3
+ import { bindInstanceMethods } from "@tanstack/pacer/utils";
4
+ function createQueuer(initialOptions = {}) {
5
+ const queuer = new Queuer(initialOptions);
6
+ const [allItems, setAllItems] = createSignal(
7
+ queuer.getAllItems()
8
+ );
9
+ const [executionCount, setExecutionCount] = createSignal(
10
+ queuer.getExecutionCount()
11
+ );
12
+ const [rejectionCount, setRejectionCount] = createSignal(
13
+ queuer.getRejectionCount()
14
+ );
15
+ const [isEmpty, setIsEmpty] = createSignal(queuer.getIsEmpty());
16
+ const [isFull, setIsFull] = createSignal(queuer.getIsFull());
17
+ const [isIdle, setIsIdle] = createSignal(queuer.getIsIdle());
18
+ const [isRunning, setIsRunning] = createSignal(queuer.getIsRunning());
19
+ const [peek, setPeek] = createSignal(queuer.getPeek());
20
+ const [size, setSize] = createSignal(queuer.getSize());
21
+ function setOptions(newOptions) {
22
+ queuer.setOptions({
23
+ ...newOptions,
24
+ onItemsChange: (queuer2) => {
25
+ setAllItems(queuer2.getAllItems());
26
+ setExecutionCount(queuer2.getExecutionCount());
27
+ setIsEmpty(queuer2.getIsEmpty());
28
+ setIsFull(queuer2.getIsFull());
29
+ setIsIdle(queuer2.getIsIdle());
30
+ setPeek(() => queuer2.getPeek());
31
+ setSize(queuer2.getSize());
32
+ const onItemsChange = newOptions.onItemsChange ?? initialOptions.onItemsChange;
33
+ onItemsChange == null ? void 0 : onItemsChange(queuer2);
34
+ },
35
+ onIsRunningChange: (queuer2) => {
36
+ setIsRunning(queuer2.getIsRunning());
37
+ setIsIdle(queuer2.getIsIdle());
38
+ const onIsRunningChange = newOptions.onIsRunningChange ?? initialOptions.onIsRunningChange;
39
+ onIsRunningChange == null ? void 0 : onIsRunningChange(queuer2);
40
+ },
41
+ onReject: (item, queuer2) => {
42
+ setRejectionCount(queuer2.getRejectionCount());
43
+ const onReject = newOptions.onReject ?? initialOptions.onReject;
44
+ onReject == null ? void 0 : onReject(item, queuer2);
45
+ }
46
+ });
47
+ }
48
+ setOptions(initialOptions);
49
+ return {
50
+ ...bindInstanceMethods(queuer),
51
+ allItems,
52
+ executionCount,
53
+ isEmpty,
54
+ isFull,
55
+ isIdle,
56
+ isRunning,
57
+ peek,
58
+ rejectionCount,
59
+ size,
60
+ setOptions
61
+ };
62
+ }
63
+ export {
64
+ createQueuer
65
+ };
66
+ //# sourceMappingURL=createQueuer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createQueuer.js","sources":["../../../src/queuer/createQueuer.ts"],"sourcesContent":["import { Queuer } from '@tanstack/pacer/queuer'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { QueuerOptions } from '@tanstack/pacer/queuer'\n\nexport interface SolidQueuer<TValue>\n extends Omit<\n Queuer<TValue>,\n | 'getAllItems'\n | 'getExecutionCount'\n | 'getIsEmpty'\n | 'getIsFull'\n | 'getIsIdle'\n | 'getIsRunning'\n | 'getPeek'\n | 'getSize'\n > {\n /**\n * Signal version of `getAllItems`\n */\n allItems: Accessor<Array<TValue>>\n /**\n * Signal version of `getExecutionCount`\n */\n executionCount: Accessor<number>\n /**\n * Signal version of `getIsEmpty`\n */\n isEmpty: Accessor<boolean>\n /**\n * Signal version of `getIsFull`\n */\n isFull: Accessor<boolean>\n /**\n * Signal version of `getIsIdle`\n */\n isIdle: Accessor<boolean>\n /**\n * Signal version of `getIsRunning`\n */\n isRunning: Accessor<boolean>\n /**\n * Signal version of `getPeek`\n */\n peek: Accessor<TValue | undefined>\n /**\n * Signal version of `getSize`\n */\n size: Accessor<number>\n}\n\n/**\n * A Solid hook that creates and manages a Queuer instance.\n *\n * This is a lower-level hook that provides direct access to the Queuer's functionality without\n * any built-in state management. This allows you to integrate it with any state management solution\n * you prefer (createSignal, Redux, Zustand, etc.) by utilizing the onItemsChange callback.\n *\n * For a hook with built-in state management, see createQueuerSignal.\n *\n * The Queuer extends the base Queue to add processing capabilities. Items are processed\n * synchronously in order, with optional delays between processing each item. The queuer includes\n * an internal tick mechanism that can be started and stopped, making it useful as a scheduler.\n * When started, it will process one item per tick, with an optional wait time between ticks.\n *\n * By default uses FIFO (First In First Out) behavior, but can be configured for LIFO\n * (Last In First Out) by specifying 'front' position when adding items.\n *\n * @example\n * ```tsx\n * // Example with custom state management and scheduling\n * const [items, setItems] = createSignal([]);\n *\n * const queue = createQueuer({\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * onItemsChange: (queue) => setItems(queue.getAllItems()),\n * getPriority: (item) => item.priority // Process higher priority items first\n * });\n *\n * // Add items to process - they'll be handled automatically\n * queue.addItem('task1');\n * queue.addItem('task2');\n *\n * // Control the scheduler\n * queue.stop(); // Pause processing\n * queue.start(); // Resume processing\n *\n * // Access queue state via signals\n * console.log('Items:', queue.allItems());\n * console.log('Size:', queue.size());\n * console.log('Is empty:', queue.isEmpty());\n * console.log('Is running:', queue.isRunning());\n * console.log('Next item:', queue.peek());\n * ```\n */\nexport function createQueuer<TValue>(\n initialOptions: QueuerOptions<TValue> = {},\n): SolidQueuer<TValue> {\n const queuer = new Queuer<TValue>(initialOptions)\n\n const [allItems, setAllItems] = createSignal<Array<TValue>>(\n queuer.getAllItems(),\n )\n const [executionCount, setExecutionCount] = createSignal(\n queuer.getExecutionCount(),\n )\n const [rejectionCount, setRejectionCount] = createSignal(\n queuer.getRejectionCount(),\n )\n const [isEmpty, setIsEmpty] = createSignal(queuer.getIsEmpty())\n const [isFull, setIsFull] = createSignal(queuer.getIsFull())\n const [isIdle, setIsIdle] = createSignal(queuer.getIsIdle())\n const [isRunning, setIsRunning] = createSignal(queuer.getIsRunning())\n const [peek, setPeek] = createSignal<TValue | undefined>(queuer.getPeek())\n const [size, setSize] = createSignal(queuer.getSize())\n\n function setOptions(newOptions: Partial<QueuerOptions<TValue>>) {\n queuer.setOptions({\n ...newOptions,\n onItemsChange: (queuer) => {\n setAllItems(queuer.getAllItems())\n setExecutionCount(queuer.getExecutionCount())\n setIsEmpty(queuer.getIsEmpty())\n setIsFull(queuer.getIsFull())\n setIsIdle(queuer.getIsIdle())\n setPeek(() => queuer.getPeek())\n setSize(queuer.getSize())\n\n const onItemsChange =\n newOptions.onItemsChange ?? initialOptions.onItemsChange\n onItemsChange?.(queuer)\n },\n onIsRunningChange: (queuer) => {\n setIsRunning(queuer.getIsRunning())\n setIsIdle(queuer.getIsIdle())\n\n const onIsRunningChange =\n newOptions.onIsRunningChange ?? initialOptions.onIsRunningChange\n onIsRunningChange?.(queuer)\n },\n onReject: (item, queuer) => {\n setRejectionCount(queuer.getRejectionCount())\n\n const onReject = newOptions.onReject ?? initialOptions.onReject\n onReject?.(item, queuer)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...bindInstanceMethods(queuer),\n allItems,\n executionCount,\n isEmpty,\n isFull,\n isIdle,\n isRunning,\n peek,\n rejectionCount,\n size,\n setOptions,\n }\n}\n"],"names":["queuer"],"mappings":";;;AAiGgB,SAAA,aACd,iBAAwC,IACnB;AACf,QAAA,SAAS,IAAI,OAAe,cAAc;AAE1C,QAAA,CAAC,UAAU,WAAW,IAAI;AAAA,IAC9B,OAAO,YAAY;AAAA,EACrB;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,OAAO,kBAAkB;AAAA,EAC3B;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,OAAO,kBAAkB;AAAA,EAC3B;AACA,QAAM,CAAC,SAAS,UAAU,IAAI,aAAa,OAAO,YAAY;AAC9D,QAAM,CAAC,QAAQ,SAAS,IAAI,aAAa,OAAO,WAAW;AAC3D,QAAM,CAAC,QAAQ,SAAS,IAAI,aAAa,OAAO,WAAW;AAC3D,QAAM,CAAC,WAAW,YAAY,IAAI,aAAa,OAAO,cAAc;AACpE,QAAM,CAAC,MAAM,OAAO,IAAI,aAAiC,OAAO,SAAS;AACzE,QAAM,CAAC,MAAM,OAAO,IAAI,aAAa,OAAO,SAAS;AAErD,WAAS,WAAW,YAA4C;AAC9D,WAAO,WAAW;AAAA,MAChB,GAAG;AAAA,MACH,eAAe,CAACA,YAAW;AACbA,oBAAAA,QAAO,aAAa;AACdA,0BAAAA,QAAO,mBAAmB;AACjCA,mBAAAA,QAAO,YAAY;AACpBA,kBAAAA,QAAO,WAAW;AAClBA,kBAAAA,QAAO,WAAW;AACpB,gBAAA,MAAMA,QAAO,SAAS;AACtBA,gBAAAA,QAAO,SAAS;AAElB,cAAA,gBACJ,WAAW,iBAAiB,eAAe;AAC7C,uDAAgBA;AAAAA,MAClB;AAAA,MACA,mBAAmB,CAACA,YAAW;AAChBA,qBAAAA,QAAO,cAAc;AACxBA,kBAAAA,QAAO,WAAW;AAEtB,cAAA,oBACJ,WAAW,qBAAqB,eAAe;AACjD,+DAAoBA;AAAAA,MACtB;AAAA,MACA,UAAU,CAAC,MAAMA,YAAW;AACRA,0BAAAA,QAAO,mBAAmB;AAEtC,cAAA,WAAW,WAAW,YAAY,eAAe;AACvD,6CAAW,MAAMA;AAAAA,MAAM;AAAA,IACzB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAG,oBAAoB,MAAM;AAAA,IAC7B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
@@ -0,0 +1,2 @@
1
+ export * from '@tanstack/pacer/queuer';
2
+ export * from './createQueuer.js';
@@ -0,0 +1,6 @@
1
+ export * from "@tanstack/pacer/queuer";
2
+ import { createQueuer } from "./createQueuer.js";
3
+ export {
4
+ createQueuer
5
+ };
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,58 @@
1
+ import { SolidRateLimiter } from './createRateLimiter.js';
2
+ import { Accessor, Setter } from 'solid-js';
3
+ import { RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
4
+ /**
5
+ * A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.
6
+ * This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.
7
+ *
8
+ * Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks
9
+ * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out
10
+ * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.
11
+ *
12
+ * For smoother update patterns, consider:
13
+ * - createThrottledSignal: When you want consistent spacing between updates (e.g. UI changes)
14
+ * - createDebouncedSignal: When you want to collapse rapid updates into a single update (e.g. search input)
15
+ *
16
+ * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.
17
+ *
18
+ * The hook returns a tuple containing:
19
+ * - The rate-limited state value accessor
20
+ * - A rate-limited setter function that respects the configured limits
21
+ * - The rateLimiter instance for additional control
22
+ *
23
+ * For more direct control over rate limiting without state management,
24
+ * consider using the lower-level createRateLimiter hook instead.
25
+ *
26
+ * @example
27
+ * ```tsx
28
+ * // Basic rate limiting - update state at most 5 times per minute
29
+ * const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {
30
+ * limit: 5,
31
+ * window: 60000
32
+ * });
33
+ *
34
+ * // With rejection callback
35
+ * const [value, setValue] = createRateLimitedSignal(0, {
36
+ * limit: 3,
37
+ * window: 5000,
38
+ * onReject: (rateLimiter) => {
39
+ * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
40
+ * }
41
+ * });
42
+ *
43
+ * // Access rateLimiter state via signals
44
+ * const handleSubmit = () => {
45
+ * const remaining = rateLimiter.remainingInWindow();
46
+ * if (remaining > 0) {
47
+ * setValue(newValue);
48
+ * } else {
49
+ * showRateLimitWarning();
50
+ * }
51
+ * };
52
+ * ```
53
+ */
54
+ export declare function createRateLimitedSignal<TValue>(value: TValue, initialOptions: RateLimiterOptions<Setter<TValue>, [Accessor<TValue>]>): [
55
+ Accessor<TValue>,
56
+ Setter<TValue>,
57
+ SolidRateLimiter<Setter<TValue>, [Accessor<TValue>]>
58
+ ];
@@ -0,0 +1,15 @@
1
+ import { createSignal } from "solid-js";
2
+ import { createRateLimiter } from "./createRateLimiter.js";
3
+ function createRateLimitedSignal(value, initialOptions) {
4
+ const [rateLimitedValue, setRateLimitedValue] = createSignal(value);
5
+ const rateLimiter = createRateLimiter(setRateLimitedValue, initialOptions);
6
+ return [
7
+ rateLimitedValue,
8
+ rateLimiter.maybeExecute.bind(rateLimiter),
9
+ rateLimiter
10
+ ];
11
+ }
12
+ export {
13
+ createRateLimitedSignal
14
+ };
15
+ //# sourceMappingURL=createRateLimitedSignal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createRateLimitedSignal.js","sources":["../../../src/rate-limiter/createRateLimitedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createRateLimiter } from './createRateLimiter'\nimport type { SolidRateLimiter } from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.\n * This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * For smoother update patterns, consider:\n * - createThrottledSignal: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedSignal: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns a tuple containing:\n * - The rate-limited state value accessor\n * - A rate-limited setter function that respects the configured limits\n * - The rateLimiter instance for additional control\n *\n * For more direct control over rate limiting without state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * @example\n * ```tsx\n * // Basic rate limiting - update state at most 5 times per minute\n * const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {\n * limit: 5,\n * window: 60000\n * });\n *\n * // With rejection callback\n * const [value, setValue] = createRateLimitedSignal(0, {\n * limit: 3,\n * window: 5000,\n * onReject: (rateLimiter) => {\n * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access rateLimiter state via signals\n * const handleSubmit = () => {\n * const remaining = rateLimiter.remainingInWindow();\n * if (remaining > 0) {\n * setValue(newValue);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n * ```\n */\nexport function createRateLimitedSignal<TValue>(\n value: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>, [Accessor<TValue>]>,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidRateLimiter<Setter<TValue>, [Accessor<TValue>]>,\n] {\n const [rateLimitedValue, setRateLimitedValue] = createSignal<TValue>(value)\n\n const rateLimiter = createRateLimiter(setRateLimitedValue, initialOptions)\n\n return [\n rateLimitedValue,\n rateLimiter.maybeExecute.bind(rateLimiter) as Setter<TValue>,\n rateLimiter,\n ]\n}\n"],"names":[],"mappings":";;AAwDgB,SAAA,wBACd,OACA,gBAKA;AACA,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,aAAqB,KAAK;AAEpE,QAAA,cAAc,kBAAkB,qBAAqB,cAAc;AAElE,SAAA;AAAA,IACL;AAAA,IACA,YAAY,aAAa,KAAK,WAAW;AAAA,IACzC;AAAA,EACF;AACF;"}
@@ -0,0 +1,51 @@
1
+ import { SolidRateLimiter } from './createRateLimiter.js';
2
+ import { Accessor, Setter } from 'solid-js';
3
+ import { RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
4
+ /**
5
+ * A high-level Solid hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window.
6
+ * This hook uses Solid's createSignal internally to manage the rate-limited state.
7
+ *
8
+ * Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks
9
+ * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out
10
+ * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.
11
+ *
12
+ * For smoother update patterns, consider:
13
+ * - createThrottledValue: When you want consistent spacing between updates (e.g. UI changes)
14
+ * - createDebouncedValue: When you want to collapse rapid updates into a single update (e.g. search input)
15
+ *
16
+ * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.
17
+ *
18
+ * The hook returns both the rate-limited value and the underlying rateLimiter instance for additional control.
19
+ *
20
+ * For more direct control over rate limiting behavior without Solid state management,
21
+ * consider using the lower-level createRateLimiter hook instead.
22
+ *
23
+ * @example
24
+ * ```tsx
25
+ * // Basic rate limiting - update at most 5 times per minute
26
+ * const [rateLimitedValue] = createRateLimitedValue(rawValue, {
27
+ * limit: 5,
28
+ * window: 60000
29
+ * });
30
+ *
31
+ * // With rejection callback
32
+ * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
33
+ * limit: 3,
34
+ * window: 5000,
35
+ * onReject: (rateLimiter) => {
36
+ * console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
37
+ * }
38
+ * });
39
+ *
40
+ * // Optionally access rateLimiter state via signals
41
+ * const handleSubmit = () => {
42
+ * const remaining = rateLimiter.remainingInWindow();
43
+ * if (remaining > 0) {
44
+ * console.log(`${remaining} updates remaining in this window`);
45
+ * } else {
46
+ * console.log('Rate limit reached for this window');
47
+ * }
48
+ * };
49
+ * ```
50
+ */
51
+ export declare function createRateLimitedValue<TValue>(value: Accessor<TValue>, initialOptions: RateLimiterOptions<Setter<TValue>, [Accessor<TValue>]>): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, [Accessor<TValue>]>];
@@ -0,0 +1,13 @@
1
+ import { createEffect } from "solid-js";
2
+ import { createRateLimitedSignal } from "./createRateLimitedSignal.js";
3
+ function createRateLimitedValue(value, initialOptions) {
4
+ const [rateLimitedValue, setRateLimitedValue, rateLimiter] = createRateLimitedSignal(value(), initialOptions);
5
+ createEffect(() => {
6
+ setRateLimitedValue(value());
7
+ });
8
+ return [rateLimitedValue, rateLimiter];
9
+ }
10
+ export {
11
+ createRateLimitedValue
12
+ };
13
+ //# sourceMappingURL=createRateLimitedValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createRateLimitedValue.js","sources":["../../../src/rate-limiter/createRateLimitedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createRateLimitedSignal } from './createRateLimitedSignal'\nimport type { SolidRateLimiter } from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A high-level Solid hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window.\n * This hook uses Solid's createSignal internally to manage the rate-limited state.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * For smoother update patterns, consider:\n * - createThrottledValue: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedValue: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns both the rate-limited value and the underlying rateLimiter instance for additional control.\n *\n * For more direct control over rate limiting behavior without Solid state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * @example\n * ```tsx\n * // Basic rate limiting - update at most 5 times per minute\n * const [rateLimitedValue] = createRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000\n * });\n *\n * // With rejection callback\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 3,\n * window: 5000,\n * onReject: (rateLimiter) => {\n * console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Optionally access rateLimiter state via signals\n * const handleSubmit = () => {\n * const remaining = rateLimiter.remainingInWindow();\n * if (remaining > 0) {\n * console.log(`${remaining} updates remaining in this window`);\n * } else {\n * console.log('Rate limit reached for this window');\n * }\n * };\n * ```\n */\nexport function createRateLimitedValue<TValue>(\n value: Accessor<TValue>,\n initialOptions: RateLimiterOptions<Setter<TValue>, [Accessor<TValue>]>,\n): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, [Accessor<TValue>]>] {\n const [rateLimitedValue, setRateLimitedValue, rateLimiter] =\n createRateLimitedSignal(value(), initialOptions)\n\n createEffect(() => {\n setRateLimitedValue(value() as any)\n })\n\n return [rateLimitedValue, rateLimiter]\n}\n"],"names":[],"mappings":";;AAqDgB,SAAA,uBACd,OACA,gBAC0E;AACpE,QAAA,CAAC,kBAAkB,qBAAqB,WAAW,IACvD,wBAAwB,SAAS,cAAc;AAEjD,eAAa,MAAM;AACjB,wBAAoB,OAAc;AAAA,EAAA,CACnC;AAEM,SAAA,CAAC,kBAAkB,WAAW;AACvC;"}
@@ -0,0 +1,49 @@
1
+ import { RateLimiter, RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
2
+ import { Accessor } from 'solid-js';
3
+ import { AnyFunction } from '@tanstack/pacer/types';
4
+ export interface SolidRateLimiter<TFn extends AnyFunction, TArgs extends Parameters<TFn>> extends Omit<RateLimiter<TFn, TArgs>, 'getExecutionCount' | 'getMsUntilNextWindow' | 'getRejectionCount' | 'getRemainingInWindow'> {
5
+ executionCount: Accessor<number>;
6
+ msUntilNextWindow: Accessor<number>;
7
+ rejectionCount: Accessor<number>;
8
+ remainingInWindow: Accessor<number>;
9
+ }
10
+ /**
11
+ * A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.
12
+ *
13
+ * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that
14
+ * you can integrate with any state management solution (createSignal, etc).
15
+ *
16
+ * Rate limiting is a simple "hard limit" approach that allows executions until a maximum count is reached within
17
+ * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,
18
+ * it does not attempt to space out or collapse executions intelligently.
19
+ *
20
+ * For smoother execution patterns:
21
+ * - Use throttling when you want consistent spacing between executions (e.g. UI updates)
22
+ * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)
23
+ * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)
24
+ *
25
+ * @example
26
+ * ```tsx
27
+ * // Basic rate limiting - max 5 calls per minute
28
+ * const rateLimiter = createRateLimiter(apiCall, {
29
+ * limit: 5,
30
+ * window: 60000,
31
+ * });
32
+ *
33
+ * // Monitor rate limit status
34
+ * const handleClick = () => {
35
+ * if (rateLimiter.remainingInWindow() > 0) {
36
+ * rateLimiter.maybeExecute(data);
37
+ * } else {
38
+ * showRateLimitWarning();
39
+ * }
40
+ * };
41
+ *
42
+ * // Access rate limiter state via signals
43
+ * console.log('Executions:', rateLimiter.executionCount());
44
+ * console.log('Rejections:', rateLimiter.rejectionCount());
45
+ * console.log('Remaining:', rateLimiter.remainingInWindow());
46
+ * console.log('Next window in:', rateLimiter.msUntilNextWindow());
47
+ * ```
48
+ */
49
+ export declare function createRateLimiter<TFn extends AnyFunction, TArgs extends Parameters<TFn>>(fn: TFn, initialOptions: RateLimiterOptions<TFn, TArgs>): SolidRateLimiter<TFn, TArgs>;
@@ -0,0 +1,50 @@
1
+ import { RateLimiter } from "@tanstack/pacer/rate-limiter";
2
+ import { createSignal } from "solid-js";
3
+ import { bindInstanceMethods } from "@tanstack/pacer/utils";
4
+ function createRateLimiter(fn, initialOptions) {
5
+ const rateLimiter = new RateLimiter(fn, initialOptions);
6
+ const [executionCount, setExecutionCount] = createSignal(
7
+ rateLimiter.getExecutionCount()
8
+ );
9
+ const [rejectionCount, setRejectionCount] = createSignal(
10
+ rateLimiter.getRejectionCount()
11
+ );
12
+ const [remainingInWindow, setRemainingInWindow] = createSignal(
13
+ rateLimiter.getRemainingInWindow()
14
+ );
15
+ const [msUntilNextWindow, setMsUntilNextWindow] = createSignal(
16
+ rateLimiter.getMsUntilNextWindow()
17
+ );
18
+ function setOptions(newOptions) {
19
+ rateLimiter.setOptions({
20
+ ...newOptions,
21
+ onExecute: (rateLimiter2) => {
22
+ setExecutionCount(rateLimiter2.getExecutionCount());
23
+ setRemainingInWindow(rateLimiter2.getRemainingInWindow());
24
+ setMsUntilNextWindow(rateLimiter2.getMsUntilNextWindow());
25
+ const onExecute = newOptions.onExecute ?? initialOptions.onExecute;
26
+ onExecute == null ? void 0 : onExecute(rateLimiter2);
27
+ },
28
+ onReject: (rateLimiter2) => {
29
+ setRejectionCount(rateLimiter2.getRejectionCount());
30
+ setRemainingInWindow(rateLimiter2.getRemainingInWindow());
31
+ setMsUntilNextWindow(rateLimiter2.getMsUntilNextWindow());
32
+ const onReject = newOptions.onReject ?? initialOptions.onReject;
33
+ onReject == null ? void 0 : onReject(rateLimiter2);
34
+ }
35
+ });
36
+ }
37
+ setOptions(initialOptions);
38
+ return {
39
+ ...bindInstanceMethods(rateLimiter),
40
+ executionCount,
41
+ rejectionCount,
42
+ remainingInWindow,
43
+ msUntilNextWindow,
44
+ setOptions
45
+ };
46
+ }
47
+ export {
48
+ createRateLimiter
49
+ };
50
+ //# sourceMappingURL=createRateLimiter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createRateLimiter.js","sources":["../../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\n\nexport interface SolidRateLimiter<\n TFn extends AnyFunction,\n TArgs extends Parameters<TFn>,\n> extends Omit<\n RateLimiter<TFn, TArgs>,\n | 'getExecutionCount'\n | 'getMsUntilNextWindow'\n | 'getRejectionCount'\n | 'getRemainingInWindow'\n > {\n executionCount: Accessor<number>\n msUntilNextWindow: Accessor<number>\n rejectionCount: Accessor<number>\n remainingInWindow: Accessor<number>\n}\n\n/**\n * A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Rate limiting is a simple \"hard limit\" approach that allows executions until a maximum count is reached within\n * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,\n * it does not attempt to space out or collapse executions intelligently.\n *\n * For smoother execution patterns:\n * - Use throttling when you want consistent spacing between executions (e.g. UI updates)\n * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)\n * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)\n *\n * @example\n * ```tsx\n * // Basic rate limiting - max 5 calls per minute\n * const rateLimiter = createRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * });\n *\n * // Monitor rate limit status\n * const handleClick = () => {\n * if (rateLimiter.remainingInWindow() > 0) {\n * rateLimiter.maybeExecute(data);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n *\n * // Access rate limiter state via signals\n * console.log('Executions:', rateLimiter.executionCount());\n * console.log('Rejections:', rateLimiter.rejectionCount());\n * console.log('Remaining:', rateLimiter.remainingInWindow());\n * console.log('Next window in:', rateLimiter.msUntilNextWindow());\n * ```\n */\nexport function createRateLimiter<\n TFn extends AnyFunction,\n TArgs extends Parameters<TFn>,\n>(\n fn: TFn,\n initialOptions: RateLimiterOptions<TFn, TArgs>,\n): SolidRateLimiter<TFn, TArgs> {\n const rateLimiter = new RateLimiter<TFn, TArgs>(fn, initialOptions)\n\n const [executionCount, setExecutionCount] = createSignal(\n rateLimiter.getExecutionCount(),\n )\n const [rejectionCount, setRejectionCount] = createSignal(\n rateLimiter.getRejectionCount(),\n )\n const [remainingInWindow, setRemainingInWindow] = createSignal(\n rateLimiter.getRemainingInWindow(),\n )\n const [msUntilNextWindow, setMsUntilNextWindow] = createSignal(\n rateLimiter.getMsUntilNextWindow(),\n )\n\n function setOptions(newOptions: Partial<RateLimiterOptions<TFn, TArgs>>) {\n rateLimiter.setOptions({\n ...newOptions,\n onExecute: (rateLimiter) => {\n setExecutionCount(rateLimiter.getExecutionCount())\n setRemainingInWindow(rateLimiter.getRemainingInWindow())\n setMsUntilNextWindow(rateLimiter.getMsUntilNextWindow())\n const onExecute = newOptions.onExecute ?? initialOptions.onExecute\n onExecute?.(rateLimiter)\n },\n onReject: (rateLimiter) => {\n setRejectionCount(rateLimiter.getRejectionCount())\n setRemainingInWindow(rateLimiter.getRemainingInWindow())\n setMsUntilNextWindow(rateLimiter.getMsUntilNextWindow())\n const onReject = newOptions.onReject ?? initialOptions.onReject\n onReject?.(rateLimiter)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...bindInstanceMethods(rateLimiter),\n executionCount,\n rejectionCount,\n remainingInWindow,\n msUntilNextWindow,\n setOptions,\n }\n}\n"],"names":["rateLimiter"],"mappings":";;;AA8DgB,SAAA,kBAId,IACA,gBAC8B;AAC9B,QAAM,cAAc,IAAI,YAAwB,IAAI,cAAc;AAE5D,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,YAAY,kBAAkB;AAAA,EAChC;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,YAAY,kBAAkB;AAAA,EAChC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAI;AAAA,IAChD,YAAY,qBAAqB;AAAA,EACnC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAI;AAAA,IAChD,YAAY,qBAAqB;AAAA,EACnC;AAEA,WAAS,WAAW,YAAqD;AACvE,gBAAY,WAAW;AAAA,MACrB,GAAG;AAAA,MACH,WAAW,CAACA,iBAAgB;AACRA,0BAAAA,aAAY,mBAAmB;AAC5BA,6BAAAA,aAAY,sBAAsB;AAClCA,6BAAAA,aAAY,sBAAsB;AACjD,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MACd;AAAA,MACA,UAAU,CAACA,iBAAgB;AACPA,0BAAAA,aAAY,mBAAmB;AAC5BA,6BAAAA,aAAY,sBAAsB;AAClCA,6BAAAA,aAAY,sBAAsB;AACjD,cAAA,WAAW,WAAW,YAAY,eAAe;AACvD,6CAAWA;AAAAA,MAAW;AAAA,IACxB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAG,oBAAoB,WAAW;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
@@ -0,0 +1,4 @@
1
+ export * from '@tanstack/pacer/rate-limiter';
2
+ export * from './createRateLimiter.js';
3
+ export * from './createRateLimitedSignal.js';
4
+ export * from './createRateLimitedValue.js';
@@ -0,0 +1,10 @@
1
+ export * from "@tanstack/pacer/rate-limiter";
2
+ import { createRateLimiter } from "./createRateLimiter.js";
3
+ import { createRateLimitedSignal } from "./createRateLimitedSignal.js";
4
+ import { createRateLimitedValue } from "./createRateLimitedValue.js";
5
+ export {
6
+ createRateLimitedSignal,
7
+ createRateLimitedValue,
8
+ createRateLimiter
9
+ };
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -0,0 +1,42 @@
1
+ import { SolidThrottler } from './createThrottler.js';
2
+ import { Accessor, Setter } from 'solid-js';
3
+ import { ThrottlerOptions } from '@tanstack/pacer/throttler';
4
+ /**
5
+ * A Solid hook that creates a throttled state value that updates at most once within a specified time window.
6
+ * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.
7
+ *
8
+ * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.
9
+ * This is useful for rate-limiting expensive re-renders or operations that depend on rapidly changing state.
10
+ *
11
+ * The hook returns a tuple containing:
12
+ * - The throttled state value accessor
13
+ * - A throttled setter function that respects the configured wait time
14
+ * - The throttler instance for additional control
15
+ *
16
+ * For more direct control over throttling without state management,
17
+ * consider using the lower-level createThrottler hook instead.
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * // Basic throttling - update state at most once per second
22
+ * const [value, setValue, throttler] = createThrottledSignal(0, { wait: 1000 });
23
+ *
24
+ * // With custom leading/trailing behavior
25
+ * const [value, setValue] = createThrottledSignal(0, {
26
+ * wait: 1000,
27
+ * leading: true, // Update immediately on first change
28
+ * trailing: false // Skip trailing edge updates
29
+ * });
30
+ *
31
+ * // Access throttler state via signals
32
+ * console.log('Executions:', throttler.executionCount());
33
+ * console.log('Is pending:', throttler.isPending());
34
+ * console.log('Last execution:', throttler.lastExecutionTime());
35
+ * console.log('Next execution:', throttler.nextExecutionTime());
36
+ * ```
37
+ */
38
+ export declare function createThrottledSignal<TValue>(value: TValue, initialOptions: ThrottlerOptions<Setter<TValue>, [Accessor<TValue>]>): [
39
+ Accessor<TValue>,
40
+ Setter<TValue>,
41
+ SolidThrottler<Setter<TValue>, [Accessor<TValue>]>
42
+ ];