@tanstack/solid-pacer 0.2.0 → 0.3.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 (89) hide show
  1. package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs +22 -7
  2. package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs.map +1 -1
  3. package/dist/cjs/async-debouncer/createAsyncDebouncer.d.cts +6 -3
  4. package/dist/cjs/async-queuer/createAsyncQueuer.cjs.map +1 -1
  5. package/dist/cjs/async-queuer/createAsyncQueuer.d.cts +5 -1
  6. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs +20 -9
  7. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs.map +1 -1
  8. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.d.cts +5 -3
  9. package/dist/cjs/async-throttler/createAsyncThrottler.cjs +32 -10
  10. package/dist/cjs/async-throttler/createAsyncThrottler.cjs.map +1 -1
  11. package/dist/cjs/async-throttler/createAsyncThrottler.d.cts +7 -3
  12. package/dist/cjs/debouncer/createDebouncedSignal.cjs.map +1 -1
  13. package/dist/cjs/debouncer/createDebouncedSignal.d.cts +1 -5
  14. package/dist/cjs/debouncer/createDebouncedValue.cjs +0 -3
  15. package/dist/cjs/debouncer/createDebouncedValue.cjs.map +1 -1
  16. package/dist/cjs/debouncer/createDebouncedValue.d.cts +5 -11
  17. package/dist/cjs/debouncer/createDebouncer.cjs +7 -2
  18. package/dist/cjs/debouncer/createDebouncer.cjs.map +1 -1
  19. package/dist/cjs/debouncer/createDebouncer.d.cts +2 -2
  20. package/dist/cjs/queuer/createQueuer.cjs +2 -2
  21. package/dist/cjs/queuer/createQueuer.cjs.map +1 -1
  22. package/dist/cjs/queuer/createQueuer.d.cts +4 -0
  23. package/dist/cjs/rate-limiter/createRateLimitedSignal.cjs.map +1 -1
  24. package/dist/cjs/rate-limiter/createRateLimitedSignal.d.cts +1 -5
  25. package/dist/cjs/rate-limiter/createRateLimitedValue.cjs.map +1 -1
  26. package/dist/cjs/rate-limiter/createRateLimitedValue.d.cts +9 -20
  27. package/dist/cjs/rate-limiter/createRateLimiter.cjs +4 -2
  28. package/dist/cjs/rate-limiter/createRateLimiter.cjs.map +1 -1
  29. package/dist/cjs/rate-limiter/createRateLimiter.d.cts +2 -2
  30. package/dist/cjs/throttler/createThrottledSignal.cjs.map +1 -1
  31. package/dist/cjs/throttler/createThrottledSignal.d.cts +1 -5
  32. package/dist/cjs/throttler/createThrottledValue.cjs +0 -3
  33. package/dist/cjs/throttler/createThrottledValue.cjs.map +1 -1
  34. package/dist/cjs/throttler/createThrottledValue.d.cts +10 -14
  35. package/dist/cjs/throttler/createThrottler.cjs +7 -2
  36. package/dist/cjs/throttler/createThrottler.cjs.map +1 -1
  37. package/dist/cjs/throttler/createThrottler.d.cts +2 -2
  38. package/dist/esm/async-debouncer/createAsyncDebouncer.d.ts +6 -3
  39. package/dist/esm/async-debouncer/createAsyncDebouncer.js +22 -7
  40. package/dist/esm/async-debouncer/createAsyncDebouncer.js.map +1 -1
  41. package/dist/esm/async-queuer/createAsyncQueuer.d.ts +5 -1
  42. package/dist/esm/async-queuer/createAsyncQueuer.js.map +1 -1
  43. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.d.ts +5 -3
  44. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js +20 -9
  45. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js.map +1 -1
  46. package/dist/esm/async-throttler/createAsyncThrottler.d.ts +7 -3
  47. package/dist/esm/async-throttler/createAsyncThrottler.js +32 -10
  48. package/dist/esm/async-throttler/createAsyncThrottler.js.map +1 -1
  49. package/dist/esm/debouncer/createDebouncedSignal.d.ts +1 -5
  50. package/dist/esm/debouncer/createDebouncedSignal.js.map +1 -1
  51. package/dist/esm/debouncer/createDebouncedValue.d.ts +5 -11
  52. package/dist/esm/debouncer/createDebouncedValue.js +1 -4
  53. package/dist/esm/debouncer/createDebouncedValue.js.map +1 -1
  54. package/dist/esm/debouncer/createDebouncer.d.ts +2 -2
  55. package/dist/esm/debouncer/createDebouncer.js +8 -3
  56. package/dist/esm/debouncer/createDebouncer.js.map +1 -1
  57. package/dist/esm/queuer/createQueuer.d.ts +4 -0
  58. package/dist/esm/queuer/createQueuer.js +2 -2
  59. package/dist/esm/queuer/createQueuer.js.map +1 -1
  60. package/dist/esm/rate-limiter/createRateLimitedSignal.d.ts +1 -5
  61. package/dist/esm/rate-limiter/createRateLimitedSignal.js.map +1 -1
  62. package/dist/esm/rate-limiter/createRateLimitedValue.d.ts +9 -20
  63. package/dist/esm/rate-limiter/createRateLimitedValue.js.map +1 -1
  64. package/dist/esm/rate-limiter/createRateLimiter.d.ts +2 -2
  65. package/dist/esm/rate-limiter/createRateLimiter.js +4 -2
  66. package/dist/esm/rate-limiter/createRateLimiter.js.map +1 -1
  67. package/dist/esm/throttler/createThrottledSignal.d.ts +1 -5
  68. package/dist/esm/throttler/createThrottledSignal.js.map +1 -1
  69. package/dist/esm/throttler/createThrottledValue.d.ts +10 -14
  70. package/dist/esm/throttler/createThrottledValue.js +1 -4
  71. package/dist/esm/throttler/createThrottledValue.js.map +1 -1
  72. package/dist/esm/throttler/createThrottler.d.ts +2 -2
  73. package/dist/esm/throttler/createThrottler.js +8 -3
  74. package/dist/esm/throttler/createThrottler.js.map +1 -1
  75. package/package.json +2 -2
  76. package/src/async-debouncer/createAsyncDebouncer.ts +40 -24
  77. package/src/async-queuer/createAsyncQueuer.ts +6 -2
  78. package/src/async-rate-limiter/createAsyncRateLimiter.ts +34 -26
  79. package/src/async-throttler/createAsyncThrottler.ts +49 -24
  80. package/src/debouncer/createDebouncedSignal.ts +2 -6
  81. package/src/debouncer/createDebouncedValue.ts +7 -16
  82. package/src/debouncer/createDebouncer.ts +16 -15
  83. package/src/queuer/createQueuer.ts +7 -3
  84. package/src/rate-limiter/createRateLimitedSignal.ts +2 -6
  85. package/src/rate-limiter/createRateLimitedValue.ts +10 -21
  86. package/src/rate-limiter/createRateLimiter.ts +14 -15
  87. package/src/throttler/createThrottledSignal.ts +2 -6
  88. package/src/throttler/createThrottledValue.ts +12 -19
  89. package/src/throttler/createThrottler.ts +17 -16
