@tanstack/solid-pacer 0.8.0 → 0.9.1

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 (132) hide show
  1. package/dist/cjs/async-batcher/createAsyncBatcher.cjs +14 -0
  2. package/dist/cjs/async-batcher/createAsyncBatcher.cjs.map +1 -0
  3. package/dist/cjs/async-batcher/createAsyncBatcher.d.cts +72 -0
  4. package/dist/cjs/async-batcher/index.cjs +12 -0
  5. package/dist/cjs/{compare → async-batcher}/index.cjs.map +1 -1
  6. package/dist/cjs/async-batcher/index.d.cts +2 -0
  7. package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs +9 -36
  8. package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs.map +1 -1
  9. package/dist/cjs/async-debouncer/createAsyncDebouncer.d.cts +10 -9
  10. package/dist/cjs/async-queuer/createAsyncQueuer.cjs +5 -73
  11. package/dist/cjs/async-queuer/createAsyncQueuer.cjs.map +1 -1
  12. package/dist/cjs/async-queuer/createAsyncQueuer.d.cts +7 -53
  13. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs +5 -52
  14. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs.map +1 -1
  15. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.d.cts +4 -9
  16. package/dist/cjs/async-throttler/createAsyncThrottler.cjs +5 -55
  17. package/dist/cjs/async-throttler/createAsyncThrottler.cjs.map +1 -1
  18. package/dist/cjs/async-throttler/createAsyncThrottler.d.cts +9 -11
  19. package/dist/cjs/batcher/createBatcher.cjs +5 -49
  20. package/dist/cjs/batcher/createBatcher.cjs.map +1 -1
  21. package/dist/cjs/batcher/createBatcher.d.cts +9 -27
  22. package/dist/cjs/debouncer/createDebouncedSignal.cjs +2 -2
  23. package/dist/cjs/debouncer/createDebouncedSignal.cjs.map +1 -1
  24. package/dist/cjs/debouncer/createDebouncedSignal.d.cts +6 -2
  25. package/dist/cjs/debouncer/createDebouncedValue.cjs +3 -2
  26. package/dist/cjs/debouncer/createDebouncedValue.cjs.map +1 -1
  27. package/dist/cjs/debouncer/createDebouncedValue.d.cts +2 -2
  28. package/dist/cjs/debouncer/createDebouncer.cjs +7 -24
  29. package/dist/cjs/debouncer/createDebouncer.cjs.map +1 -1
  30. package/dist/cjs/debouncer/createDebouncer.d.cts +9 -8
  31. package/dist/cjs/index.cjs +2 -0
  32. package/dist/cjs/index.cjs.map +1 -1
  33. package/dist/cjs/index.d.cts +1 -0
  34. package/dist/cjs/queuer/createQueuer.cjs +5 -59
  35. package/dist/cjs/queuer/createQueuer.cjs.map +1 -1
  36. package/dist/cjs/queuer/createQueuer.d.cts +7 -37
  37. package/dist/cjs/rate-limiter/createRateLimitedSignal.cjs +7 -3
  38. package/dist/cjs/rate-limiter/createRateLimitedSignal.cjs.map +1 -1
  39. package/dist/cjs/rate-limiter/createRateLimitedSignal.d.cts +6 -2
  40. package/dist/cjs/rate-limiter/createRateLimitedValue.cjs +2 -2
  41. package/dist/cjs/rate-limiter/createRateLimitedValue.cjs.map +1 -1
  42. package/dist/cjs/rate-limiter/createRateLimitedValue.d.cts +2 -2
  43. package/dist/cjs/rate-limiter/createRateLimiter.cjs +5 -43
  44. package/dist/cjs/rate-limiter/createRateLimiter.cjs.map +1 -1
  45. package/dist/cjs/rate-limiter/createRateLimiter.d.cts +9 -7
  46. package/dist/cjs/throttler/createThrottledSignal.cjs +2 -2
  47. package/dist/cjs/throttler/createThrottledSignal.cjs.map +1 -1
  48. package/dist/cjs/throttler/createThrottledSignal.d.cts +6 -2
  49. package/dist/cjs/throttler/createThrottledValue.cjs +3 -2
  50. package/dist/cjs/throttler/createThrottledValue.cjs.map +1 -1
  51. package/dist/cjs/throttler/createThrottledValue.d.cts +2 -2
  52. package/dist/cjs/throttler/createThrottler.cjs +7 -34
  53. package/dist/cjs/throttler/createThrottler.cjs.map +1 -1
  54. package/dist/cjs/throttler/createThrottler.d.cts +9 -10
  55. package/dist/esm/async-batcher/createAsyncBatcher.d.ts +72 -0
  56. package/dist/esm/async-batcher/createAsyncBatcher.js +14 -0
  57. package/dist/esm/async-batcher/createAsyncBatcher.js.map +1 -0
  58. package/dist/esm/async-batcher/index.d.ts +2 -0
  59. package/dist/esm/async-batcher/index.js +6 -0
  60. package/dist/esm/{compare → async-batcher}/index.js.map +1 -1
  61. package/dist/esm/async-debouncer/createAsyncDebouncer.d.ts +10 -9
  62. package/dist/esm/async-debouncer/createAsyncDebouncer.js +10 -37
  63. package/dist/esm/async-debouncer/createAsyncDebouncer.js.map +1 -1
  64. package/dist/esm/async-queuer/createAsyncQueuer.d.ts +7 -53
  65. package/dist/esm/async-queuer/createAsyncQueuer.js +5 -73
  66. package/dist/esm/async-queuer/createAsyncQueuer.js.map +1 -1
  67. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.d.ts +4 -9
  68. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js +5 -52
  69. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js.map +1 -1
  70. package/dist/esm/async-throttler/createAsyncThrottler.d.ts +9 -11
  71. package/dist/esm/async-throttler/createAsyncThrottler.js +5 -55
  72. package/dist/esm/async-throttler/createAsyncThrottler.js.map +1 -1
  73. package/dist/esm/batcher/createBatcher.d.ts +9 -27
  74. package/dist/esm/batcher/createBatcher.js +5 -49
  75. package/dist/esm/batcher/createBatcher.js.map +1 -1
  76. package/dist/esm/debouncer/createDebouncedSignal.d.ts +6 -2
  77. package/dist/esm/debouncer/createDebouncedSignal.js +2 -2
  78. package/dist/esm/debouncer/createDebouncedSignal.js.map +1 -1
  79. package/dist/esm/debouncer/createDebouncedValue.d.ts +2 -2
  80. package/dist/esm/debouncer/createDebouncedValue.js +3 -2
  81. package/dist/esm/debouncer/createDebouncedValue.js.map +1 -1
  82. package/dist/esm/debouncer/createDebouncer.d.ts +9 -8
  83. package/dist/esm/debouncer/createDebouncer.js +8 -25
  84. package/dist/esm/debouncer/createDebouncer.js.map +1 -1
  85. package/dist/esm/index.d.ts +1 -0
  86. package/dist/esm/index.js +2 -0
  87. package/dist/esm/index.js.map +1 -1
  88. package/dist/esm/queuer/createQueuer.d.ts +7 -37
  89. package/dist/esm/queuer/createQueuer.js +5 -59
  90. package/dist/esm/queuer/createQueuer.js.map +1 -1
  91. package/dist/esm/rate-limiter/createRateLimitedSignal.d.ts +6 -2
  92. package/dist/esm/rate-limiter/createRateLimitedSignal.js +7 -3
  93. package/dist/esm/rate-limiter/createRateLimitedSignal.js.map +1 -1
  94. package/dist/esm/rate-limiter/createRateLimitedValue.d.ts +2 -2
  95. package/dist/esm/rate-limiter/createRateLimitedValue.js +2 -2
  96. package/dist/esm/rate-limiter/createRateLimitedValue.js.map +1 -1
  97. package/dist/esm/rate-limiter/createRateLimiter.d.ts +9 -7
  98. package/dist/esm/rate-limiter/createRateLimiter.js +5 -43
  99. package/dist/esm/rate-limiter/createRateLimiter.js.map +1 -1
  100. package/dist/esm/throttler/createThrottledSignal.d.ts +6 -2
  101. package/dist/esm/throttler/createThrottledSignal.js +2 -2
  102. package/dist/esm/throttler/createThrottledSignal.js.map +1 -1
  103. package/dist/esm/throttler/createThrottledValue.d.ts +2 -2
  104. package/dist/esm/throttler/createThrottledValue.js +3 -2
  105. package/dist/esm/throttler/createThrottledValue.js.map +1 -1
  106. package/dist/esm/throttler/createThrottler.d.ts +9 -10
  107. package/dist/esm/throttler/createThrottler.js +8 -35
  108. package/dist/esm/throttler/createThrottler.js.map +1 -1
  109. package/package.json +14 -3
  110. package/src/async-batcher/createAsyncBatcher.ts +98 -0
  111. package/src/async-batcher/index.ts +3 -0
  112. package/src/async-debouncer/createAsyncDebouncer.ts +31 -56
  113. package/src/async-queuer/createAsyncQueuer.ts +18 -141
  114. package/src/async-rate-limiter/createAsyncRateLimiter.ts +20 -75
  115. package/src/async-throttler/createAsyncThrottler.ts +25 -81
  116. package/src/batcher/createBatcher.ts +17 -94
  117. package/src/debouncer/createDebouncedSignal.ts +15 -4
  118. package/src/debouncer/createDebouncedValue.ts +11 -3
  119. package/src/debouncer/createDebouncer.ts +28 -38
  120. package/src/index.ts +3 -0
  121. package/src/queuer/createQueuer.ts +15 -115
  122. package/src/rate-limiter/createRateLimitedSignal.ts +17 -5
  123. package/src/rate-limiter/createRateLimitedValue.ts +8 -4
  124. package/src/rate-limiter/createRateLimiter.ts +25 -62
  125. package/src/throttler/createThrottledSignal.ts +15 -4
  126. package/src/throttler/createThrottledValue.ts +11 -3
  127. package/src/throttler/createThrottler.ts +28 -56
  128. package/dist/cjs/compare/index.cjs +0 -10
  129. package/dist/cjs/compare/index.d.cts +0 -1
  130. package/dist/esm/compare/index.d.ts +0 -1
  131. package/dist/esm/compare/index.js +0 -2
  132. package/src/compare/index.ts +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"createRateLimitedSignal.cjs","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 * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\n *\n * For smoother update patterns, consider:\n * - createThrottledSignal: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedSignal: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns a tuple containing:\n * - The rate-limited state value accessor\n * - A rate-limited setter function that respects the configured limits\n * - The rateLimiter instance for additional control\n *\n * For more direct control over rate limiting without state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * @example\n * ```tsx\n * // Basic rate limiting - update state at most 5 times per minute with a sliding window\n * const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // With rejection callback and fixed window\n * const [value, setValue] = createRateLimitedSignal(0, {\n * limit: 3,\n * window: 5000,\n * windowType: 'fixed',\n * onReject: (rateLimiter) => {\n * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access rateLimiter state via signals\n * const handleSubmit = () => {\n * const remaining = rateLimiter.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>>,\n): [Accessor<TValue>, Setter<TValue>, SolidRateLimiter<Setter<TValue>>] {\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":["createSignal","createRateLimiter"],"mappings":";;;;AAgEgB,SAAA,wBACd,OACA,gBACsE;AACtE,QAAM,CAAC,kBAAkB,mBAAmB,IAAIA,QAAAA,aAAqB,KAAK;AAEpE,QAAA,cAAcC,kBAAAA,kBAAkB,qBAAqB,cAAc;AAElE,SAAA;AAAA,IACL;AAAA,IACA,YAAY,aAAa,KAAK,WAAW;AAAA,IACzC;AAAA,EACF;AACF;;"}