@@ -1,9 +1,13 @@
1
1
  import { AsyncThrottler, AsyncThrottlerOptions } from '@tanstack/pacer/async-throttler';
2
2
  import { Accessor } from 'solid-js';
3
3
  import { AnyAsyncFunction } from '@tanstack/pacer/types';
4
- export interface SolidAsyncThrottler<TFn extends AnyAsyncFunction, TArgs extends Parameters<TFn>> extends Omit<AsyncThrottler<TFn, TArgs>, 'getExecutionCount' | 'getIsPending' | 'getLastExecutionTime' | 'getNextExecutionTime'> {
5
- executionCount: Accessor<number>;
4
+ export interface SolidAsyncThrottler<TFn extends AnyAsyncFunction> extends Omit<AsyncThrottler<TFn>, 'getSuccessCount' | 'getSettleCount' | 'getErrorCount' | 'getIsPending' | 'getIsExecuting' | 'getLastResult' | 'getLastExecutionTime' | 'getNextExecutionTime'> {
5
+ successCount: Accessor<number>;
6
+ settleCount: Accessor<number>;
7
+ errorCount: Accessor<number>;
6
8
  isPending: Accessor<boolean>;
9
+ isExecuting: Accessor<boolean>;
10
+ lastResult: Accessor<ReturnType<TFn> | undefined>;
7
11
  lastExecutionTime: Accessor<number>;
8
12
  nextExecutionTime: Accessor<number>;
9
13
  }
@@ -43,4 +47,4 @@ export interface SolidAsyncThrottler<TFn extends AnyAsyncFunction, TArgs extends
43
47
  * );
44
48
  * ```
45
49
  */
46
- export declare function createAsyncThrottler<TFn extends AnyAsyncFunction, TArgs extends Parameters<TFn>>(fn: TFn, initialOptions: AsyncThrottlerOptions<TFn, TArgs>): SolidAsyncThrottler<TFn, TArgs>;
50
+ export declare function createAsyncThrottler<TFn extends AnyAsyncFunction>(fn: TFn, initialOptions: AsyncThrottlerOptions<TFn>): SolidAsyncThrottler<TFn>;
@@ -2,11 +2,25 @@ import { AsyncThrottler } from "@tanstack/pacer/async-throttler";
2
2
  import { createSignal } from "solid-js";
3
3
  import { bindInstanceMethods } from "@tanstack/pacer/utils";
4
4
  function createAsyncThrottler(fn, initialOptions) {
5
- const asyncThrottler = new AsyncThrottler(fn, initialOptions);
6
- const [executionCount, setExecutionCount] = createSignal(
7
- asyncThrottler.getExecutionCount()
5
+ const asyncThrottler = bindInstanceMethods(
6
+ new AsyncThrottler(fn, initialOptions)
7
+ );
8
+ const [successCount, setSuccessCount] = createSignal(
9
+ asyncThrottler.getSuccessCount()
10
+ );
11
+ const [settleCount, setSettleCount] = createSignal(
12
+ asyncThrottler.getSettleCount()
13
+ );
14
+ const [errorCount, setErrorCount] = createSignal(
15
+ asyncThrottler.getErrorCount()
8
16
  );
9
17
  const [isPending, setIsPending] = createSignal(asyncThrottler.getIsPending());
18
+ const [isExecuting, setIsExecuting] = createSignal(
19
+ asyncThrottler.getIsExecuting()
20
+ );
21
+ const [lastResult, setLastResult] = createSignal(
22
+ asyncThrottler.getLastResult()
23
+ );
10
24
  const [lastExecutionTime, setLastExecutionTime] = createSignal(
11
25
  asyncThrottler.getLastExecutionTime()
12
26
  );
@@ -16,24 +30,32 @@ function createAsyncThrottler(fn, initialOptions) {
16
30
  function setOptions(newOptions) {
17
31
  asyncThrottler.setOptions({
18
32
  ...newOptions,
19
- onExecute: (throttler) => {
20
- setExecutionCount(throttler.getExecutionCount());
33
+ onSettled: (throttler) => {
34
+ setSuccessCount(throttler.getSuccessCount());
35
+ setSettleCount(throttler.getSettleCount());
36
+ setErrorCount(throttler.getErrorCount());
21
37
  setIsPending(throttler.getIsPending());
38
+ setIsExecuting(throttler.getIsExecuting());
22
39
  setLastExecutionTime(throttler.getLastExecutionTime());
23
40
  setNextExecutionTime(throttler.getNextExecutionTime());
24
- const onExecute = newOptions.onExecute ?? initialOptions.onExecute;
25
- onExecute == null ? void 0 : onExecute(throttler);
41
+ setLastResult(throttler.getLastResult());
42
+ const onSettled = newOptions.onSettled ?? initialOptions.onSettled;
43
+ onSettled == null ? void 0 : onSettled(throttler);
26
44
  }
27
45
  });
28
46
  }
29
47
  setOptions(initialOptions);
30
48
  return {
31
- ...bindInstanceMethods(asyncThrottler),
32
- executionCount,
49
+ ...asyncThrottler,
50
+ errorCount,
51
+ isExecuting,
33
52
  isPending,
34
53
  lastExecutionTime,
54
+ lastResult,
35
55
  nextExecutionTime,
36
- setOptions
56
+ setOptions,
57
+ settleCount,
58
+ successCount
37
59
  };
38
60
  }
39
61
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"createAsyncThrottler.js","sources":["../../../src/async-throttler/createAsyncThrottler.ts"],"sourcesContent":["import { AsyncThrottler } from '@tanstack/pacer/async-throttler'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type { AsyncThrottlerOptions } from '@tanstack/pacer/async-throttler'\n\nexport interface SolidAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TArgs extends Parameters<TFn>,\n> extends Omit<\n AsyncThrottler<TFn, TArgs>,\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 an `AsyncThrottler` instance to limit how often an async 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, etc).\n *\n * Async throttling ensures an async 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 expensive API calls,\n * database operations, or other async tasks.\n *\n * @example\n * ```tsx\n * // Basic API call throttling\n * const { maybeExecute } = createAsyncThrottler(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data;\n * },\n * { wait: 1000 }\n * );\n *\n * // With state management\n * const [data, setData] = createSignal(null);\n * const { maybeExecute } = createAsyncThrottler(\n * async (query) => {\n * const result = await searchAPI(query);\n * setData(result);\n * },\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false // Skip trailing edge updates\n * }\n * );\n * ```\n */\n\nexport function createAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TArgs extends Parameters<TFn>,\n>(\n fn: TFn,\n initialOptions: AsyncThrottlerOptions<TFn, TArgs>,\n): SolidAsyncThrottler<TFn, TArgs> {\n const asyncThrottler = new AsyncThrottler<TFn, TArgs>(fn, initialOptions)\n\n const [executionCount, setExecutionCount] = createSignal(\n asyncThrottler.getExecutionCount(),\n )\n const [isPending, setIsPending] = createSignal(asyncThrottler.getIsPending())\n const [lastExecutionTime, setLastExecutionTime] = createSignal(\n asyncThrottler.getLastExecutionTime(),\n )\n const [nextExecutionTime, setNextExecutionTime] = createSignal(\n asyncThrottler.getNextExecutionTime(),\n )\n\n function setOptions(newOptions: Partial<AsyncThrottlerOptions<TFn, TArgs>>) {\n asyncThrottler.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 return {\n ...bindInstanceMethods(asyncThrottler),\n executionCount,\n isPending,\n lastExecutionTime,\n nextExecutionTime,\n setOptions,\n }\n}\n"],"names":[],"mappings":";;;AA4DgB,SAAA,qBAId,IACA,gBACiC;AACjC,QAAM,iBAAiB,IAAI,eAA2B,IAAI,cAAc;AAElE,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,eAAe,kBAAkB;AAAA,EACnC;AACA,QAAM,CAAC,WAAW,YAAY,IAAI,aAAa,eAAe,cAAc;AACtE,QAAA,CAAC,mBAAmB,oBAAoB,IAAI;AAAA,IAChD,eAAe,qBAAqB;AAAA,EACtC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAI;AAAA,IAChD,eAAe,qBAAqB;AAAA,EACtC;AAEA,WAAS,WAAW,YAAwD;AAC1E,mBAAe,WAAW;AAAA,MACxB,GAAG;AAAA,MACH,WAAW,CAAC,cAAc;AACN,0BAAA,UAAU,mBAAmB;AAClC,qBAAA,UAAU,cAAc;AAChB,6BAAA,UAAU,sBAAsB;AAChC,6BAAA,UAAU,sBAAsB;AAE/C,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAY;AAAA,MAAS;AAAA,IACvB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAG,oBAAoB,cAAc;AAAA,IACrC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"createAsyncThrottler.js","sources":["../../../src/async-throttler/createAsyncThrottler.ts"],"sourcesContent":["import { AsyncThrottler } from '@tanstack/pacer/async-throttler'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type { AsyncThrottlerOptions } from '@tanstack/pacer/async-throttler'\n\nexport interface SolidAsyncThrottler<TFn extends AnyAsyncFunction>\n extends Omit<\n AsyncThrottler<TFn>,\n | 'getSuccessCount'\n | 'getSettleCount'\n | 'getErrorCount'\n | 'getIsPending'\n | 'getIsExecuting'\n | 'getLastResult'\n | 'getLastExecutionTime'\n | 'getNextExecutionTime'\n > {\n successCount: Accessor<number>\n settleCount: Accessor<number>\n errorCount: Accessor<number>\n isPending: Accessor<boolean>\n isExecuting: Accessor<boolean>\n lastResult: Accessor<ReturnType<TFn> | undefined>\n lastExecutionTime: Accessor<number>\n nextExecutionTime: Accessor<number>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncThrottler` instance to limit how often an async 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, etc).\n *\n * Async throttling ensures an async 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 expensive API calls,\n * database operations, or other async tasks.\n *\n * @example\n * ```tsx\n * // Basic API call throttling\n * const { maybeExecute } = createAsyncThrottler(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data;\n * },\n * { wait: 1000 }\n * );\n *\n * // With state management\n * const [data, setData] = createSignal(null);\n * const { maybeExecute } = createAsyncThrottler(\n * async (query) => {\n * const result = await searchAPI(query);\n * setData(result);\n * },\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false // Skip trailing edge updates\n * }\n * );\n * ```\n */\n\nexport function createAsyncThrottler<TFn extends AnyAsyncFunction>(\n fn: TFn,\n initialOptions: AsyncThrottlerOptions<TFn>,\n): SolidAsyncThrottler<TFn> {\n const asyncThrottler = bindInstanceMethods(\n new AsyncThrottler<TFn>(fn, initialOptions),\n )\n\n const [successCount, setSuccessCount] = createSignal(\n asyncThrottler.getSuccessCount(),\n )\n const [settleCount, setSettleCount] = createSignal(\n asyncThrottler.getSettleCount(),\n )\n const [errorCount, setErrorCount] = createSignal(\n asyncThrottler.getErrorCount(),\n )\n const [isPending, setIsPending] = createSignal(asyncThrottler.getIsPending())\n const [isExecuting, setIsExecuting] = createSignal(\n asyncThrottler.getIsExecuting(),\n )\n const [lastResult, setLastResult] = createSignal(\n asyncThrottler.getLastResult(),\n )\n const [lastExecutionTime, setLastExecutionTime] = createSignal(\n asyncThrottler.getLastExecutionTime(),\n )\n const [nextExecutionTime, setNextExecutionTime] = createSignal(\n asyncThrottler.getNextExecutionTime(),\n )\n\n function setOptions(newOptions: Partial<AsyncThrottlerOptions<TFn>>) {\n asyncThrottler.setOptions({\n ...newOptions,\n onSettled: (throttler) => {\n setSuccessCount(throttler.getSuccessCount())\n setSettleCount(throttler.getSettleCount())\n setErrorCount(throttler.getErrorCount())\n setIsPending(throttler.getIsPending())\n setIsExecuting(throttler.getIsExecuting())\n setLastExecutionTime(throttler.getLastExecutionTime())\n setNextExecutionTime(throttler.getNextExecutionTime())\n setLastResult(throttler.getLastResult())\n\n const onSettled = newOptions.onSettled ?? initialOptions.onSettled\n onSettled?.(throttler)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...asyncThrottler,\n errorCount,\n isExecuting,\n isPending,\n lastExecutionTime,\n lastResult,\n nextExecutionTime,\n setOptions,\n settleCount,\n successCount,\n } as SolidAsyncThrottler<TFn>\n}\n"],"names":[],"mappings":";;;AAkEgB,SAAA,qBACd,IACA,gBAC0B;AAC1B,QAAM,iBAAiB;AAAA,IACrB,IAAI,eAAoB,IAAI,cAAc;AAAA,EAC5C;AAEM,QAAA,CAAC,cAAc,eAAe,IAAI;AAAA,IACtC,eAAe,gBAAgB;AAAA,EACjC;AACM,QAAA,CAAC,aAAa,cAAc,IAAI;AAAA,IACpC,eAAe,eAAe;AAAA,EAChC;AACM,QAAA,CAAC,YAAY,aAAa,IAAI;AAAA,IAClC,eAAe,cAAc;AAAA,EAC/B;AACA,QAAM,CAAC,WAAW,YAAY,IAAI,aAAa,eAAe,cAAc;AACtE,QAAA,CAAC,aAAa,cAAc,IAAI;AAAA,IACpC,eAAe,eAAe;AAAA,EAChC;AACM,QAAA,CAAC,YAAY,aAAa,IAAI;AAAA,IAClC,eAAe,cAAc;AAAA,EAC/B;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAI;AAAA,IAChD,eAAe,qBAAqB;AAAA,EACtC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAI;AAAA,IAChD,eAAe,qBAAqB;AAAA,EACtC;AAEA,WAAS,WAAW,YAAiD;AACnE,mBAAe,WAAW;AAAA,MACxB,GAAG;AAAA,MACH,WAAW,CAAC,cAAc;AACR,wBAAA,UAAU,iBAAiB;AAC5B,uBAAA,UAAU,gBAAgB;AAC3B,sBAAA,UAAU,eAAe;AAC1B,qBAAA,UAAU,cAAc;AACtB,uBAAA,UAAU,gBAAgB;AACpB,6BAAA,UAAU,sBAAsB;AAChC,6BAAA,UAAU,sBAAsB;AACvC,sBAAA,UAAU,eAAe;AAEjC,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAY;AAAA,MAAS;AAAA,IACvB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
@@ -40,8 +40,4 @@ import { DebouncerOptions } from '@tanstack/pacer/debouncer';
40
40
  * });