1
+ {"version":3,"file":"createRateLimitedSignal.cjs","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 {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\n/**\n * A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.\n * This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\n *\n * For smoother update patterns, consider:\n * - createThrottledSignal: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedSignal: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns a tuple containing:\n * - The rate-limited state value accessor\n * - A rate-limited setter function that respects the configured limits\n * - The rateLimiter instance for additional control\n *\n * For more direct control over rate limiting without state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * @example\n * ```tsx\n * // Basic rate limiting - update state at most 5 times per minute with a sliding window\n * const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // With rejection callback and fixed window\n * const [value, setValue] = createRateLimitedSignal(0, {\n * limit: 3,\n * window: 5000,\n * windowType: 'fixed',\n * onReject: (rateLimiter) => {\n * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access rateLimiter state via signals\n * const handleSubmit = () => {\n * const remaining = rateLimiter.remainingInWindow();\n * if (remaining > 0) {\n * setValue(newValue);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n * ```\n */\nexport function createRateLimitedSignal<TValue, TSelected = RateLimiterState>(\n value: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidRateLimiter<Setter<TValue>, TSelected>,\n] {\n const [rateLimitedValue, setRateLimitedValue] = createSignal<TValue>(value)\n\n const rateLimiter = createRateLimiter(\n setRateLimitedValue,\n initialOptions,\n selector,\n )\n\n return [\n rateLimitedValue,\n rateLimiter.maybeExecute as Setter<TValue>,\n rateLimiter,\n ]\n}\n"],"names":["createSignal","createRateLimiter"],"mappings":";;;;AAmEO,SAAS,wBACd,OACA,gBACA,UAKA;AACA,QAAM,CAAC,kBAAkB,mBAAmB,IAAIA,QAAAA,aAAqB,KAAK;AAE1E,QAAM,cAAcC,kBAAAA;AAAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGF,SAAO;AAAA,IACL;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,EAAA;AAEJ;;"}
@@ -1,6 +1,6 @@
1
1
  import { SolidRateLimiter } from './createRateLimiter.cjs';
2
2
  import { Accessor, Setter } from 'solid-js';