41
41
  * ```
42
42
  */
43
- export declare function createDebouncedSignal<TValue>(value: TValue, initialOptions: DebouncerOptions<Setter<TValue>, [Accessor<TValue>]>): [
44
- Accessor<TValue>,
45
- Setter<TValue>,
46
- SolidDebouncer<Setter<TValue>, [Accessor<TValue>]>
47
- ];
43
+ export declare function createDebouncedSignal<TValue>(value: TValue, initialOptions: DebouncerOptions<Setter<TValue>>): [Accessor<TValue>, Setter<TValue>, SolidDebouncer<Setter<TValue>>];
@@ -1 +1 @@
1
- {"version":3,"file":"createDebouncedSignal.js","sources":["../../../src/debouncer/createDebouncedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createDebouncer } from './createDebouncer'\nimport type { SolidDebouncer } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { DebouncerOptions } from '@tanstack/pacer/debouncer'\n\n/**\n * A Solid hook that creates a debounced state value, combining Solid's createSignal with debouncing functionality.\n * This hook provides both the current debounced value and methods to update it.\n *\n * The state value is only updated after the specified wait time has elapsed since the last update attempt.\n * If another update is attempted before the wait time expires, the timer resets and starts waiting again.\n * This is useful for handling frequent state updates that should be throttled, like search input values\n * or window resize dimensions.\n *\n * The hook returns a tuple containing:\n * - The current debounced value accessor\n * - A function to update the debounced value\n * - The debouncer instance with additional control methods and state signals\n *\n * @example\n * ```tsx\n * // Debounced search input\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {\n * wait: 500 // Wait 500ms after last keystroke\n * });\n *\n * // Update value - will be debounced\n * const handleChange = (e) => {\n * setSearchTerm(e.target.value);\n * };\n *\n * // Access debouncer state via signals\n * console.log('Executions:', debouncer.executionCount());\n * console.log('Is pending:', debouncer.isPending());\n *\n * // In onExecute callback, use get* methods\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {\n * wait: 500,\n * onExecute: (debouncer) => {\n * console.log('Total executions:', debouncer.getExecutionCount());\n * }\n * });\n * ```\n */\nexport function createDebouncedSignal<TValue>(\n value: TValue,\n initialOptions: DebouncerOptions<Setter<TValue>, [Accessor<TValue>]>,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidDebouncer<Setter<TValue>, [Accessor<TValue>]>,\n] {\n const [debouncedValue, setDebouncedValue] = createSignal<TValue>(value)\n\n const debouncer = createDebouncer(setDebouncedValue, initialOptions)\n\n return [debouncedValue, debouncer.maybeExecute as Setter<TValue>, debouncer]\n}\n"],"names":[],"mappings":";;AA6CgB,SAAA,sBACd,OACA,gBAKA;AACA,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,aAAqB,KAAK;AAEhE,QAAA,YAAY,gBAAgB,mBAAmB,cAAc;AAEnE,SAAO,CAAC,gBAAgB,UAAU,cAAgC,SAAS;AAC7E;"}
1
+ {"version":3,"file":"createDebouncedSignal.js","sources":["../../../src/debouncer/createDebouncedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createDebouncer } from './createDebouncer'\nimport type { SolidDebouncer } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { DebouncerOptions } from '@tanstack/pacer/debouncer'\n\n/**\n * A Solid hook that creates a debounced state value, combining Solid's createSignal with debouncing functionality.\n * This hook provides both the current debounced value and methods to update it.\n *\n * The state value is only updated after the specified wait time has elapsed since the last update attempt.\n * If another update is attempted before the wait time expires, the timer resets and starts waiting again.\n * This is useful for handling frequent state updates that should be throttled, like search input values\n * or window resize dimensions.\n *\n * The hook returns a tuple containing:\n * - The current debounced value accessor\n * - A function to update the debounced value\n * - The debouncer instance with additional control methods and state signals\n *\n * @example\n * ```tsx\n * // Debounced search input\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {\n * wait: 500 // Wait 500ms after last keystroke\n * });\n *\n * // Update value - will be debounced\n * const handleChange = (e) => {\n * setSearchTerm(e.target.value);\n * };\n *\n * // Access debouncer state via signals\n * console.log('Executions:', debouncer.executionCount());\n * console.log('Is pending:', debouncer.isPending());\n *\n * // In onExecute callback, use get* methods\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {\n * wait: 500,\n * onExecute: (debouncer) => {\n * console.log('Total executions:', debouncer.getExecutionCount());\n * }\n * });\n * ```\n */\nexport function createDebouncedSignal<TValue>(\n value: TValue,\n initialOptions: DebouncerOptions<Setter<TValue>>,\n): [Accessor<TValue>, Setter<TValue>, SolidDebouncer<Setter<TValue>>] {\n const [debouncedValue, setDebouncedValue] = createSignal<TValue>(value)\n\n const debouncer = createDebouncer(setDebouncedValue, initialOptions)\n\n return [debouncedValue, debouncer.maybeExecute as Setter<TValue>, debouncer]\n}\n"],"names":[],"mappings":";;AA6CgB,SAAA,sBACd,OACA,gBACoE;AACpE,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,aAAqB,KAAK;AAEhE,QAAA,YAAY,gBAAgB,mBAAmB,cAAc;AAEnE,SAAO,CAAC,gBAAgB,UAAU,cAAgC,SAAS;AAC7E;"}
@@ -15,8 +15,8 @@ import { DebouncerOptions } from '@tanstack/pacer/debouncer';
15
15
  * or calculations occur.