3
- import { RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
3
+ import { RateLimiterOptions, RateLimiterState } from '@tanstack/pacer/rate-limiter';
4
4
  /**
5
5
  * A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.
6
6
  * This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.
@@ -59,4 +59,8 @@ import { RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
59
59
  * };
60
60
  * ```
61
61
  */
62
- export declare function createRateLimitedSignal<TValue>(value: TValue, initialOptions: RateLimiterOptions<Setter<TValue>>): [Accessor<TValue>, Setter<TValue>, SolidRateLimiter<Setter<TValue>>];
62
+ export declare function createRateLimitedSignal<TValue, TSelected = RateLimiterState>(value: TValue, initialOptions: RateLimiterOptions<Setter<TValue>>, selector?: (state: RateLimiterState) => TSelected): [
63
+ Accessor<TValue>,
64
+ Setter<TValue>,
65
+ SolidRateLimiter<Setter<TValue>, TSelected>
66
+ ];
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const solidJs = require("solid-js");
4
4
  const createRateLimitedSignal = require("./createRateLimitedSignal.cjs");
5
- function createRateLimitedValue(value, initialOptions) {
6
- const [rateLimitedValue, setRateLimitedValue, rateLimiter] = createRateLimitedSignal.createRateLimitedSignal(value(), initialOptions);
5
+ function createRateLimitedValue(value, initialOptions, selector) {
6
+ const [rateLimitedValue, setRateLimitedValue, rateLimiter] = createRateLimitedSignal.createRateLimitedSignal(value(), initialOptions, selector);
7
7
  solidJs.createEffect(() => {
8
8
  setRateLimitedValue(value());
9
9
  });
@@ -1 +1 @@
1
- {"version":3,"file":"createRateLimitedValue.cjs","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 * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\n *\n * For smoother update patterns, consider:\n * - 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 a tuple containing:\n * - An accessor function that provides the rate-limited value\n * - The rate limiter instance with control methods\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 with a sliding window\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Use the rate-limited value\n * console.log(rateLimitedValue()); // Access the current rate-limited value\n *\n * // Control the rate limiter\n * rateLimiter.reset(); // Reset the rate limit window\n * ```\n */\nexport function createRateLimitedValue<TValue>(\n value: Accessor<TValue>,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n): [Accessor<TValue>, SolidRateLimiter<Setter<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":["createRateLimitedSignal","createEffect"],"mappings":";;;;AAiDgB,SAAA,uBACd,OACA,gBACsD;AAChD,QAAA,CAAC,kBAAkB,qBAAqB,WAAW,IACvDA,gDAAwB,SAAS,cAAc;AAEjDC,UAAAA,aAAa,MAAM;AACjB,wBAAoB,OAAc;AAAA,EAAA,CACnC;AAEM,SAAA,CAAC,kBAAkB,WAAW;AACvC;;"}
1
+ {"version":3,"file":"createRateLimitedValue.cjs","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 {\n RateLimiterOptions,\n RateLimiterState,\n} 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 * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\n *\n * For smoother update patterns, consider:\n * - 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 a tuple containing:\n * - An accessor function that provides the rate-limited value\n * - The rate limiter instance with control methods\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 with a sliding window\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Use the rate-limited value\n * console.log(rateLimitedValue()); // Access the current rate-limited value\n *\n * // Control the rate limiter\n * rateLimiter.reset(); // Reset the rate limit window\n * ```\n */\nexport function createRateLimitedValue<TValue, TSelected = RateLimiterState>(\n value: Accessor<TValue>,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, TSelected>] {\n const [rateLimitedValue, setRateLimitedValue, rateLimiter] =\n createRateLimitedSignal(value(), initialOptions, selector)\n\n createEffect(() => {\n setRateLimitedValue(value() as any)\n })\n\n return [rateLimitedValue, rateLimiter]\n}\n"],"names":["createRateLimitedSignal","createEffect"],"mappings":";;;;AAoDO,SAAS,uBACd,OACA,gBACA,UACiE;AACjE,QAAM,CAAC,kBAAkB,qBAAqB,WAAW,IACvDA,wBAAAA,wBAAwB,MAAA,GAAS,gBAAgB,QAAQ;AAE3DC,UAAAA,aAAa,MAAM;AACjB,wBAAoB,OAAc;AAAA,EAAA,CACnC;AAED,SAAO,CAAC,kBAAkB,WAAW;AACvC;;"}
@@ -1,6 +1,6 @@
1
1
  import { SolidRateLimiter } from './createRateLimiter.cjs';
2
2
  import { Accessor, Setter } from 'solid-js';
3
- import { RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
3
+ import { RateLimiterOptions, RateLimiterState } from '@tanstack/pacer/rate-limiter';
4
4
  /**
5
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
6
  * This hook uses Solid's createSignal internally to manage the rate-limited state.
@@ -44,4 +44,4 @@ import { RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
44
44
  * rateLimiter.reset(); // Reset the rate limit window
45
45
  * ```
46
46
  */
47
- export declare function createRateLimitedValue<TValue>(value: Accessor<TValue>, initialOptions: RateLimiterOptions<Setter<TValue>>): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>>];
47
+ export declare function createRateLimitedValue<TValue, TSelected = RateLimiterState>(value: Accessor<TValue>, initialOptions: RateLimiterOptions<Setter<TValue>>, selector?: (state: RateLimiterState) => TSelected): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, TSelected>];
@@ -1,51 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const rateLimiter = require("@tanstack/pacer/rate-limiter");
4
- const solidJs = require("solid-js");
5
- const utils = require("@tanstack/pacer/utils");
6
- function createRateLimiter(fn, initialOptions) {
7
- const rateLimiter$1 = utils.bindInstanceMethods(
8
- new rateLimiter.RateLimiter(fn, initialOptions)
9
- );
10
- const [executionCount, setExecutionCount] = solidJs.createSignal(
11
- rateLimiter$1.getExecutionCount()
12
- );
13
- const [rejectionCount, setRejectionCount] = solidJs.createSignal(
14
- rateLimiter$1.getRejectionCount()
15
- );
16
- const [remainingInWindow, setRemainingInWindow] = solidJs.createSignal(
17
- rateLimiter$1.getRemainingInWindow()
18
- );
19
- const [msUntilNextWindow, setMsUntilNextWindow] = solidJs.createSignal(
20
- rateLimiter$1.getMsUntilNextWindow()
21
- );
22
- function setOptions(newOptions) {
23
- rateLimiter$1.setOptions({
24
- ...newOptions,
25
- onExecute: (rateLimiter2) => {
26
- setExecutionCount(rateLimiter2.getExecutionCount());
27
- setRemainingInWindow(rateLimiter2.getRemainingInWindow());
28
- setMsUntilNextWindow(rateLimiter2.getMsUntilNextWindow());
29
- const onExecute = newOptions.onExecute ?? initialOptions.onExecute;
30
- onExecute == null ? void 0 : onExecute(rateLimiter2);
31
- },
32
- onReject: (rateLimiter2) => {
33
- setRejectionCount(rateLimiter2.getRejectionCount());
34
- setRemainingInWindow(rateLimiter2.getRemainingInWindow());
35
- setMsUntilNextWindow(rateLimiter2.getMsUntilNextWindow());
36
- const onReject = newOptions.onReject ?? initialOptions.onReject;
37
- onReject == null ? void 0 : onReject(rateLimiter2);
38
- }
39
- });
40
- }
41
- setOptions(initialOptions);
4
+ const solidStore = require("@tanstack/solid-store");
5
+ function createRateLimiter(fn, initialOptions, selector) {
6
+ const rateLimiter$1 = new rateLimiter.RateLimiter(fn, initialOptions);
7
+ const state = solidStore.useStore(rateLimiter$1.store, selector);
42
8
  return {
43
9
  ...rateLimiter$1,
44
- executionCount,
45
- rejectionCount,
46
- remainingInWindow,
47
- msUntilNextWindow,
48
- setOptions
10
+ state
49
11
  };
50
12
  }
51
13
  exports.createRateLimiter = createRateLimiter;
@@ -1 +1 @@
1
- {"version":3,"file":"createRateLimiter.cjs","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<TFn extends AnyFunction>\n extends Omit<\n RateLimiter<TFn>,\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 * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n * consistent rate of execution over time.\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 with a sliding window\n * const rateLimiter = createRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * onReject: (rateLimiter) => {\n * console.log(`Rate limit exceeded. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\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<TFn extends AnyFunction>(\n fn: TFn,\n initialOptions: RateLimiterOptions<TFn>,\n): SolidRateLimiter<TFn> {\n const rateLimiter = bindInstanceMethods(\n new RateLimiter<TFn>(fn, initialOptions),\n )\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>>) {\n rateLimiter.setOptions({\n ...newOptions,\n onExecute: (rateLimiter) => {\n setExecutionCount(rateLimiter.getExecutionCount())\n setRemainingInWindow(rateLimiter.getRemainingInWindow())\n setMsUntilNextWindow(rateLimiter.getMsUntilNextWindow())\n\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\n const onReject = newOptions.onReject ?? initialOptions.onReject\n onReject?.(rateLimiter)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...rateLimiter,\n executionCount,\n rejectionCount,\n remainingInWindow,\n msUntilNextWindow,\n setOptions,\n } as SolidRateLimiter<TFn>\n}\n"],"names":["rateLimiter","bindInstanceMethods","RateLimiter","createSignal"],"mappings":";;;;;AA6DgB,SAAA,kBACd,IACA,gBACuB;AACvB,QAAMA,gBAAcC,MAAA;AAAA,IAClB,IAAIC,YAAAA,YAAiB,IAAI,cAAc;AAAA,EACzC;AAEM,QAAA,CAAC,gBAAgB,iBAAiB,IAAIC,QAAA;AAAA,IAC1CH,cAAY,kBAAkB;AAAA,EAChC;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAIG,QAAA;AAAA,IAC1CH,cAAY,kBAAkB;AAAA,EAChC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIG,QAAA;AAAA,IAChDH,cAAY,qBAAqB;AAAA,EACnC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIG,QAAA;AAAA,IAChDH,cAAY,qBAAqB;AAAA,EACnC;AAEA,WAAS,WAAW,YAA8C;AAChEA,kBAAY,WAAW;AAAA,MACrB,GAAG;AAAA,MACH,WAAW,CAACA,iBAAgB;AACRA,0BAAAA,aAAY,mBAAmB;AAC5BA,6BAAAA,aAAY,sBAAsB;AAClCA,6BAAAA,aAAY,sBAAsB;AAEjD,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;AAEjD,cAAA,WAAW,WAAW,YAAY,eAAe;AACvD,6CAAWA;AAAAA,MAAW;AAAA,IACxB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAGA;AAAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
1
+ {"version":3,"file":"createRateLimiter.cjs","sources":["../../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { useStore } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\nexport interface SolidRateLimiter<\n TFn extends AnyFunction,\n TSelected = RateLimiterState,\n> extends Omit<RateLimiter<TFn>, 'store'> {\n /**\n * Reactive state that will be updated when the rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\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 * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n * consistent rate of execution over time.\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 with a sliding window\n * const rateLimiter = createRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * onReject: (rateLimiter) => {\n * console.log(`Rate limit exceeded. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\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 TSelected = RateLimiterState,\n>(\n fn: TFn,\n initialOptions: RateLimiterOptions<TFn>,\n selector?: (state: RateLimiterState) => TSelected,\n): SolidRateLimiter<TFn, TSelected> {\n const rateLimiter = new RateLimiter<TFn>(fn, initialOptions)\n\n const state = useStore(rateLimiter.store, selector)\n\n return {\n ...rateLimiter,\n state,\n } as unknown as SolidRateLimiter<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"names":["rateLimiter","RateLimiter","useStore"],"mappings":";;;;AA6DO,SAAS,kBAId,IACA,gBACA,UACkC;AAClC,QAAMA,gBAAc,IAAIC,wBAAiB,IAAI,cAAc;AAE3D,QAAM,QAAQC,WAAAA,SAASF,cAAY,OAAO,QAAQ;AAElD,SAAO;AAAA,IACL,GAAGA;AAAAA,IACH;AAAA,EAAA;AAEJ;;"}
@@ -1,11 +1,13 @@
1
- import { RateLimiter, RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
1
+ import { RateLimiter, RateLimiterOptions, RateLimiterState } from '@tanstack/pacer/rate-limiter';
2
2
  import { Accessor } from 'solid-js';
3
3
  import { AnyFunction } from '@tanstack/pacer/types';
4
- export interface SolidRateLimiter<TFn extends AnyFunction> extends Omit<RateLimiter<TFn>, 'getExecutionCount' | 'getMsUntilNextWindow' | 'getRejectionCount' | 'getRemainingInWindow'> {
5
- executionCount: Accessor<number>;
6
- msUntilNextWindow: Accessor<number>;
7
- rejectionCount: Accessor<number>;
8
- remainingInWindow: Accessor<number>;
4
+ export interface SolidRateLimiter<TFn extends AnyFunction, TSelected = RateLimiterState> extends Omit<RateLimiter<TFn>, 'store'> {
5
+ /**
6
+ * Reactive state that will be updated when the rate limiter state changes
7
+ *
8
+ * Use this instead of `rateLimiter.store.state`
9
+ */
10
+ readonly state: Accessor<Readonly<TSelected>>;
9
11
  }
10
12
  /**
11
13
  * A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.
@@ -47,4 +49,4 @@ export interface SolidRateLimiter<TFn extends AnyFunction> extends Omit<RateLimi
47
49
  * console.log('Next window in:', rateLimiter.msUntilNextWindow());
48
50
  * ```
49
51
  */
50
- export declare function createRateLimiter<TFn extends AnyFunction>(fn: TFn, initialOptions: RateLimiterOptions<TFn>): SolidRateLimiter<TFn>;
52
+ export declare function createRateLimiter<TFn extends AnyFunction, TSelected = RateLimiterState>(fn: TFn, initialOptions: RateLimiterOptions<TFn>, selector?: (state: RateLimiterState) => TSelected): SolidRateLimiter<TFn, TSelected>;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const solidJs = require("solid-js");
4
4
  const createThrottler = require("./createThrottler.cjs");
5
- function createThrottledSignal(value, initialOptions) {
5
+ function createThrottledSignal(value, initialOptions, selector) {
6
6
  const [throttledValue, setThrottledValue] = solidJs.createSignal(value);
7
- const throttler = createThrottler.createThrottler(setThrottledValue, initialOptions);
7
+ const throttler = createThrottler.createThrottler(setThrottledValue, initialOptions, selector);
8
8
  return [throttledValue, throttler.maybeExecute, throttler];
9
9
  }
10
10
  exports.createThrottledSignal = createThrottledSignal;
@@ -1 +1 @@
1
- {"version":3,"file":"createThrottledSignal.cjs","sources":["../../../src/throttler/createThrottledSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createThrottler } from './createThrottler'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\n\n/**\n * A Solid hook that creates a throttled state value that updates at most once within a specified time window.\n * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.\n *\n * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.\n * This is useful for rate-limiting expensive re-renders or operations that depend on rapidly changing state.\n *\n * The hook returns a tuple containing:\n * - The throttled state value accessor\n * - A throttled setter function that respects the configured wait time\n * - The throttler instance for additional control\n *\n * For more direct control over throttling without state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * @example\n * ```tsx\n * // Basic throttling - update state at most once per second\n * const [value, setValue, throttler] = createThrottledSignal(0, { wait: 1000 });\n *\n * // With custom leading/trailing behavior\n * const [value, setValue] = createThrottledSignal(0, {\n * wait: 1000,\n * leading: true, // Update immediately on first change\n * trailing: false // Skip trailing edge updates\n * });\n *\n * // Access throttler state via signals\n * console.log('Executions:', throttler.executionCount());\n * console.log('Is pending:', throttler.isPending());\n * console.log('Last execution:', throttler.lastExecutionTime());\n * console.log('Next execution:', throttler.nextExecutionTime());\n * ```\n */\nexport function createThrottledSignal<TValue>(\n value: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n): [Accessor<TValue>, Setter<TValue>, SolidThrottler<Setter<TValue>>] {\n const [throttledValue, setThrottledValue] = createSignal<TValue>(value)\n const throttler = createThrottler(setThrottledValue, initialOptions)\n return [throttledValue, throttler.maybeExecute as Setter<TValue>, throttler]\n}\n"],"names":["createSignal","createThrottler"],"mappings":";;;;AAwCgB,SAAA,sBACd,OACA,gBACoE;AACpE,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,QAAAA,aAAqB,KAAK;AAChE,QAAA,YAAYC,gBAAAA,gBAAgB,mBAAmB,cAAc;AACnE,SAAO,CAAC,gBAAgB,UAAU,cAAgC,SAAS;AAC7E;;"}
1
+ {"version":3,"file":"createThrottledSignal.cjs","sources":["../../../src/throttler/createThrottledSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createThrottler } from './createThrottler'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\n/**\n * A Solid hook that creates a throttled state value that updates at most once within a specified time window.\n * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.\n *\n * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.\n * This is useful for rate-limiting expensive re-renders or operations that depend on rapidly changing state.\n *\n * The hook returns a tuple containing:\n * - The throttled state value accessor\n * - A throttled setter function that respects the configured wait time\n * - The throttler instance for additional control\n *\n * For more direct control over throttling without state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * @example\n * ```tsx\n * // Basic throttling - update state at most once per second\n * const [value, setValue, throttler] = createThrottledSignal(0, { wait: 1000 });\n *\n * // With custom leading/trailing behavior\n * const [value, setValue] = createThrottledSignal(0, {\n * wait: 1000,\n * leading: true, // Update immediately on first change\n * trailing: false // Skip trailing edge updates\n * });\n *\n * // Access throttler state via signals\n * console.log('Executions:', throttler.executionCount());\n * console.log('Is pending:', throttler.isPending());\n * console.log('Last execution:', throttler.lastExecutionTime());\n * console.log('Next execution:', throttler.nextExecutionTime());\n * ```\n */\nexport function createThrottledSignal<\n TValue,\n TSelected = ThrottlerState<Setter<TValue>>,\n>(\n value: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidThrottler<Setter<TValue>, TSelected>,\n] {\n const [throttledValue, setThrottledValue] = createSignal<TValue>(value)\n const throttler = createThrottler(setThrottledValue, initialOptions, selector)\n return [throttledValue, throttler.maybeExecute as Setter<TValue>, throttler]\n}\n"],"names":["createSignal","createThrottler"],"mappings":";;;;AA2CO,SAAS,sBAId,OACA,gBACA,UAKA;AACA,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,QAAAA,aAAqB,KAAK;AACtE,QAAM,YAAYC,gBAAAA,gBAAgB,mBAAmB,gBAAgB,QAAQ;AAC7E,SAAO,CAAC,gBAAgB,UAAU,cAAgC,SAAS;AAC7E;;"}
@@ -1,6 +1,6 @@
1
1
  import { SolidThrottler } from './createThrottler.cjs';
2
2
  import { Accessor, Setter } from 'solid-js';
3
- import { ThrottlerOptions } from '@tanstack/pacer/throttler';
3
+ import { ThrottlerOptions, ThrottlerState } from '@tanstack/pacer/throttler';
4
4
  /**
5
5
  * A Solid hook that creates a throttled state value that updates at most once within a specified time window.
6
6
  * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.
@@ -35,4 +35,8 @@ import { ThrottlerOptions } from '@tanstack/pacer/throttler';
35
35
  * console.log('Next execution:', throttler.nextExecutionTime());
36
36
  * ```
37
37
  */
38
- export declare function createThrottledSignal<TValue>(value: TValue, initialOptions: ThrottlerOptions<Setter<TValue>>): [Accessor<TValue>, Setter<TValue>, SolidThrottler<Setter<TValue>>];
38
+ export declare function createThrottledSignal<TValue, TSelected = ThrottlerState<Setter<TValue>>>(value: TValue, initialOptions: ThrottlerOptions<Setter<TValue>>, selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected): [
39
+ Accessor<TValue>,
40
+ Setter<TValue>,
41
+ SolidThrottler<Setter<TValue>, TSelected>
42
+ ];
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const solidJs = require("solid-js");
4
4
  const createThrottledSignal = require("./createThrottledSignal.cjs");
5
- function createThrottledValue(value, initialOptions) {
5
+ function createThrottledValue(value, initialOptions, selector) {
6
6
  const [throttledValue, setThrottledValue, throttler] = createThrottledSignal.createThrottledSignal(
7
7
  value(),
8
- initialOptions
8
+ initialOptions,
9
+ selector
9
10
  );
10
11
  solidJs.createEffect(() => {
11
12
  setThrottledValue(value());
@@ -1 +1 @@
1
- {"version":3,"file":"createThrottledValue.cjs","sources":["../../../src/throttler/createThrottledValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createThrottledSignal } from './createThrottledSignal'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\n\n/**\n * A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window.\n * This hook uses Solid's createSignal internally to manage the throttled state.\n *\n * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.\n * This is useful for rate-limiting expensive re-renders or API calls that depend on rapidly changing values.\n *\n * The hook returns a tuple containing:\n * - An accessor function that provides the throttled value\n * - The throttler instance with control methods\n *\n * The throttled value will update according to the leading/trailing edge behavior specified in the options.\n *\n * For more direct control over throttling behavior without Solid state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * @example\n * ```tsx\n * // Basic throttling - update at most once per second\n * const [throttledValue, throttler] = createThrottledValue(rawValue, { wait: 1000 });\n *\n * // Use the throttled value\n * console.log(throttledValue()); // Access the current throttled value\n *\n * // Control the throttler\n * throttler.cancel(); // Cancel any pending updates\n * ```\n */\nexport function createThrottledValue<TValue>(\n value: Accessor<TValue>,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n): [Accessor<TValue>, SolidThrottler<Setter<TValue>>] {\n const [throttledValue, setThrottledValue, throttler] = createThrottledSignal(\n value(),\n initialOptions,\n )\n\n createEffect(() => {\n setThrottledValue(value() as any)\n })\n\n return [throttledValue, throttler]\n}\n"],"names":["createThrottledSignal","createEffect"],"mappings":";;;;AAkCgB,SAAA,qBACd,OACA,gBACoD;AACpD,QAAM,CAAC,gBAAgB,mBAAmB,SAAS,IAAIA,sBAAA;AAAA,IACrD,MAAM;AAAA,IACN;AAAA,EACF;AAEAC,UAAAA,aAAa,MAAM;AACjB,sBAAkB,OAAc;AAAA,EAAA,CACjC;AAEM,SAAA,CAAC,gBAAgB,SAAS;AACnC;;"}
1
+ {"version":3,"file":"createThrottledValue.cjs","sources":["../../../src/throttler/createThrottledValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createThrottledSignal } from './createThrottledSignal'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\n/**\n * A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window.\n * This hook uses Solid's createSignal internally to manage the throttled state.\n *\n * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.\n * This is useful for rate-limiting expensive re-renders or API calls that depend on rapidly changing values.\n *\n * The hook returns a tuple containing:\n * - An accessor function that provides the throttled value\n * - The throttler instance with control methods\n *\n * The throttled value will update according to the leading/trailing edge behavior specified in the options.\n *\n * For more direct control over throttling behavior without Solid state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * @example\n * ```tsx\n * // Basic throttling - update at most once per second\n * const [throttledValue, throttler] = createThrottledValue(rawValue, { wait: 1000 });\n *\n * // Use the throttled value\n * console.log(throttledValue()); // Access the current throttled value\n *\n * // Control the throttler\n * throttler.cancel(); // Cancel any pending updates\n * ```\n */\nexport function createThrottledValue<\n TValue,\n TSelected = ThrottlerState<Setter<TValue>>,\n>(\n value: Accessor<TValue>,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): [Accessor<TValue>, SolidThrottler<Setter<TValue>, TSelected>] {\n const [throttledValue, setThrottledValue, throttler] = createThrottledSignal(\n value(),\n initialOptions,\n selector,\n )\n\n createEffect(() => {\n setThrottledValue(value() as any)\n })\n\n return [throttledValue, throttler]\n}\n"],"names":["createThrottledSignal","createEffect"],"mappings":";;;;AAqCO,SAAS,qBAId,OACA,gBACA,UAC+D;AAC/D,QAAM,CAAC,gBAAgB,mBAAmB,SAAS,IAAIA,sBAAAA;AAAAA,IACrD,MAAA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGFC,UAAAA,aAAa,MAAM;AACjB,sBAAkB,OAAc;AAAA,EAAA,CACjC;AAED,SAAO,CAAC,gBAAgB,SAAS;AACnC;;"}
@@ -1,6 +1,6 @@
1
1
  import { SolidThrottler } from './createThrottler.cjs';
2
2
  import { Accessor, Setter } from 'solid-js';
3
- import { ThrottlerOptions } from '@tanstack/pacer/throttler';
3
+ import { ThrottlerOptions, ThrottlerState } from '@tanstack/pacer/throttler';
4
4
  /**
5
5
  * A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window.
6
6
  * This hook uses Solid's createSignal internally to manage the throttled state.
@@ -29,4 +29,4 @@ import { ThrottlerOptions } from '@tanstack/pacer/throttler';
29
29
  * throttler.cancel(); // Cancel any pending updates
30
30
  * ```
31
31
  */
32
- export declare function createThrottledValue<TValue>(value: Accessor<TValue>, initialOptions: ThrottlerOptions<Setter<TValue>>): [Accessor<TValue>, SolidThrottler<Setter<TValue>>];
32
+ export declare function createThrottledValue<TValue, TSelected = ThrottlerState<Setter<TValue>>>(value: Accessor<TValue>, initialOptions: ThrottlerOptions<Setter<TValue>>, selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected): [Accessor<TValue>, SolidThrottler<Setter<TValue>, TSelected>];
@@ -2,45 +2,18 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const throttler = require("@tanstack/pacer/throttler");
4
4
  const solidJs = require("solid-js");
5
- const utils = require("@tanstack/pacer/utils");
6
- function createThrottler(fn, initialOptions) {
7
- const throttler$1 = utils.bindInstanceMethods(new throttler.Throttler(fn, initialOptions));
8
- const [executionCount, setExecutionCount] = solidJs.createSignal(
9
- throttler$1.getExecutionCount()
10
- );
11
- const [isPending, setIsPending] = solidJs.createSignal(throttler$1.getIsPending());
12
- const [lastExecutionTime, setLastExecutionTime] = solidJs.createSignal(
13
- throttler$1.getLastExecutionTime()
14
- );
15
- const [nextExecutionTime, setNextExecutionTime] = solidJs.createSignal(
16
- throttler$1.getNextExecutionTime()
17
- );
18
- function setOptions(newOptions) {
19
- throttler$1.setOptions({
20
- ...newOptions,
21
- onExecute: (throttler2) => {
22
- setExecutionCount(throttler2.getExecutionCount());
23
- setIsPending(throttler2.getIsPending());
24
- setLastExecutionTime(throttler2.getLastExecutionTime());
25
- setNextExecutionTime(throttler2.getNextExecutionTime());
26
- const onExecute = newOptions.onExecute ?? initialOptions.onExecute;
27
- onExecute == null ? void 0 : onExecute(throttler2);
28
- }
29
- });
30
- }
31
- setOptions(initialOptions);
5
+ const solidStore = require("@tanstack/solid-store");
6
+ function createThrottler(fn, initialOptions, selector) {
7
+ const asyncThrottler = new throttler.Throttler(fn, initialOptions);
8
+ const state = solidStore.useStore(asyncThrottler.store, selector);
32
9
  solidJs.createEffect(() => {
33
10
  solidJs.onCleanup(() => {
34
- throttler$1.cancel();
11
+ asyncThrottler.cancel();
35
12
  });
36
13
  });
37
14
  return {
38
- ...throttler$1,
39
- executionCount,
40
- isPending,
41
- lastExecutionTime,
42
- nextExecutionTime,
43
- setOptions
15
+ ...asyncThrottler,
16
+ state
44
17
  };
45
18
  }
46
19
  exports.createThrottler = createThrottler;
@@ -1 +1 @@
1
- {"version":3,"file":"createThrottler.cjs","sources":["../../../src/throttler/createThrottler.ts"],"sourcesContent":["import { Throttler } from '@tanstack/pacer/throttler'\nimport { createEffect, createSignal, onCleanup } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\n\n/**\n * An extension of the Throttler class that adds Solid signals to access the internal state of the throttler\n */\nexport interface SolidThrottler<TFn extends AnyFunction>\n extends Omit<\n Throttler<TFn>,\n | 'getExecutionCount'\n | 'getIsPending'\n | 'getLastExecutionTime'\n | 'getNextExecutionTime'\n > {\n executionCount: Accessor<number>\n isPending: Accessor<boolean>\n lastExecutionTime: Accessor<number>\n nextExecutionTime: Accessor<number>\n}\n\n/**\n * A low-level Solid hook that creates a `Throttler` instance that limits how often the provided function can execute.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that\n * you can integrate with any state management solution (createSignal, Redux, Zustand, Jotai, etc). For a simpler and higher-level hook that\n * integrates directly with Solid's createSignal, see createThrottledSignal.\n *\n * Throttling ensures a function executes at most once within a specified time window,\n * regardless of how many times it is called. This is useful for rate-limiting\n * expensive operations or UI updates.\n *\n * @example\n * ```tsx\n * // Basic throttling with custom state\n * const [value, setValue] = createSignal(0);\n * const throttler = createThrottler(setValue, { wait: 1000 });\n *\n * // With any state manager\n * const throttler = createThrottler(\n * (value) => stateManager.setState(value),\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false // Skip trailing edge updates\n * }\n * );\n *\n * // Access throttler state via signals\n * console.log(throttler.executionCount()); // number of times executed\n * console.log(throttler.isPending()); // whether throttled function is pending\n * console.log(throttler.lastExecutionTime()); // timestamp of last execution\n * console.log(throttler.nextExecutionTime()); // timestamp of next allowed execution\n * ```\n */\nexport function createThrottler<TFn extends AnyFunction>(\n fn: TFn,\n initialOptions: ThrottlerOptions<TFn>,\n): SolidThrottler<TFn> {\n const throttler = bindInstanceMethods(new Throttler<TFn>(fn, initialOptions))\n\n const [executionCount, setExecutionCount] = createSignal(\n throttler.getExecutionCount(),\n )\n const [isPending, setIsPending] = createSignal(throttler.getIsPending())\n const [lastExecutionTime, setLastExecutionTime] = createSignal(\n throttler.getLastExecutionTime(),\n )\n const [nextExecutionTime, setNextExecutionTime] = createSignal(\n throttler.getNextExecutionTime(),\n )\n\n function setOptions(newOptions: Partial<ThrottlerOptions<TFn>>) {\n throttler.setOptions({\n ...newOptions,\n onExecute: (throttler) => {\n setExecutionCount(throttler.getExecutionCount())\n setIsPending(throttler.getIsPending())\n setLastExecutionTime(throttler.getLastExecutionTime())\n setNextExecutionTime(throttler.getNextExecutionTime())\n\n const onExecute = newOptions.onExecute ?? initialOptions.onExecute\n onExecute?.(throttler)\n },\n })\n }\n\n setOptions(initialOptions)\n\n createEffect(() => {\n onCleanup(() => {\n throttler.cancel()\n })\n })\n\n return {\n ...throttler,\n executionCount,\n isPending,\n lastExecutionTime,\n nextExecutionTime,\n setOptions,\n } as SolidThrottler<TFn>\n}\n"],"names":["throttler","bindInstanceMethods","Throttler","createSignal","createEffect","onCleanup"],"mappings":";;;;;AA0DgB,SAAA,gBACd,IACA,gBACqB;AACrB,QAAMA,cAAYC,MAAAA,oBAAoB,IAAIC,UAAe,UAAA,IAAI,cAAc,CAAC;AAEtE,QAAA,CAAC,gBAAgB,iBAAiB,IAAIC,QAAA;AAAA,IAC1CH,YAAU,kBAAkB;AAAA,EAC9B;AACA,QAAM,CAAC,WAAW,YAAY,IAAIG,QAAAA,aAAaH,YAAU,cAAc;AACjE,QAAA,CAAC,mBAAmB,oBAAoB,IAAIG,QAAA;AAAA,IAChDH,YAAU,qBAAqB;AAAA,EACjC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIG,QAAA;AAAA,IAChDH,YAAU,qBAAqB;AAAA,EACjC;AAEA,WAAS,WAAW,YAA4C;AAC9DA,gBAAU,WAAW;AAAA,MACnB,GAAG;AAAA,MACH,WAAW,CAACA,eAAc;AACNA,0BAAAA,WAAU,mBAAmB;AAClCA,qBAAAA,WAAU,cAAc;AAChBA,6BAAAA,WAAU,sBAAsB;AAChCA,6BAAAA,WAAU,sBAAsB;AAE/C,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MAAS;AAAA,IACvB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAEzBI,UAAAA,aAAa,MAAM;AACjBC,YAAAA,UAAU,MAAM;AACdL,kBAAU,OAAO;AAAA,IAAA,CAClB;AAAA,EAAA,CACF;AAEM,SAAA;AAAA,IACL,GAAGA;AAAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
1
+ {"version":3,"file":"createThrottler.cjs","sources":["../../../src/throttler/createThrottler.ts"],"sourcesContent":["import { Throttler } from '@tanstack/pacer/throttler'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { useStore } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\nexport interface SolidThrottler<\n TFn extends AnyFunction,\n TSelected = ThrottlerState<TFn>,\n> extends Omit<Throttler<TFn>, 'store'> {\n /**\n * Reactive state that will be updated when the throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n}\n\n/**\n * A low-level Solid hook that creates a `Throttler` instance that limits how often the provided function can execute.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that\n * you can integrate with any state management solution (createSignal, Redux, Zustand, Jotai, etc). For a simpler and higher-level hook that\n * integrates directly with Solid's createSignal, see createThrottledSignal.\n *\n * Throttling ensures a function executes at most once within a specified time window,\n * regardless of how many times it is called. This is useful for rate-limiting\n * expensive operations or UI updates.\n *\n * @example\n * ```tsx\n * // Basic throttling with custom state\n * const [value, setValue] = createSignal(0);\n * const throttler = createThrottler(setValue, { wait: 1000 });\n *\n * // With any state manager\n * const throttler = createThrottler(\n * (value) => stateManager.setState(value),\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false // Skip trailing edge updates\n * }\n * );\n *\n * // Access throttler state via signals\n * console.log(throttler.executionCount()); // number of times executed\n * console.log(throttler.isPending()); // whether throttled function is pending\n * console.log(throttler.lastExecutionTime()); // timestamp of last execution\n * console.log(throttler.nextExecutionTime()); // timestamp of next allowed execution\n * ```\n */\nexport function createThrottler<\n TFn extends AnyFunction,\n TSelected = ThrottlerState<TFn>,\n>(\n fn: TFn,\n initialOptions: ThrottlerOptions<TFn>,\n selector?: (state: ThrottlerState<TFn>) => TSelected,\n): SolidThrottler<TFn, TSelected> {\n const asyncThrottler = new Throttler<TFn>(fn, initialOptions)\n\n const state = useStore(asyncThrottler.store, selector)\n\n createEffect(() => {\n onCleanup(() => {\n asyncThrottler.cancel()\n })\n })\n\n return {\n ...asyncThrottler,\n state,\n } as SolidThrottler<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"names":["Throttler","useStore","createEffect","onCleanup"],"mappings":";;;;;AAwDO,SAAS,gBAId,IACA,gBACA,UACgC;AAChC,QAAM,iBAAiB,IAAIA,oBAAe,IAAI,cAAc;AAE5D,QAAM,QAAQC,WAAAA,SAAS,eAAe,OAAO,QAAQ;AAErDC,UAAAA,aAAa,MAAM;AACjBC,YAAAA,UAAU,MAAM;AACd,qBAAe,OAAA;AAAA,IAAO,CACvB;AAAA,EAAA,CACF;AAED,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,EAAA;AAEJ;;"}
@@ -1,14 +1,13 @@
1
- import { Throttler, ThrottlerOptions } from '@tanstack/pacer/throttler';
1
+ import { Throttler, ThrottlerOptions, ThrottlerState } from '@tanstack/pacer/throttler';
2
2
  import { Accessor } from 'solid-js';
3
3
  import { AnyFunction } from '@tanstack/pacer/types';
4
- /**
5
- * An extension of the Throttler class that adds Solid signals to access the internal state of the throttler
6
- */
7
- export interface SolidThrottler<TFn extends AnyFunction> extends Omit<Throttler<TFn>, 'getExecutionCount' | 'getIsPending' | 'getLastExecutionTime' | 'getNextExecutionTime'> {
8
- executionCount: Accessor<number>;
9
- isPending: Accessor<boolean>;
10
- lastExecutionTime: Accessor<number>;
11
- nextExecutionTime: Accessor<number>;
4
+ export interface SolidThrottler<TFn extends AnyFunction, TSelected = ThrottlerState<TFn>> extends Omit<Throttler<TFn>, 'store'> {
5
+ /**
6
+ * Reactive state that will be updated when the throttler state changes
7
+ *
8
+ * Use this instead of `throttler.store.state`
9
+ */
10
+ readonly state: Accessor<Readonly<TSelected>>;
12
11
  }
13
12
  /**
14
13
  * A low-level Solid hook that creates a `Throttler` instance that limits how often the provided function can execute.
@@ -44,4 +43,4 @@ export interface SolidThrottler<TFn extends AnyFunction> extends Omit<Throttler<
44
43
  * console.log(throttler.nextExecutionTime()); // timestamp of next allowed execution
45
44
  * ```
46
45
  */
47
- export declare function createThrottler<TFn extends AnyFunction>(fn: TFn, initialOptions: ThrottlerOptions<TFn>): SolidThrottler<TFn>;
46
+ export declare function createThrottler<TFn extends AnyFunction, TSelected = ThrottlerState<TFn>>(fn: TFn, initialOptions: ThrottlerOptions<TFn>, selector?: (state: ThrottlerState<TFn>) => TSelected): SolidThrottler<TFn, TSelected>;
@@ -0,0 +1,72 @@
1
+ import { AsyncBatcher, AsyncBatcherOptions, AsyncBatcherState } from '@tanstack/pacer/async-batcher';
2
+ import { Accessor } from 'solid-js';
3
+ export interface SolidAsyncBatcher<TValue, TSelected = AsyncBatcherState<TValue>> extends Omit<AsyncBatcher<TValue>, 'store'> {
4
+ /**
5
+ * Reactive state that will be updated when the batcher state changes
6
+ *
7
+ * Use this instead of `batcher.store.state`
8
+ */
9
+ readonly state: Accessor<Readonly<TSelected>>;
10
+ }
11
+ /**
12
+ * Creates a Solid-compatible AsyncBatcher instance for managing asynchronous batches of items, exposing Solid signals for all stateful properties.
13
+ *
14
+ * This is the async version of the createBatcher hook. Unlike the sync version, this async batcher:
15
+ * - Handles promises and returns results from batch executions
16
+ * - Provides error handling with configurable error behavior
17
+ * - Tracks success, error, and settle counts separately
18
+ * - Has state tracking for when batches are executing
19
+ * - Returns the result of the batch function execution
20
+ *
21
+ * Features:
22
+ * - Configurable batch size and wait time
23
+ * - Custom batch processing logic via getShouldExecute
24
+ * - Event callbacks for monitoring batch operations
25
+ * - Error handling for failed batch operations
26
+ * - Automatic or manual batch processing
27
+ * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity
28
+ *
29
+ * The batcher collects items and processes them in batches based on:
30
+ * - Maximum batch size (number of items per batch)
31
+ * - Time-based batching (process after X milliseconds)
32
+ * - Custom batch processing logic via getShouldExecute
33
+ *
34
+ * Error Handling:
35
+ * - If an `onError` handler is provided, it will be called with the error and batcher instance
36
+ * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
37
+ * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
38
+ * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown
39
+ * - The error state can be checked using the underlying AsyncBatcher instance
40
+ *
41
+ * Example usage:
42
+ * ```tsx
43
+ * // Basic async batcher for API requests
44
+ * const asyncBatcher = createAsyncBatcher(
45
+ * async (items) => {
46
+ * const results = await Promise.all(items.map(item => processItem(item)));
47
+ * return results;
48
+ * },
49
+ * {
50
+ * maxSize: 10,
51
+ * wait: 2000,
52
+ * onSuccess: (result) => {
53
+ * console.log('Batch processed successfully:', result);
54
+ * },
55
+ * onError: (error) => {
56
+ * console.error('Batch processing failed:', error);
57
+ * }
58
+ * }
59
+ * );
60
+ *
61
+ * // Add items to batch
62
+ * asyncBatcher.addItem(newItem);
63
+ *
64
+ * // Manually execute batch
65
+ * const result = await asyncBatcher.execute();
66
+ *
67
+ * // Use Solid signals in your UI
68
+ * const items = asyncBatcher.state().items;
69
+ * const isExecuting = asyncBatcher.state().isExecuting;
70
+ * ```
71
+ */
72
+ export declare function createAsyncBatcher<TValue, TSelected = AsyncBatcherState<TValue>>(fn: (items: Array<TValue>) => Promise<any>, initialOptions?: AsyncBatcherOptions<TValue>, selector?: (state: AsyncBatcherState<TValue>) => TSelected): SolidAsyncBatcher<TValue, TSelected>;
@@ -0,0 +1,14 @@
1
+ import { AsyncBatcher } from "@tanstack/pacer/async-batcher";
2
+ import { useStore } from "@tanstack/solid-store";
3
+ function createAsyncBatcher(fn, initialOptions = {}, selector) {
4
+ const asyncBatcher = new AsyncBatcher(fn, initialOptions);
5
+ const state = useStore(asyncBatcher.store, selector);
6
+ return {
7
+ ...asyncBatcher,
8
+ state
9
+ };
10
+ }
11
+ export {
12
+ createAsyncBatcher
13
+ };
14
+ //# sourceMappingURL=createAsyncBatcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createAsyncBatcher.js","sources":["../../../src/async-batcher/createAsyncBatcher.ts"],"sourcesContent":["import { AsyncBatcher } from '@tanstack/pacer/async-batcher'\nimport { useStore } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type {\n AsyncBatcherOptions,\n AsyncBatcherState,\n} from '@tanstack/pacer/async-batcher'\n\nexport interface SolidAsyncBatcher<\n TValue,\n TSelected = AsyncBatcherState<TValue>,\n> extends Omit<AsyncBatcher<TValue>, 'store'> {\n /**\n * Reactive state that will be updated when the batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n}\n\n/**\n * Creates a Solid-compatible AsyncBatcher instance for managing asynchronous batches of items, exposing Solid signals for all stateful properties.\n *\n * This is the async version of the createBatcher hook. Unlike the sync version, this async batcher:\n * - Handles promises and returns results from batch executions\n * - Provides error handling with configurable error behavior\n * - Tracks success, error, and settle counts separately\n * - Has state tracking for when batches are executing\n * - Returns the result of the batch function execution\n *\n * Features:\n * - Configurable batch size and wait time\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\n * - Error handling for failed batch operations\n * - Automatic or manual batch processing\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The batcher collects items and processes them in batches based on:\n * - Maximum batch size (number of items per batch)\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and batcher instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncBatcher instance\n *\n * Example usage:\n * ```tsx\n * // Basic async batcher for API requests\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * {\n * maxSize: 10,\n * wait: 2000,\n * onSuccess: (result) => {\n * console.log('Batch processed successfully:', result);\n * },\n * onError: (error) => {\n * console.error('Batch processing failed:', error);\n * }\n * }\n * );\n *\n * // Add items to batch\n * asyncBatcher.addItem(newItem);\n *\n * // Manually execute batch\n * const result = await asyncBatcher.execute();\n *\n * // Use Solid signals in your UI\n * const items = asyncBatcher.state().items;\n * const isExecuting = asyncBatcher.state().isExecuting;\n * ```\n */\nexport function createAsyncBatcher<\n TValue,\n TSelected = AsyncBatcherState<TValue>,\n>(\n fn: (items: Array<TValue>) => Promise<any>,\n initialOptions: AsyncBatcherOptions<TValue> = {},\n selector?: (state: AsyncBatcherState<TValue>) => TSelected,\n): SolidAsyncBatcher<TValue, TSelected> {\n const asyncBatcher = new AsyncBatcher<TValue>(fn, initialOptions)\n\n const state = useStore(asyncBatcher.store, selector)\n\n return {\n ...asyncBatcher,\n state,\n } as unknown as SolidAsyncBatcher<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"names":[],"mappings":";;AAiFO,SAAS,mBAId,IACA,iBAA8C,CAAA,GAC9C,UACsC;AACtC,QAAM,eAAe,IAAI,aAAqB,IAAI,cAAc;AAEhE,QAAM,QAAQ,SAAS,aAAa,OAAO,QAAQ;AAEnD,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,EAAA;AAEJ;"}
@@ -0,0 +1,2 @@
1
+ export * from '@tanstack/pacer/async-batcher';
2
+ export * from './createAsyncBatcher.js';
@@ -0,0 +1,6 @@
1
+ export * from "@tanstack/pacer/async-batcher";
2
+ import { createAsyncBatcher } from "./createAsyncBatcher.js";
3
+ export {
4
+ createAsyncBatcher
5
+ };
6
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -1,12 +1,13 @@
1
- import { AsyncDebouncer, AsyncDebouncerOptions } from '@tanstack/pacer/async-debouncer';
2
- import { AnyAsyncFunction } from '@tanstack/pacer/types';
1
+ import { AsyncDebouncer, AsyncDebouncerOptions, AsyncDebouncerState } from '@tanstack/pacer/async-debouncer';
3
2
  import { Accessor } from 'solid-js';
4
- export interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction> extends Omit<AsyncDebouncer<TFn>, 'getErrorCount' | 'getIsPending' | 'getLastResult' | 'getSettleCount' | 'getSuccessCount'> {
5
- errorCount: Accessor<number>;
6
- isPending: Accessor<boolean>;
7
- lastResult: Accessor<ReturnType<TFn> | undefined>;
8
- settleCount: Accessor<number>;
9
- successCount: Accessor<number>;
3
+ import { AnyAsyncFunction } from '@tanstack/pacer/types';
4
+ export interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = AsyncDebouncerState<TFn>> extends Omit<AsyncDebouncer<TFn>, 'store'> {
5
+ /**
6
+ * Reactive state that will be updated when the debouncer state changes
7
+ *
8
+ * Use this instead of `debouncer.store.state`
9
+ */
10
+ readonly state: Accessor<Readonly<TSelected>>;
10
11
  }
11
12
  /**
12
13
  * A low-level Solid hook that creates an `AsyncDebouncer` instance to delay execution of an async function.
@@ -61,4 +62,4 @@ export interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction> extends Omit<
61
62
  * );
62
63
  * ```
63
64
  */
64
- export declare function createAsyncDebouncer<TFn extends AnyAsyncFunction>(fn: TFn, initialOptions: AsyncDebouncerOptions<TFn>): SolidAsyncDebouncer<TFn>;
65
+ export declare function createAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = AsyncDebouncerState<TFn>>(fn: TFn, initialOptions: AsyncDebouncerOptions<TFn>, selector?: (state: AsyncDebouncerState<TFn>) => TSelected): SolidAsyncDebouncer<TFn, TSelected>;
@@ -1,44 +1,17 @@
1
1
  import { AsyncDebouncer } from "@tanstack/pacer/async-debouncer";
2
- import { createSignal } from "solid-js";
3
- import { bindInstanceMethods } from "@tanstack/pacer/utils";
4
- function createAsyncDebouncer(fn, initialOptions) {
2
+ import { useStore } from "@tanstack/solid-store";
3
+ import { createEffect, onCleanup } from "solid-js";
4
+ function createAsyncDebouncer(fn, initialOptions, selector) {
5
5
  const asyncDebouncer = new AsyncDebouncer(fn, initialOptions);
6
- const [errorCount, setErrorCount] = createSignal(
7
- asyncDebouncer.getErrorCount()
8
- );
9
- const [settleCount, setSettleCount] = createSignal(
10
- asyncDebouncer.getSettleCount()
11
- );
12
- const [successCount, setSuccessCount] = createSignal(
13
- asyncDebouncer.getSuccessCount()
14
- );
15
- const [isPending, setIsPending] = createSignal(asyncDebouncer.getIsPending());
16
- const [lastResult, setLastResult] = createSignal(
17
- asyncDebouncer.getLastResult()
18
- );
19
- function setOptions(newOptions) {
20
- asyncDebouncer.setOptions({
21
- ...newOptions,
22
- onSettled: (asyncDebouncer2) => {
23
- setSuccessCount(asyncDebouncer2.getSuccessCount());
24
- setErrorCount(asyncDebouncer2.getErrorCount());
25
- setSettleCount(asyncDebouncer2.getSettleCount());
26
- setIsPending(asyncDebouncer2.getIsPending());
27
- setLastResult(asyncDebouncer2.getLastResult());
28
- const onSettled = newOptions.onSettled ?? initialOptions.onSettled;
29
- onSettled == null ? void 0 : onSettled(asyncDebouncer2);
30
- }
6
+ const state = useStore(asyncDebouncer.store, selector);
7
+ createEffect(() => {
8
+ onCleanup(() => {
9
+ asyncDebouncer.cancel();
31
10
  });
32
- }
33
- setOptions(initialOptions);
11
+ });
34
12
  return {
35
- ...bindInstanceMethods(asyncDebouncer),
36
- errorCount,
37
- isPending,
38
- lastResult,
39
- settleCount,
40
- successCount,
41
- setOptions
13
+ ...asyncDebouncer,
14
+ state
42
15
  };
43
16
  }
44
17
  export {