16
16
  *
17
17
  * The hook returns a tuple containing:
18
- * - The current debounced value (as an Accessor)
19
- * - The debouncer instance with control methods and state signals
18
+ * - An Accessor that provides the current debounced value
19
+ * - The debouncer instance with control methods
20
20
  *
21
21
  * @example
22
22
  * ```tsx
@@ -31,14 +31,8 @@ import { DebouncerOptions } from '@tanstack/pacer/debouncer';
31
31
  * fetchSearchResults(debouncedQuery());
32
32
  * });
33
33
  *
34
- * // Access debouncer state via signals
35
- * console.log('Executions:', debouncer.executionCount());
36
- * console.log('Is pending:', debouncer.isPending());
37
- *
38
- * // Handle input changes
39
- * const handleChange = (e) => {
40
- * setSearchQuery(e.target.value);
41
- * };
34
+ * // Control the debouncer
35
+ * debouncer.cancel(); // Cancel any pending updates
42
36
  * ```
43
37
  */
44
- export declare function createDebouncedValue<TValue>(value: Accessor<TValue>, initialOptions: DebouncerOptions<Setter<TValue>, [Accessor<TValue>]>): [Accessor<TValue>, SolidDebouncer<Setter<TValue>, [Accessor<TValue>]>];
38
+ export declare function createDebouncedValue<TValue>(value: Accessor<TValue>, initialOptions: DebouncerOptions<Setter<TValue>>): [Accessor<TValue>, SolidDebouncer<Setter<TValue>>];
@@ -1,4 +1,4 @@
1
- import { createEffect, onCleanup } from "solid-js";
1
+ import { createEffect } from "solid-js";
2
2
  import { createDebouncedSignal } from "./createDebouncedSignal.js";
3
3
  function createDebouncedValue(value, initialOptions) {
4
4
  const [debouncedValue, setDebouncedValue, debouncer] = createDebouncedSignal(
@@ -7,9 +7,6 @@ function createDebouncedValue(value, initialOptions) {
7
7
  );
8
8
  createEffect(() => {
9
9
  setDebouncedValue(value());
10
- onCleanup(() => {
11
- debouncer.cancel();
12
- });
13
10
  });
14
11
  return [debouncedValue, debouncer];
15
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"createDebouncedValue.js","sources":["../../../src/debouncer/createDebouncedValue.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { createDebouncedSignal } from './createDebouncedSignal'\nimport type { SolidDebouncer } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { DebouncerOptions } from '@tanstack/pacer/debouncer'\n\n/**\n * A Solid hook that creates a debounced value that updates only after a specified delay.\n * Unlike createDebouncedSignal, this hook automatically tracks changes to the input value\n * and updates the debounced value accordingly.\n *\n * The debounced value will only update after the specified wait time has elapsed since\n * the last change to the input value. If the input value changes again before the wait\n * time expires, the timer resets and starts waiting again.\n *\n * This is useful for deriving debounced values from props or state that change frequently,\n * like search queries or form inputs, where you want to limit how often downstream effects\n * or calculations occur.\n *\n * The hook returns a tuple containing:\n * - The current debounced value (as an Accessor)\n * - The debouncer instance with control methods and state signals\n *\n * @example\n * ```tsx\n * // Debounce a search query\n * const [searchQuery, setSearchQuery] = createSignal('');\n * const [debouncedQuery, debouncer] = createDebouncedValue(searchQuery, {\n * wait: 500 // Wait 500ms after last change\n * });\n *\n * // debouncedQuery will update 500ms after searchQuery stops changing\n * createEffect(() => {\n * fetchSearchResults(debouncedQuery());\n * });\n *\n * // Access debouncer state via signals\n * console.log('Executions:', debouncer.executionCount());\n * console.log('Is pending:', debouncer.isPending());\n *\n * // Handle input changes\n * const handleChange = (e) => {\n * setSearchQuery(e.target.value);\n * };\n * ```\n */\nexport function createDebouncedValue<TValue>(\n value: Accessor<TValue>,\n initialOptions: DebouncerOptions<Setter<TValue>, [Accessor<TValue>]>,\n): [Accessor<TValue>, SolidDebouncer<Setter<TValue>, [Accessor<TValue>]>] {\n const [debouncedValue, setDebouncedValue, debouncer] = createDebouncedSignal(\n value(),\n initialOptions,\n )\n\n createEffect(() => {\n setDebouncedValue(value() as any)\n onCleanup(() => {\n debouncer.cancel()\n })\n })\n\n return [debouncedValue, debouncer]\n}\n"],"names":[],"mappings":";;AA8CgB,SAAA,qBACd,OACA,gBACwE;AACxE,QAAM,CAAC,gBAAgB,mBAAmB,SAAS,IAAI;AAAA,IACrD,MAAM;AAAA,IACN;AAAA,EACF;AAEA,eAAa,MAAM;AACjB,sBAAkB,OAAc;AAChC,cAAU,MAAM;AACd,gBAAU,OAAO;AAAA,IAAA,CAClB;AAAA,EAAA,CACF;AAEM,SAAA,CAAC,gBAAgB,SAAS;AACnC;"}
1
+ {"version":3,"file":"createDebouncedValue.js","sources":["../../../src/debouncer/createDebouncedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createDebouncedSignal } from './createDebouncedSignal'\nimport type { SolidDebouncer } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { DebouncerOptions } from '@tanstack/pacer/debouncer'\n\n/**\n * A Solid hook that creates a debounced value that updates only after a specified delay.\n * Unlike createDebouncedSignal, this hook automatically tracks changes to the input value\n * and updates the debounced value accordingly.\n *\n * The debounced value will only update after the specified wait time has elapsed since\n * the last change to the input value. If the input value changes again before the wait\n * time expires, the timer resets and starts waiting again.\n *\n * This is useful for deriving debounced values from props or state that change frequently,\n * like search queries or form inputs, where you want to limit how often downstream effects\n * or calculations occur.\n *\n * The hook returns a tuple containing:\n * - An Accessor that provides the current debounced value\n * - The debouncer instance with control methods\n *\n * @example\n * ```tsx\n * // Debounce a search query\n * const [searchQuery, setSearchQuery] = createSignal('');\n * const [debouncedQuery, debouncer] = createDebouncedValue(searchQuery, {\n * wait: 500 // Wait 500ms after last change\n * });\n *\n * // debouncedQuery will update 500ms after searchQuery stops changing\n * createEffect(() => {\n * fetchSearchResults(debouncedQuery());\n * });\n *\n * // Control the debouncer\n * debouncer.cancel(); // Cancel any pending updates\n * ```\n */\nexport function createDebouncedValue<TValue>(\n value: Accessor<TValue>,\n initialOptions: DebouncerOptions<Setter<TValue>>,\n): [Accessor<TValue>, SolidDebouncer<Setter<TValue>>] {\n const [debouncedValue, setDebouncedValue, debouncer] = createDebouncedSignal(\n value(),\n initialOptions,\n )\n\n createEffect(() => {\n setDebouncedValue(value() as any)\n })\n\n return [debouncedValue, debouncer]\n}\n"],"names":[],"mappings":";;AAwCgB,SAAA,qBACd,OACA,gBACoD;AACpD,QAAM,CAAC,gBAAgB,mBAAmB,SAAS,IAAI;AAAA,IACrD,MAAM;AAAA,IACN;AAAA,EACF;AAEA,eAAa,MAAM;AACjB,sBAAkB,OAAc;AAAA,EAAA,CACjC;AAEM,SAAA,CAAC,gBAAgB,SAAS;AACnC;"}
@@ -4,7 +4,7 @@ import { AnyFunction } from '@tanstack/pacer/types';
4
4
  /**
5
5
  * An extension of the Debouncer class that adds Solid signals to access the internal state of the debouncer
6
6
  */
7
- export interface SolidDebouncer<TFn extends AnyFunction, TArgs extends Parameters<TFn>> extends Omit<Debouncer<TFn, TArgs>, 'getExecutionCount' | 'getIsPending'> {
7
+ export interface SolidDebouncer<TFn extends AnyFunction> extends Omit<Debouncer<TFn>, 'getExecutionCount' | 'getIsPending'> {
8
8
  executionCount: Accessor<number>;
9
9
  isPending: Accessor<boolean>;
10
10
  }
@@ -44,4 +44,4 @@ export interface SolidDebouncer<TFn extends AnyFunction, TArgs extends Parameter
44
44
  * debouncer.setOptions({ wait: 1000 });
45
45
  * ```
46
46
  */
47
- export declare function createDebouncer<TFn extends AnyFunction, TArgs extends Parameters<TFn>>(fn: TFn, initialOptions: DebouncerOptions<TFn, TArgs>): SolidDebouncer<TFn, TArgs>;
47
+ export declare function createDebouncer<TFn extends AnyFunction>(fn: TFn, initialOptions: DebouncerOptions<TFn>): SolidDebouncer<TFn>;
@@ -1,8 +1,8 @@
1
1
  import { Debouncer } from "@tanstack/pacer/debouncer";
2
- import { createSignal } from "solid-js";
2
+ import { createSignal, createEffect, onCleanup } from "solid-js";
3
3
  import { bindInstanceMethods } from "@tanstack/pacer/utils";
4
4
  function createDebouncer(fn, initialOptions) {
5
- const debouncer = new Debouncer(fn, initialOptions);
5
+ const debouncer = bindInstanceMethods(new Debouncer(fn, initialOptions));
6
6
  const [executionCount, setExecutionCount] = createSignal(
7
7
  debouncer.getExecutionCount()
8
8
  );
@@ -19,8 +19,13 @@ function createDebouncer(fn, initialOptions) {
19
19
  });
20
20
  }
21
21
  setOptions(initialOptions);
22
+ createEffect(() => {
23
+ onCleanup(() => {
24
+ debouncer.cancel();
25
+ });
26
+ });
22
27
  return {
23
- ...bindInstanceMethods(debouncer),
28
+ ...debouncer,
24
29
  executionCount,
25
30
  isPending,
26
31
  setOptions
@@ -1 +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;"}
1
+ {"version":3,"file":"createDebouncer.js","sources":["../../../src/debouncer/createDebouncer.ts"],"sourcesContent":["import { Debouncer } from '@tanstack/pacer/debouncer'\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 { 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<TFn extends AnyFunction>\n extends Omit<Debouncer<TFn>, '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<TFn extends AnyFunction>(\n fn: TFn,\n initialOptions: DebouncerOptions<TFn>,\n): SolidDebouncer<TFn> {\n const debouncer = bindInstanceMethods(new Debouncer<TFn>(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>>) {\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 createEffect(() => {\n onCleanup(() => {\n debouncer.cancel()\n })\n })\n\n return {\n ...debouncer,\n executionCount,\n isPending,\n setOptions,\n } as SolidDebouncer<TFn>\n}\n"],"names":["debouncer"],"mappings":";;;AAoDgB,SAAA,gBACd,IACA,gBACqB;AACrB,QAAM,YAAY,oBAAoB,IAAI,UAAe,IAAI,cAAc,CAAC;AAEtE,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,UAAU,kBAAkB;AAAA,EAC9B;AACA,QAAM,CAAC,WAAW,YAAY,IAAI,aAAa,UAAU,cAAc;AAEvE,WAAS,WAAW,YAA4C;AAC9D,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;AAEzB,eAAa,MAAM;AACjB,cAAU,MAAM;AACd,gBAAU,OAAO;AAAA,IAAA,CAClB;AAAA,EAAA,CACF;AAEM,SAAA;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
@@ -29,6 +29,10 @@ export interface SolidQueuer<TValue> extends Omit<Queuer<TValue>, 'getAllItems'
29
29
  * Signal version of `getPeek`
30
30
  */
31
31
  peek: Accessor<TValue | undefined>;
32
+ /**
33
+ * Signal version of `getRejectionCount`
34
+ */
35
+ rejectionCount: Accessor<number>;
32
36
  /**
33
37
  * Signal version of `getSize`
34
38
  */
@@ -2,7 +2,7 @@ import { Queuer } from "@tanstack/pacer/queuer";
2
2
  import { createSignal } from "solid-js";
3
3
  import { bindInstanceMethods } from "@tanstack/pacer/utils";
4
4
  function createQueuer(initialOptions = {}) {
5
- const queuer = new Queuer(initialOptions);
5
+ const queuer = bindInstanceMethods(new Queuer(initialOptions));
6
6
  const [allItems, setAllItems] = createSignal(
7
7
  queuer.getAllItems()
8
8
  );
@@ -47,7 +47,7 @@ function createQueuer(initialOptions = {}) {
47
47
  }
48
48
  setOptions(initialOptions);
49
49
  return {
50
- ...bindInstanceMethods(queuer),
50
+ ...queuer,
51
51
  allItems,
52
52
  executionCount,
53
53
  isEmpty,
@@ -1 +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;"}
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 `getRejectionCount`\n */\n rejectionCount: Accessor<number>\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 = bindInstanceMethods(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 ...queuer,\n allItems,\n executionCount,\n isEmpty,\n isFull,\n isIdle,\n isRunning,\n peek,\n rejectionCount,\n size,\n setOptions,\n } as SolidQueuer<TValue>\n}\n"],"names":["queuer"],"mappings":";;;AAqGgB,SAAA,aACd,iBAAwC,IACnB;AACrB,QAAM,SAAS,oBAAoB,IAAI,OAAe,cAAc,CAAC;AAE/D,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;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
@@ -51,8 +51,4 @@ import { RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
51
51
  * };
52
52
  * ```
53
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
- ];
54
+ export declare function createRateLimitedSignal<TValue>(value: TValue, initialOptions: RateLimiterOptions<Setter<TValue>>): [Accessor<TValue>, Setter<TValue>, SolidRateLimiter<Setter<TValue>>];
@@ -1 +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;"}
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>>,\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":[],"mappings":";;AAwDgB,SAAA,wBACd,OACA,gBACsE;AACtE,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;"}
@@ -15,7 +15,9 @@ import { RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
15
15
  *
16
16
  * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.
17
17
  *
18
- * The hook returns both the rate-limited value and the underlying rateLimiter instance for additional control.
18
+ * The hook returns a tuple containing:
19
+ * - An accessor function that provides the rate-limited value
20
+ * - The rate limiter instance with control methods
19
21
  *
20
22
  * For more direct control over rate limiting behavior without Solid state management,
21
23
  * consider using the lower-level createRateLimiter hook instead.
@@ -23,29 +25,16 @@ import { RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
23
25
  * @example
24
26
  * ```tsx
25
27
  * // Basic rate limiting - update at most 5 times per minute
26
- * const [rateLimitedValue] = createRateLimitedValue(rawValue, {
28
+ * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
27
29
  * limit: 5,
28
30
  * window: 60000
29
31
  * });
30
32
  *
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
- * });
33
+ * // Use the rate-limited value
34
+ * console.log(rateLimitedValue()); // Access the current rate-limited value
39
35
  *
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
- * };
36
+ * // Control the rate limiter
37
+ * rateLimiter.reset(); // Reset the rate limit window
49
38
  * ```
50
39
  */
51
- export declare function createRateLimitedValue<TValue>(value: Accessor<TValue>, initialOptions: RateLimiterOptions<Setter<TValue>, [Accessor<TValue>]>): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, [Accessor<TValue>]>];
40
+ export declare function createRateLimitedValue<TValue>(value: Accessor<TValue>, initialOptions: RateLimiterOptions<Setter<TValue>>): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>>];
@@ -1 +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;"}
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 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\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000\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":[],"mappings":";;AA0CgB,SAAA,uBACd,OACA,gBACsD;AAChD,QAAA,CAAC,kBAAkB,qBAAqB,WAAW,IACvD,wBAAwB,SAAS,cAAc;AAEjD,eAAa,MAAM;AACjB,wBAAoB,OAAc;AAAA,EAAA,CACnC;AAEM,SAAA,CAAC,kBAAkB,WAAW;AACvC;"}
@@ -1,7 +1,7 @@
1
1
  import { RateLimiter, RateLimiterOptions } 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, TArgs extends Parameters<TFn>> extends Omit<RateLimiter<TFn, TArgs>, 'getExecutionCount' | 'getMsUntilNextWindow' | 'getRejectionCount' | 'getRemainingInWindow'> {
4
+ export interface SolidRateLimiter<TFn extends AnyFunction> extends Omit<RateLimiter<TFn>, 'getExecutionCount' | 'getMsUntilNextWindow' | 'getRejectionCount' | 'getRemainingInWindow'> {
5
5
  executionCount: Accessor<number>;
6
6
  msUntilNextWindow: Accessor<number>;
7
7
  rejectionCount: Accessor<number>;
@@ -46,4 +46,4 @@ export interface SolidRateLimiter<TFn extends AnyFunction, TArgs extends Paramet
46
46
  * console.log('Next window in:', rateLimiter.msUntilNextWindow());
47
47
  * ```
48
48
  */
49
- export declare function createRateLimiter<TFn extends AnyFunction, TArgs extends Parameters<TFn>>(fn: TFn, initialOptions: RateLimiterOptions<TFn, TArgs>): SolidRateLimiter<TFn, TArgs>;
49
+ export declare function createRateLimiter<TFn extends AnyFunction>(fn: TFn, initialOptions: RateLimiterOptions<TFn>): SolidRateLimiter<TFn>;
@@ -2,7 +2,9 @@ import { RateLimiter } from "@tanstack/pacer/rate-limiter";
2
2
  import { createSignal } from "solid-js";
3
3
  import { bindInstanceMethods } from "@tanstack/pacer/utils";
4
4
  function createRateLimiter(fn, initialOptions) {
5
- const rateLimiter = new RateLimiter(fn, initialOptions);
5
+ const rateLimiter = bindInstanceMethods(
6
+ new RateLimiter(fn, initialOptions)
7
+ );
6
8
  const [executionCount, setExecutionCount] = createSignal(
7
9
  rateLimiter.getExecutionCount()
8
10
  );
@@ -36,7 +38,7 @@ function createRateLimiter(fn, initialOptions) {
36
38
  }
37
39
  setOptions(initialOptions);
38
40
  return {
39
- ...bindInstanceMethods(rateLimiter),
41
+ ...rateLimiter,
40
42
  executionCount,
41
43
  rejectionCount,
42
44
  remainingInWindow,
@@ -1 +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;"}
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<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 * 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<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"],"mappings":";;;AA4DgB,SAAA,kBACd,IACA,gBACuB;AACvB,QAAM,cAAc;AAAA,IAClB,IAAI,YAAiB,IAAI,cAAc;AAAA,EACzC;AAEM,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,YAA8C;AAChE,gBAAY,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,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
@@ -35,8 +35,4 @@ 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>]>): [
39
- Accessor<TValue>,
40
- Setter<TValue>,
41
- SolidThrottler<Setter<TValue>, [Accessor<TValue>]>
42
- ];
38
+ export declare function createThrottledSignal<TValue>(value: TValue, initialOptions: ThrottlerOptions<Setter<TValue>>): [Accessor<TValue>, Setter<TValue>, SolidThrottler<Setter<TValue>>];
@@ -1 +1 @@
1
- {"version":3,"file":"createThrottledSignal.js","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>, [Accessor<TValue>]>,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidThrottler<Setter<TValue>, [Accessor<TValue>]>,\n] {\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":[],"mappings":";;AAwCgB,SAAA,sBACd,OACA,gBAKA;AACA,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,aAAqB,KAAK;AAChE,QAAA,YAAY,gBAAgB,mBAAmB,cAAc;AACnE,SAAO,CAAC,gBAAgB,UAAU,cAAgC,SAAS;AAC7E;"}
1
+ {"version":3,"file":"createThrottledSignal.js","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":[],"mappings":";;AAwCgB,SAAA,sBACd,OACA,gBACoE;AACpE,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,aAAqB,KAAK;AAChE,QAAA,YAAY,gBAAgB,mBAAmB,cAAc;AACnE,SAAO,CAAC,gBAAgB,UAAU,cAAgC,SAAS;AAC7E;"}
@@ -8,7 +8,10 @@ import { ThrottlerOptions } from '@tanstack/pacer/throttler';
8
8
  * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.
9
9
  * This is useful for rate-limiting expensive re-renders or API calls that depend on rapidly changing values.
10
10
  *
11
- * The hook returns both the throttled value and the underlying throttler instance for additional control.
11
+ * The hook returns a tuple containing:
12
+ * - An accessor function that provides the throttled value
13
+ * - The throttler instance with control methods
14
+ *
12
15
  * The throttled value will update according to the leading/trailing edge behavior specified in the options.
13
16
  *
14
17
  * For more direct control over throttling behavior without Solid state management,
@@ -17,20 +20,13 @@ import { ThrottlerOptions } from '@tanstack/pacer/throttler';
17
20
  * @example
18
21
  * ```tsx
19
22
  * // Basic throttling - update at most once per second
20
- * const [throttledValue] = createThrottledValue(rawValue, { wait: 1000 });
23
+ * const [throttledValue, throttler] = createThrottledValue(rawValue, { wait: 1000 });
21
24
  *
22
- * // With custom leading/trailing behavior
23
- * const [throttledValue, throttler] = createThrottledValue(rawValue, {
24
- * wait: 1000,
25
- * leading: true, // Update immediately on first change
26
- * trailing: false // Skip trailing edge updates
27
- * });
25
+ * // Use the throttled value
26
+ * console.log(throttledValue()); // Access the current throttled value
28
27
  *
29
- * // Access throttler state via signals
30
- * console.log('Executions:', throttler.executionCount());
31
- * console.log('Is pending:', throttler.isPending());
32
- * console.log('Last execution:', throttler.lastExecutionTime());
33
- * console.log('Next execution:', throttler.nextExecutionTime());
28
+ * // Control the throttler
29
+ * throttler.cancel(); // Cancel any pending updates
34
30
  * ```
35
31
  */
36
- export declare function createThrottledValue<TValue>(value: Accessor<TValue>, initialOptions: ThrottlerOptions<Setter<TValue>, [Accessor<TValue>]>): [Accessor<TValue>, SolidThrottler<Setter<TValue>, [Accessor<TValue>]>];
32
+ export declare function createThrottledValue<TValue>(value: Accessor<TValue>, initialOptions: ThrottlerOptions<Setter<TValue>>): [Accessor<TValue>, SolidThrottler<Setter<TValue>>];
@@ -1,4 +1,4 @@
1
- import { createEffect, onCleanup } from "solid-js";
1
+ import { createEffect } from "solid-js";
2
2
  import { createThrottledSignal } from "./createThrottledSignal.js";
3
3
  function createThrottledValue(value, initialOptions) {
4
4
  const [throttledValue, setThrottledValue, throttler] = createThrottledSignal(
@@ -7,9 +7,6 @@ function createThrottledValue(value, initialOptions) {
7
7
  );
8
8
  createEffect(() => {
9
9
  setThrottledValue(value());
10
- onCleanup(() => {
11
- throttler.cancel();
12
- });
13
10
  });
14
11
  return [throttledValue, throttler];
15
12
  }