@tanstack/solid-pacer 0.15.2 → 0.16.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 (105) hide show
  1. package/README.md +165 -0
  2. package/dist/cjs/async-batcher/createAsyncBatcher.cjs +7 -2
  3. package/dist/cjs/async-batcher/createAsyncBatcher.cjs.map +1 -1
  4. package/dist/cjs/async-batcher/createAsyncBatcher.d.cts +1 -1
  5. package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs +7 -2
  6. package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs.map +1 -1
  7. package/dist/cjs/async-debouncer/createAsyncDebouncer.d.cts +1 -1
  8. package/dist/cjs/async-queuer/createAsyncQueuer.cjs +7 -2
  9. package/dist/cjs/async-queuer/createAsyncQueuer.cjs.map +1 -1
  10. package/dist/cjs/async-queuer/createAsyncQueuer.d.cts +1 -1
  11. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs +7 -2
  12. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs.map +1 -1
  13. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.d.cts +1 -1
  14. package/dist/cjs/async-throttler/createAsyncThrottler.cjs +7 -2
  15. package/dist/cjs/async-throttler/createAsyncThrottler.cjs.map +1 -1
  16. package/dist/cjs/async-throttler/createAsyncThrottler.d.cts +1 -1
  17. package/dist/cjs/batcher/createBatcher.cjs +7 -2
  18. package/dist/cjs/batcher/createBatcher.cjs.map +1 -1
  19. package/dist/cjs/batcher/createBatcher.d.cts +1 -1
  20. package/dist/cjs/debouncer/createDebouncer.cjs +7 -2
  21. package/dist/cjs/debouncer/createDebouncer.cjs.map +1 -1
  22. package/dist/cjs/debouncer/createDebouncer.d.cts +1 -1
  23. package/dist/cjs/index.cjs +6 -0
  24. package/dist/cjs/index.cjs.map +1 -1
  25. package/dist/cjs/index.d.cts +2 -0
  26. package/dist/cjs/provider/PacerProvider.cjs +28 -0
  27. package/dist/cjs/provider/PacerProvider.cjs.map +1 -0
  28. package/dist/cjs/provider/PacerProvider.d.cts +25 -0
  29. package/dist/cjs/queuer/createQueuedSignal.cjs +9 -0
  30. package/dist/cjs/queuer/createQueuedSignal.cjs.map +1 -0
  31. package/dist/cjs/queuer/createQueuedSignal.d.cts +121 -0
  32. package/dist/cjs/queuer/createQueuer.cjs +7 -2
  33. package/dist/cjs/queuer/createQueuer.cjs.map +1 -1
  34. package/dist/cjs/queuer/createQueuer.d.cts +1 -1
  35. package/dist/cjs/queuer/index.cjs +2 -0
  36. package/dist/cjs/queuer/index.cjs.map +1 -1
  37. package/dist/cjs/queuer/index.d.cts +1 -0
  38. package/dist/cjs/rate-limiter/createRateLimitedValue.cjs.map +1 -1
  39. package/dist/cjs/rate-limiter/createRateLimitedValue.d.cts +30 -16
  40. package/dist/cjs/rate-limiter/createRateLimiter.cjs +7 -2
  41. package/dist/cjs/rate-limiter/createRateLimiter.cjs.map +1 -1
  42. package/dist/cjs/rate-limiter/createRateLimiter.d.cts +1 -1
  43. package/dist/cjs/throttler/createThrottler.cjs +7 -2
  44. package/dist/cjs/throttler/createThrottler.cjs.map +1 -1
  45. package/dist/cjs/throttler/createThrottler.d.cts +1 -1
  46. package/dist/esm/async-batcher/createAsyncBatcher.d.ts +1 -1
  47. package/dist/esm/async-batcher/createAsyncBatcher.js +7 -2
  48. package/dist/esm/async-batcher/createAsyncBatcher.js.map +1 -1
  49. package/dist/esm/async-debouncer/createAsyncDebouncer.d.ts +1 -1
  50. package/dist/esm/async-debouncer/createAsyncDebouncer.js +7 -2
  51. package/dist/esm/async-debouncer/createAsyncDebouncer.js.map +1 -1
  52. package/dist/esm/async-queuer/createAsyncQueuer.d.ts +1 -1
  53. package/dist/esm/async-queuer/createAsyncQueuer.js +7 -2
  54. package/dist/esm/async-queuer/createAsyncQueuer.js.map +1 -1
  55. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.d.ts +1 -1
  56. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js +7 -2
  57. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js.map +1 -1
  58. package/dist/esm/async-throttler/createAsyncThrottler.d.ts +1 -1
  59. package/dist/esm/async-throttler/createAsyncThrottler.js +7 -2
  60. package/dist/esm/async-throttler/createAsyncThrottler.js.map +1 -1
  61. package/dist/esm/batcher/createBatcher.d.ts +1 -1
  62. package/dist/esm/batcher/createBatcher.js +7 -2
  63. package/dist/esm/batcher/createBatcher.js.map +1 -1
  64. package/dist/esm/debouncer/createDebouncer.d.ts +1 -1
  65. package/dist/esm/debouncer/createDebouncer.js +7 -2
  66. package/dist/esm/debouncer/createDebouncer.js.map +1 -1
  67. package/dist/esm/index.d.ts +2 -0
  68. package/dist/esm/index.js +7 -1
  69. package/dist/esm/index.js.map +1 -1
  70. package/dist/esm/provider/PacerProvider.d.ts +25 -0
  71. package/dist/esm/provider/PacerProvider.js +28 -0
  72. package/dist/esm/provider/PacerProvider.js.map +1 -0
  73. package/dist/esm/queuer/createQueuedSignal.d.ts +121 -0
  74. package/dist/esm/queuer/createQueuedSignal.js +9 -0
  75. package/dist/esm/queuer/createQueuedSignal.js.map +1 -0
  76. package/dist/esm/queuer/createQueuer.d.ts +1 -1
  77. package/dist/esm/queuer/createQueuer.js +7 -2
  78. package/dist/esm/queuer/createQueuer.js.map +1 -1
  79. package/dist/esm/queuer/index.d.ts +1 -0
  80. package/dist/esm/queuer/index.js +2 -0
  81. package/dist/esm/queuer/index.js.map +1 -1
  82. package/dist/esm/rate-limiter/createRateLimitedValue.d.ts +30 -16
  83. package/dist/esm/rate-limiter/createRateLimitedValue.js.map +1 -1
  84. package/dist/esm/rate-limiter/createRateLimiter.d.ts +1 -1
  85. package/dist/esm/rate-limiter/createRateLimiter.js +7 -2
  86. package/dist/esm/rate-limiter/createRateLimiter.js.map +1 -1
  87. package/dist/esm/throttler/createThrottler.d.ts +1 -1
  88. package/dist/esm/throttler/createThrottler.js +7 -2
  89. package/dist/esm/throttler/createThrottler.js.map +1 -1
  90. package/package.json +2 -2
  91. package/src/async-batcher/createAsyncBatcher.ts +8 -2
  92. package/src/async-debouncer/createAsyncDebouncer.ts +8 -2
  93. package/src/async-queuer/createAsyncQueuer.ts +8 -2
  94. package/src/async-rate-limiter/createAsyncRateLimiter.ts +8 -2
  95. package/src/async-throttler/createAsyncThrottler.ts +8 -2
  96. package/src/batcher/createBatcher.ts +8 -2
  97. package/src/debouncer/createDebouncer.ts +8 -2
  98. package/src/index.ts +4 -0
  99. package/src/provider/PacerProvider.tsx +63 -0
  100. package/src/queuer/createQueuedSignal.ts +138 -0
  101. package/src/queuer/createQueuer.ts +8 -2
  102. package/src/queuer/index.ts +1 -0
  103. package/src/rate-limiter/createRateLimitedValue.ts +30 -16
  104. package/src/rate-limiter/createRateLimiter.ts +8 -2
  105. package/src/throttler/createThrottler.ts +8 -2
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const pacer = require("@tanstack/pacer");
4
+ const PacerProvider = require("./provider/PacerProvider.cjs");
4
5
  const createAsyncBatcher = require("./async-batcher/createAsyncBatcher.cjs");
5
6
  const createAsyncDebouncer = require("./async-debouncer/createAsyncDebouncer.cjs");
6
7
  const createAsyncQueuer = require("./async-queuer/createAsyncQueuer.cjs");
@@ -11,12 +12,16 @@ const createDebouncedSignal = require("./debouncer/createDebouncedSignal.cjs");
11
12
  const createDebouncedValue = require("./debouncer/createDebouncedValue.cjs");
12
13
  const createDebouncer = require("./debouncer/createDebouncer.cjs");
13
14
  const createQueuer = require("./queuer/createQueuer.cjs");
15
+ const createQueuedSignal = require("./queuer/createQueuedSignal.cjs");
14
16
  const createRateLimiter = require("./rate-limiter/createRateLimiter.cjs");
15
17
  const createRateLimitedSignal = require("./rate-limiter/createRateLimitedSignal.cjs");
16
18
  const createRateLimitedValue = require("./rate-limiter/createRateLimitedValue.cjs");
17
19
  const createThrottledSignal = require("./throttler/createThrottledSignal.cjs");
18
20
  const createThrottledValue = require("./throttler/createThrottledValue.cjs");
19
21
  const createThrottler = require("./throttler/createThrottler.cjs");
22
+ exports.PacerProvider = PacerProvider.PacerProvider;
23
+ exports.useDefaultPacerOptions = PacerProvider.useDefaultPacerOptions;
24
+ exports.usePacerContext = PacerProvider.usePacerContext;
20
25
  exports.createAsyncBatcher = createAsyncBatcher.createAsyncBatcher;
21
26
  exports.createAsyncDebouncer = createAsyncDebouncer.createAsyncDebouncer;
22
27
  exports.createAsyncQueuer = createAsyncQueuer.createAsyncQueuer;
@@ -27,6 +32,7 @@ exports.createDebouncedSignal = createDebouncedSignal.createDebouncedSignal;
27
32
  exports.createDebouncedValue = createDebouncedValue.createDebouncedValue;
28
33
  exports.createDebouncer = createDebouncer.createDebouncer;
29
34
  exports.createQueuer = createQueuer.createQueuer;
35
+ exports.createQueuedSignal = createQueuedSignal.createQueuedSignal;
30
36
  exports.createRateLimiter = createRateLimiter.createRateLimiter;
31
37
  exports.createRateLimitedSignal = createRateLimitedSignal.createRateLimitedSignal;
32
38
  exports.createRateLimitedValue = createRateLimitedValue.createRateLimitedValue;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,4 +1,5 @@
1
1
  export * from '@tanstack/pacer';
2
+ export * from './provider/PacerProvider.cjs';
2
3
  /**
3
4
  * Export every hook individually - DON'T export from barrel files
4
5
  */
@@ -12,6 +13,7 @@ export * from './debouncer/createDebouncedSignal.cjs';
12
13
  export * from './debouncer/createDebouncedValue.cjs';
13
14
  export * from './debouncer/createDebouncer.cjs';
14
15
  export * from './queuer/createQueuer.cjs';
16
+ export * from './queuer/createQueuedSignal.cjs';
15
17
  export * from './rate-limiter/createRateLimiter.cjs';
16
18
  export * from './rate-limiter/createRateLimitedSignal.cjs';
17
19
  export * from './rate-limiter/createRateLimitedValue.cjs';
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const web = require("solid-js/web");
4
+ const solidJs = require("solid-js");
5
+ const PacerContext = solidJs.createContext(null);
6
+ const DEFAULT_OPTIONS = {};
7
+ function PacerProvider(props) {
8
+ const contextValue = {
9
+ defaultOptions: props.defaultOptions ?? DEFAULT_OPTIONS
10
+ };
11
+ return web.createComponent(PacerContext.Provider, {
12
+ value: contextValue,
13
+ get children() {
14
+ return props.children;
15
+ }
16
+ });
17
+ }
18
+ function usePacerContext() {
19
+ return solidJs.useContext(PacerContext);
20
+ }
21
+ function useDefaultPacerOptions() {
22
+ const context = solidJs.useContext(PacerContext);
23
+ return context?.defaultOptions ?? {};
24
+ }
25
+ exports.PacerProvider = PacerProvider;
26
+ exports.useDefaultPacerOptions = useDefaultPacerOptions;
27
+ exports.usePacerContext = usePacerContext;
28
+ //# sourceMappingURL=PacerProvider.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PacerProvider.cjs","sources":["../../../src/provider/PacerProvider.tsx"],"sourcesContent":["import { createContext, useContext } from 'solid-js'\nimport type { JSX } from 'solid-js'\nimport type {\n AnyAsyncFunction,\n AnyFunction,\n AsyncBatcherOptions,\n AsyncDebouncerOptions,\n AsyncQueuerOptions,\n AsyncRateLimiterOptions,\n AsyncThrottlerOptions,\n BatcherOptions,\n DebouncerOptions,\n QueuerOptions,\n RateLimiterOptions,\n ThrottlerOptions,\n} from '@tanstack/pacer'\n\nexport interface PacerProviderOptions {\n asyncBatcher?: Partial<AsyncBatcherOptions<any>>\n asyncDebouncer?: Partial<AsyncDebouncerOptions<AnyAsyncFunction>>\n asyncQueuer?: Partial<AsyncQueuerOptions<any>>\n asyncRateLimiter?: Partial<AsyncRateLimiterOptions<AnyAsyncFunction>>\n asyncThrottler?: Partial<AsyncThrottlerOptions<AnyAsyncFunction>>\n batcher?: Partial<BatcherOptions<any>>\n debouncer?: Partial<DebouncerOptions<AnyFunction>>\n queuer?: Partial<QueuerOptions<any>>\n rateLimiter?: Partial<RateLimiterOptions<AnyFunction>>\n throttler?: Partial<ThrottlerOptions<AnyFunction>>\n}\n\ninterface PacerContextValue {\n defaultOptions: PacerProviderOptions\n}\n\nconst PacerContext = createContext<PacerContextValue | null>(null)\n\nexport interface PacerProviderProps {\n children: JSX.Element\n defaultOptions?: PacerProviderOptions\n}\n\nconst DEFAULT_OPTIONS: PacerProviderOptions = {}\n\nexport function PacerProvider(props: PacerProviderProps) {\n const contextValue: PacerContextValue = {\n defaultOptions: props.defaultOptions ?? DEFAULT_OPTIONS,\n }\n\n return (\n <PacerContext.Provider value={contextValue}>\n {props.children}\n </PacerContext.Provider>\n )\n}\n\nexport function usePacerContext() {\n return useContext(PacerContext)\n}\n\nexport function useDefaultPacerOptions() {\n const context = useContext(PacerContext)\n return context?.defaultOptions ?? {}\n}\n"],"names":["PacerContext","createContext","DEFAULT_OPTIONS","PacerProvider","props","contextValue","defaultOptions","_$createComponent","Provider","value","children","usePacerContext","useContext","useDefaultPacerOptions","context"],"mappings":";;;;AAkCA,MAAMA,eAAeC,QAAAA,cAAwC,IAAI;AAOjE,MAAMC,kBAAwC,CAAA;AAEvC,SAASC,cAAcC,OAA2B;AACvD,QAAMC,eAAkC;AAAA,IACtCC,gBAAgBF,MAAME,kBAAkBJ;AAAAA,EAAAA;AAG1C,SAAAK,IAAAA,gBACGP,aAAaQ,UAAQ;AAAA,IAACC,OAAOJ;AAAAA,IAAY,IAAAK,WAAA;AAAA,aACvCN,MAAMM;AAAAA,IAAQ;AAAA,EAAA,CAAA;AAGrB;AAEO,SAASC,kBAAkB;AAChC,SAAOC,QAAAA,WAAWZ,YAAY;AAChC;AAEO,SAASa,yBAAyB;AACvC,QAAMC,UAAUF,QAAAA,WAAWZ,YAAY;AACvC,SAAOc,SAASR,kBAAkB,CAAA;AACpC;;;;"}
@@ -0,0 +1,25 @@
1
+ import { JSX } from 'solid-js';
2
+ import { AnyAsyncFunction, AnyFunction, AsyncBatcherOptions, AsyncDebouncerOptions, AsyncQueuerOptions, AsyncRateLimiterOptions, AsyncThrottlerOptions, BatcherOptions, DebouncerOptions, QueuerOptions, RateLimiterOptions, ThrottlerOptions } from '@tanstack/pacer';
3
+ export interface PacerProviderOptions {
4
+ asyncBatcher?: Partial<AsyncBatcherOptions<any>>;
5
+ asyncDebouncer?: Partial<AsyncDebouncerOptions<AnyAsyncFunction>>;
6
+ asyncQueuer?: Partial<AsyncQueuerOptions<any>>;
7
+ asyncRateLimiter?: Partial<AsyncRateLimiterOptions<AnyAsyncFunction>>;
8
+ asyncThrottler?: Partial<AsyncThrottlerOptions<AnyAsyncFunction>>;
9
+ batcher?: Partial<BatcherOptions<any>>;
10
+ debouncer?: Partial<DebouncerOptions<AnyFunction>>;
11
+ queuer?: Partial<QueuerOptions<any>>;
12
+ rateLimiter?: Partial<RateLimiterOptions<AnyFunction>>;
13
+ throttler?: Partial<ThrottlerOptions<AnyFunction>>;
14
+ }
15
+ interface PacerContextValue {
16
+ defaultOptions: PacerProviderOptions;
17
+ }
18
+ export interface PacerProviderProps {
19
+ children: JSX.Element;
20
+ defaultOptions?: PacerProviderOptions;
21
+ }
22
+ export declare function PacerProvider(props: PacerProviderProps): JSX.Element;
23
+ export declare function usePacerContext(): PacerContextValue | null;
24
+ export declare function useDefaultPacerOptions(): PacerProviderOptions;
25
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const createQueuer = require("./createQueuer.cjs");
4
+ function createQueuedSignal(fn, options = {}, selector = (state) => ({ items: state.items })) {
5
+ const queue = createQueuer.createQueuer(fn, options, selector);
6
+ return [() => queue.state().items, queue.addItem, queue];
7
+ }
8
+ exports.createQueuedSignal = createQueuedSignal;
9
+ //# sourceMappingURL=createQueuedSignal.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createQueuedSignal.cjs","sources":["../../../src/queuer/createQueuedSignal.ts"],"sourcesContent":["import { createQueuer } from './createQueuer'\nimport type { SolidQueuer } from './createQueuer'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * A Solid primitive that creates a queuer with managed state, combining Solid's signals with queuing functionality.\n * This primitive provides both the current queue state and queue control methods.\n *\n * The queue state is automatically updated whenever items are added, removed, or reordered in the queue.\n * All queue operations are reflected in the state array returned by the primitive.\n *\n * The queue can be started and stopped to automatically process items at a specified interval,\n * making it useful as a scheduler. When started, it will process one item per tick, with an\n * optional wait time between ticks.\n *\n * The primitive returns a tuple containing:\n * - The current queue state as an array\n * - The queue instance with methods for queue manipulation\n *\n * ## State Management and Selector\n *\n * The primitive uses Solid's reactive state management via the underlying queuer instance.\n * The `selector` parameter allows you to specify which queuer state changes will trigger a re-render,\n * optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary re-renders and gives you\n * full control over when your component updates. Only when you provide a selector will the\n * component re-render when the selected state values change.\n *\n * Available queuer state properties:\n * - `executionCount`: Number of items that have been processed by the queuer\n * - `expirationCount`: Number of items that have been removed due to expiration\n * - `isEmpty`: Whether the queuer has no items to process\n * - `isFull`: Whether the queuer has reached its maximum capacity\n * - `isIdle`: Whether the queuer is not currently processing any items\n * - `isRunning`: Whether the queuer is active and will process items automatically\n * - `items`: Array of items currently waiting to be processed\n * - `itemTimestamps`: Timestamps when items were added for expiration tracking\n * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item\n * - `rejectionCount`: Number of items that have been rejected from being added\n * - `size`: Number of items currently in the queue\n * - `status`: Current processing status ('idle' | 'running' | 'stopped')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * {\n * initialItems: ['item1', 'item2'],\n * started: true,\n * wait: 1000,\n * getPriority: (item) => item.priority\n * }\n * );\n *\n * // Opt-in to re-render when queue contents change (optimized for displaying queue items)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * items: state.items,\n * size: state.size,\n * isEmpty: state.isEmpty\n * })\n * );\n *\n * // Opt-in to re-render when processing state changes (optimized for loading indicators)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * isRunning: state.isRunning,\n * isIdle: state.isIdle,\n * status: state.status,\n * pendingTick: state.pendingTick\n * })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for stats display)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * expirationCount: state.expirationCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Add items to queue\n * const handleAdd = (item) => {\n * addItem(item);\n * };\n *\n * // Start automatic processing\n * const startProcessing = () => {\n * queue.start();\n * };\n *\n * // Stop automatic processing\n * const stopProcessing = () => {\n * queue.stop();\n * };\n *\n * // Manual processing still available\n * const handleProcess = () => {\n * const nextItem = queue.getNextItem();\n * if (nextItem) {\n * processItem(nextItem);\n * }\n * };\n *\n * // Access the selected queuer state (will be empty object {} unless selector provided)\n * const { size, isRunning, executionCount } = queue.state;\n * ```\n */\nexport function createQueuedSignal<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (item: TValue) => void,\n options: QueuerOptions<TValue> = {},\n selector: (state: QueuerState<TValue>) => TSelected = (state) =>\n ({ items: state.items }) as TSelected,\n): [\n () => Array<TValue>,\n SolidQueuer<TValue, TSelected>['addItem'],\n SolidQueuer<TValue, TSelected>,\n] {\n const queue = createQueuer(fn, options, selector)\n\n return [() => queue.state().items, queue.addItem, queue]\n}\n"],"names":["createQueuer"],"mappings":";;;AAsHO,SAAS,mBAOd,IACA,UAAiC,CAAA,GACjC,WAAsD,CAAC,WACpD,EAAE,OAAO,MAAM,MAAA,IAKlB;AACA,QAAM,QAAQA,aAAAA,aAAa,IAAI,SAAS,QAAQ;AAEhD,SAAO,CAAC,MAAM,MAAM,MAAA,EAAQ,OAAO,MAAM,SAAS,KAAK;AACzD;;"}
@@ -0,0 +1,121 @@
1
+ import { SolidQueuer } from './createQueuer.cjs';
2
+ import { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer';
3
+ /**
4
+ * A Solid primitive that creates a queuer with managed state, combining Solid's signals with queuing functionality.
5
+ * This primitive provides both the current queue state and queue control methods.
6
+ *
7
+ * The queue state is automatically updated whenever items are added, removed, or reordered in the queue.
8
+ * All queue operations are reflected in the state array returned by the primitive.
9
+ *
10
+ * The queue can be started and stopped to automatically process items at a specified interval,
11
+ * making it useful as a scheduler. When started, it will process one item per tick, with an
12
+ * optional wait time between ticks.
13
+ *
14
+ * The primitive returns a tuple containing:
15
+ * - The current queue state as an array
16
+ * - The queue instance with methods for queue manipulation
17
+ *
18
+ * ## State Management and Selector
19
+ *
20
+ * The primitive uses Solid's reactive state management via the underlying queuer instance.
21
+ * The `selector` parameter allows you to specify which queuer state changes will trigger a re-render,
22
+ * optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur.
23
+ *
24
+ * **By default, there will be no reactive state subscriptions** and you must opt-in to state
25
+ * tracking by providing a selector function. This prevents unnecessary re-renders and gives you
26
+ * full control over when your component updates. Only when you provide a selector will the
27
+ * component re-render when the selected state values change.
28
+ *
29
+ * Available queuer state properties:
30
+ * - `executionCount`: Number of items that have been processed by the queuer
31
+ * - `expirationCount`: Number of items that have been removed due to expiration
32
+ * - `isEmpty`: Whether the queuer has no items to process
33
+ * - `isFull`: Whether the queuer has reached its maximum capacity
34
+ * - `isIdle`: Whether the queuer is not currently processing any items
35
+ * - `isRunning`: Whether the queuer is active and will process items automatically
36
+ * - `items`: Array of items currently waiting to be processed
37
+ * - `itemTimestamps`: Timestamps when items were added for expiration tracking
38
+ * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item
39
+ * - `rejectionCount`: Number of items that have been rejected from being added
40
+ * - `size`: Number of items currently in the queue
41
+ * - `status`: Current processing status ('idle' | 'running' | 'stopped')
42
+ *
43
+ * @example
44
+ * ```tsx
45
+ * // Default behavior - no reactive state subscriptions
46
+ * const [items, addItem, queue] = createQueuedSignal(
47
+ * (item) => console.log('Processing:', item),
48
+ * {
49
+ * initialItems: ['item1', 'item2'],
50
+ * started: true,
51
+ * wait: 1000,
52
+ * getPriority: (item) => item.priority
53
+ * }
54
+ * );
55
+ *
56
+ * // Opt-in to re-render when queue contents change (optimized for displaying queue items)
57
+ * const [items, addItem, queue] = createQueuedSignal(
58
+ * (item) => console.log('Processing:', item),
59
+ * { started: true, wait: 1000 },
60
+ * (state) => ({
61
+ * items: state.items,
62
+ * size: state.size,
63
+ * isEmpty: state.isEmpty
64
+ * })
65
+ * );
66
+ *
67
+ * // Opt-in to re-render when processing state changes (optimized for loading indicators)
68
+ * const [items, addItem, queue] = createQueuedSignal(
69
+ * (item) => console.log('Processing:', item),
70
+ * { started: true, wait: 1000 },
71
+ * (state) => ({
72
+ * isRunning: state.isRunning,
73
+ * isIdle: state.isIdle,
74
+ * status: state.status,
75
+ * pendingTick: state.pendingTick
76
+ * })
77
+ * );
78
+ *
79
+ * // Opt-in to re-render when execution metrics change (optimized for stats display)
80
+ * const [items, addItem, queue] = createQueuedSignal(
81
+ * (item) => console.log('Processing:', item),
82
+ * { started: true, wait: 1000 },
83
+ * (state) => ({
84
+ * executionCount: state.executionCount,
85
+ * expirationCount: state.expirationCount,
86
+ * rejectionCount: state.rejectionCount
87
+ * })
88
+ * );
89
+ *
90
+ * // Add items to queue
91
+ * const handleAdd = (item) => {
92
+ * addItem(item);
93
+ * };
94
+ *
95
+ * // Start automatic processing
96
+ * const startProcessing = () => {
97
+ * queue.start();
98
+ * };
99
+ *
100
+ * // Stop automatic processing
101
+ * const stopProcessing = () => {
102
+ * queue.stop();
103
+ * };
104
+ *
105
+ * // Manual processing still available
106
+ * const handleProcess = () => {
107
+ * const nextItem = queue.getNextItem();
108
+ * if (nextItem) {
109
+ * processItem(nextItem);
110
+ * }
111
+ * };
112
+ *
113
+ * // Access the selected queuer state (will be empty object {} unless selector provided)
114
+ * const { size, isRunning, executionCount } = queue.state;
115
+ * ```
116
+ */
117
+ export declare function createQueuedSignal<TValue, TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<QueuerState<TValue>, 'items'>>(fn: (item: TValue) => void, options?: QueuerOptions<TValue>, selector?: (state: QueuerState<TValue>) => TSelected): [
118
+ () => Array<TValue>,
119
+ SolidQueuer<TValue, TSelected>['addItem'],
120
+ SolidQueuer<TValue, TSelected>
121
+ ];
@@ -2,8 +2,13 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const queuer = require("@tanstack/pacer/queuer");
4
4
  const solidStore = require("@tanstack/solid-store");
5
- function createQueuer(fn, initialOptions = {}, selector = () => ({})) {
6
- const queuer$1 = new queuer.Queuer(fn, initialOptions);
5
+ const PacerProvider = require("../provider/PacerProvider.cjs");
6
+ function createQueuer(fn, options = {}, selector = () => ({})) {
7
+ const mergedOptions = {
8
+ ...PacerProvider.useDefaultPacerOptions().queuer,
9
+ ...options
10
+ };
11
+ const queuer$1 = new queuer.Queuer(fn, mergedOptions);
7
12
  const state = solidStore.useStore(queuer$1.store, selector);
8
13
  return {
9
14
  ...queuer$1,
@@ -1 +1 @@
1
- {"version":3,"file":"createQueuer.cjs","sources":["../../../src/queuer/createQueuer.ts"],"sourcesContent":["import { Queuer } from '@tanstack/pacer/queuer'\nimport { useStore } from '@tanstack/solid-store'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface SolidQueuer<TValue, TSelected = {}>\n extends Omit<Queuer<TValue>, 'store'> {\n /**\n * Reactive state that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<QueuerState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Synchronous processing of items using the provided `fn` function\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Priority queueing via `getPriority` or item `priority` property\n * - Item expiration and removal of stale items\n * - Configurable wait time between processing items\n * - Pause/resume processing\n * - Callbacks for queue state changes, execution, rejection, and expiration\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The queue processes items synchronously in order, with optional delays between each item. When started, it will process one item per tick, with an optional wait time between ticks. You can pause and resume processing with `stop()` and `start()`.\n *\n * By default, the queue uses FIFO behavior, but you can configure LIFO or double-ended queueing by specifying the position when adding or removing items.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you\n * to specify which state changes will trigger a re-render, optimizing performance by preventing\n * unnecessary re-renders when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary re-renders and gives you\n * full control over when your component updates. Only when you provide a selector will the\n * component re-render when the selected state values change.\n *\n * Available state properties:\n * - `executionCount`: Number of items that have been processed\n * - `isRunning`: Whether the queuer is currently running (not stopped)\n * - `items`: Array of items currently queued for processing\n * - `rejectionCount`: Number of items that were rejected (expired or failed validation)\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const queue = createQueuer(\n * (item) => {\n * // process item synchronously\n * console.log('Processing', item);\n * },\n * {\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * getPriority: (item) => item.priority // Process higher priority items first\n * }\n * );\n *\n * // Opt-in to re-render when items or isRunning changes (optimized for UI updates)\n * const queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\n * (state) => ({ items: state.items, isRunning: state.isRunning })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for tracking progress)\n * const queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * rejectionCount: state.rejectionCount\n * })\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 the selected state (will be empty object {} unless selector provided)\n * const { items, isRunning } = queue.state();\n * ```\n */\nexport function createQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n initialOptions: QueuerOptions<TValue> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): SolidQueuer<TValue, TSelected> {\n const queuer = new Queuer(fn, initialOptions)\n\n const state = useStore(queuer.store, selector)\n\n return {\n ...queuer,\n state,\n } as SolidQueuer<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"names":["queuer","Queuer","useStore"],"mappings":";;;;AAoGO,SAAS,aACd,IACA,iBAAwC,CAAA,GACxC,WAAsD,OAAO,CAAA,IAC7B;AAChC,QAAMA,WAAS,IAAIC,cAAO,IAAI,cAAc;AAE5C,QAAM,QAAQC,WAAAA,SAASF,SAAO,OAAO,QAAQ;AAE7C,SAAO;AAAA,IACL,GAAGA;AAAAA,IACH;AAAA,EAAA;AAEJ;;"}
1
+ {"version":3,"file":"createQueuer.cjs","sources":["../../../src/queuer/createQueuer.ts"],"sourcesContent":["import { Queuer } from '@tanstack/pacer/queuer'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface SolidQueuer<TValue, TSelected = {}>\n extends Omit<Queuer<TValue>, 'store'> {\n /**\n * Reactive state that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<QueuerState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Synchronous processing of items using the provided `fn` function\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Priority queueing via `getPriority` or item `priority` property\n * - Item expiration and removal of stale items\n * - Configurable wait time between processing items\n * - Pause/resume processing\n * - Callbacks for queue state changes, execution, rejection, and expiration\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The queue processes items synchronously in order, with optional delays between each item. When started, it will process one item per tick, with an optional wait time between ticks. You can pause and resume processing with `stop()` and `start()`.\n *\n * By default, the queue uses FIFO behavior, but you can configure LIFO or double-ended queueing by specifying the position when adding or removing items.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you\n * to specify which state changes will trigger a re-render, optimizing performance by preventing\n * unnecessary re-renders when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary re-renders and gives you\n * full control over when your component updates. Only when you provide a selector will the\n * component re-render when the selected state values change.\n *\n * Available state properties:\n * - `executionCount`: Number of items that have been processed\n * - `isRunning`: Whether the queuer is currently running (not stopped)\n * - `items`: Array of items currently queued for processing\n * - `rejectionCount`: Number of items that were rejected (expired or failed validation)\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const queue = createQueuer(\n * (item) => {\n * // process item synchronously\n * console.log('Processing', item);\n * },\n * {\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * getPriority: (item) => item.priority // Process higher priority items first\n * }\n * );\n *\n * // Opt-in to re-render when items or isRunning changes (optimized for UI updates)\n * const queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\n * (state) => ({ items: state.items, isRunning: state.isRunning })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for tracking progress)\n * const queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * rejectionCount: state.rejectionCount\n * })\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 the selected state (will be empty object {} unless selector provided)\n * const { items, isRunning } = queue.state();\n * ```\n */\nexport function createQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: QueuerOptions<TValue> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): SolidQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().queuer,\n ...options,\n } as QueuerOptions<TValue>\n\n const queuer = new Queuer(fn, mergedOptions)\n\n const state = useStore(queuer.store, selector)\n\n return {\n ...queuer,\n state,\n } as SolidQueuer<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"names":["useDefaultPacerOptions","queuer","Queuer","useStore"],"mappings":";;;;;AAqGO,SAAS,aACd,IACA,UAAiC,CAAA,GACjC,WAAsD,OAAO,CAAA,IAC7B;AAChC,QAAM,gBAAgB;AAAA,IACpB,GAAGA,cAAAA,yBAAyB;AAAA,IAC5B,GAAG;AAAA,EAAA;AAGL,QAAMC,WAAS,IAAIC,cAAO,IAAI,aAAa;AAE3C,QAAM,QAAQC,WAAAA,SAASF,SAAO,OAAO,QAAQ;AAE7C,SAAO;AAAA,IACL,GAAGA;AAAAA,IACH;AAAA,EAAA;AAEJ;;"}
@@ -93,4 +93,4 @@ export interface SolidQueuer<TValue, TSelected = {}> extends Omit<Queuer<TValue>
93
93
  * const { items, isRunning } = queue.state();
94
94
  * ```
95
95
  */
96
- export declare function createQueuer<TValue, TSelected = {}>(fn: (item: TValue) => void, initialOptions?: QueuerOptions<TValue>, selector?: (state: QueuerState<TValue>) => TSelected): SolidQueuer<TValue, TSelected>;
96
+ export declare function createQueuer<TValue, TSelected = {}>(fn: (item: TValue) => void, options?: QueuerOptions<TValue>, selector?: (state: QueuerState<TValue>) => TSelected): SolidQueuer<TValue, TSelected>;
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const queuer = require("@tanstack/pacer/queuer");
4
4
  const createQueuer = require("./createQueuer.cjs");
5
+ const createQueuedSignal = require("./createQueuedSignal.cjs");
5
6
  exports.createQueuer = createQueuer.createQueuer;
7
+ exports.createQueuedSignal = createQueuedSignal.createQueuedSignal;
6
8
  Object.keys(queuer).forEach((k) => {
7
9
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
8
10
  enumerable: true,
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
@@ -1,2 +1,3 @@
1
1
  export * from '@tanstack/pacer/queuer';
2
2
  export * from './createQueuer.cjs';
3
+ export * from './createQueuedSignal.cjs';
@@ -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 {\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 * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.\n * The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available rate limiter state properties:\n * - `callsInWindow`: Number of calls made in the current window\n * - `remainingInWindow`: Number of calls remaining in the current window\n * - `windowStart`: Unix timestamp when the current window started\n * - `nextWindowStart`: Unix timestamp when the next window will start\n * - `msUntilNextWindow`: Milliseconds until the next window starts\n * - `isAtLimit`: Whether the call limit for the current window has been reached\n * - `status`: Current status ('disabled' | 'idle' | 'at-limit')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to reactive updates when limit state changes (optimized for UI feedback)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000 },\n * (state) => ({ isAtLimit: state.isAtLimit, remainingInWindow: state.remainingInWindow })\n * );\n *\n * // Use the rate-limited value\n * console.log(rateLimitedValue()); // Access the current rate-limited value\n *\n * // Access rate limiter state via signals\n * console.log('Is at limit:', rateLimiter.state().isAtLimit);\n *\n * // Control the rate limiter\n * rateLimiter.reset(); // Reset the rate limit window\n * ```\n */\nexport function createRateLimitedValue<TValue, TSelected = {}>(\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":";;;;AAkFO,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,EACpC,CAAC;AAED,SAAO,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 * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.\n * The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available rate limiter state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations\n * - `rejectionCount`: Number of function executions that have been rejected due to rate limiting\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to reactive updates when execution count changes (optimized for tracking successful updates)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to reactive updates when rejection count changes (optimized for tracking rate limit violations)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to reactive updates when execution times change (optimized for window calculations)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // With rejection callback and fixed window\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 3,\n * window: 5000,\n * windowType: 'fixed',\n * onReject: (rateLimiter) => {\n * console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access the selected rate limiter state (will be empty object {} unless selector provided)\n * const { executionCount, rejectionCount } = rateLimiter.state;\n * ```\n */\nexport function createRateLimitedValue<TValue, TSelected = {}>(\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":";;;;AAgGO,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,EACpC,CAAC;AAED,SAAO,CAAC,kBAAkB,WAAW;AACvC;;"}
@@ -40,13 +40,9 @@ import { RateLimiterOptions, RateLimiterState } from '@tanstack/pacer/rate-limit
40
40
  * the reactive system track the selected state values.
41
41
  *
42
42
  * Available rate limiter state properties:
43
- * - `callsInWindow`: Number of calls made in the current window
44
- * - `remainingInWindow`: Number of calls remaining in the current window
45
- * - `windowStart`: Unix timestamp when the current window started
46
- * - `nextWindowStart`: Unix timestamp when the next window will start
47
- * - `msUntilNextWindow`: Milliseconds until the next window starts
48
- * - `isAtLimit`: Whether the call limit for the current window has been reached
49
- * - `status`: Current status ('disabled' | 'idle' | 'at-limit')
43
+ * - `executionCount`: Number of function executions that have been completed
44
+ * - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations
45
+ * - `rejectionCount`: Number of function executions that have been rejected due to rate limiting
50
46
  *
51
47
  * @example
52
48
  * ```tsx
@@ -57,21 +53,39 @@ import { RateLimiterOptions, RateLimiterState } from '@tanstack/pacer/rate-limit
57
53
  * windowType: 'sliding'
58
54
  * });
59
55
  *
60
- * // Opt-in to reactive updates when limit state changes (optimized for UI feedback)
56
+ * // Opt-in to reactive updates when execution count changes (optimized for tracking successful updates)
61
57
  * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
62
58
  * rawValue,
63
- * { limit: 5, window: 60000 },
64
- * (state) => ({ isAtLimit: state.isAtLimit, remainingInWindow: state.remainingInWindow })
59
+ * { limit: 5, window: 60000, windowType: 'sliding' },
60
+ * (state) => ({ executionCount: state.executionCount })
65
61
  * );
66
62
  *
67
- * // Use the rate-limited value
68
- * console.log(rateLimitedValue()); // Access the current rate-limited value
63
+ * // Opt-in to reactive updates when rejection count changes (optimized for tracking rate limit violations)
64
+ * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
65
+ * rawValue,
66
+ * { limit: 5, window: 60000, windowType: 'sliding' },
67
+ * (state) => ({ rejectionCount: state.rejectionCount })
68
+ * );
69
69
  *
70
- * // Access rate limiter state via signals
71
- * console.log('Is at limit:', rateLimiter.state().isAtLimit);
70
+ * // Opt-in to reactive updates when execution times change (optimized for window calculations)
71
+ * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
72
+ * rawValue,
73
+ * { limit: 5, window: 60000, windowType: 'sliding' },
74
+ * (state) => ({ executionTimes: state.executionTimes })
75
+ * );
76
+ *
77
+ * // With rejection callback and fixed window
78
+ * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
79
+ * limit: 3,
80
+ * window: 5000,
81
+ * windowType: 'fixed',
82
+ * onReject: (rateLimiter) => {
83
+ * console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
84
+ * }
85
+ * });
72
86
  *
73
- * // Control the rate limiter
74
- * rateLimiter.reset(); // Reset the rate limit window
87
+ * // Access the selected rate limiter state (will be empty object {} unless selector provided)
88
+ * const { executionCount, rejectionCount } = rateLimiter.state;
75
89
  * ```
76
90
  */
77
91
  export declare function createRateLimitedValue<TValue, TSelected = {}>(value: Accessor<TValue>, initialOptions: RateLimiterOptions<Setter<TValue>>, selector?: (state: RateLimiterState) => TSelected): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, TSelected>];
@@ -2,8 +2,13 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const rateLimiter = require("@tanstack/pacer/rate-limiter");
4
4
  const solidStore = require("@tanstack/solid-store");
5
- function createRateLimiter(fn, initialOptions, selector = () => ({})) {
6
- const rateLimiter$1 = new rateLimiter.RateLimiter(fn, initialOptions);
5
+ const PacerProvider = require("../provider/PacerProvider.cjs");
6
+ function createRateLimiter(fn, options, selector = () => ({})) {
7
+ const mergedOptions = {
8
+ ...PacerProvider.useDefaultPacerOptions().rateLimiter,
9
+ ...options
10
+ };
11
+ const rateLimiter$1 = new rateLimiter.RateLimiter(fn, mergedOptions);
7
12
  const state = solidStore.useStore(rateLimiter$1.store, selector);
8
13
  return {
9
14
  ...rateLimiter$1,
@@ -1 +1 @@
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 { Store } 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<TFn extends AnyFunction, TSelected = {}>\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 * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<RateLimiterState>>\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 * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you\n * to specify which state changes will trigger a re-render, optimizing performance by preventing\n * unnecessary re-renders when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary re-renders and gives you\n * full control over when your component updates. Only when you provide a selector will the\n * component re-render when the selected state values change.\n *\n * Available state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `rejectionCount`: Number of function calls that were rejected due to rate limiting\n * - `remainingInWindow`: Number of executions remaining in the current window\n * - `nextWindowTime`: Timestamp when the next window begins\n * - `currentWindowStart`: Timestamp when the current window started\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\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 * // Opt-in to re-render when rate limit state changes (optimized for UI feedback)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * { limit: 5, window: 60000 },\n * (state) => ({\n * remainingInWindow: state.remainingInWindow,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for tracking progress)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * { limit: 5, window: 60000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * nextWindowTime: state.nextWindowTime\n * })\n * );\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { remainingInWindow, rejectionCount } = rateLimiter.state();\n * ```\n */\nexport function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n initialOptions: RateLimiterOptions<TFn>,\n selector: (state: RateLimiterState) => TSelected = () => ({}) as 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 SolidRateLimiter<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"names":["rateLimiter","RateLimiter","useStore"],"mappings":";;;;AAqGO,SAAS,kBACd,IACA,gBACA,WAAmD,OAAO,CAAA,IACxB;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
+ {"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 { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } 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<TFn extends AnyFunction, TSelected = {}>\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 * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<RateLimiterState>>\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 * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you\n * to specify which state changes will trigger a re-render, optimizing performance by preventing\n * unnecessary re-renders when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary re-renders and gives you\n * full control over when your component updates. Only when you provide a selector will the\n * component re-render when the selected state values change.\n *\n * Available state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `rejectionCount`: Number of function calls that were rejected due to rate limiting\n * - `remainingInWindow`: Number of executions remaining in the current window\n * - `nextWindowTime`: Timestamp when the next window begins\n * - `currentWindowStart`: Timestamp when the current window started\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\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 * // Opt-in to re-render when rate limit state changes (optimized for UI feedback)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * { limit: 5, window: 60000 },\n * (state) => ({\n * remainingInWindow: state.remainingInWindow,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for tracking progress)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * { limit: 5, window: 60000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * nextWindowTime: state.nextWindowTime\n * })\n * );\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { remainingInWindow, rejectionCount } = rateLimiter.state();\n * ```\n */\nexport function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: RateLimiterOptions<TFn>,\n selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,\n): SolidRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().rateLimiter,\n ...options,\n } as RateLimiterOptions<TFn>\n\n const rateLimiter = new RateLimiter<TFn>(fn, mergedOptions)\n\n const state = useStore(rateLimiter.store, selector)\n\n return {\n ...rateLimiter,\n state,\n } as SolidRateLimiter<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"names":["useDefaultPacerOptions","rateLimiter","RateLimiter","useStore"],"mappings":";;;;;AAsGO,SAAS,kBACd,IACA,SACA,WAAmD,OAAO,CAAA,IACxB;AAClC,QAAM,gBAAgB;AAAA,IACpB,GAAGA,cAAAA,yBAAyB;AAAA,IAC5B,GAAG;AAAA,EAAA;AAGL,QAAMC,gBAAc,IAAIC,wBAAiB,IAAI,aAAa;AAE1D,QAAM,QAAQC,WAAAA,SAASF,cAAY,OAAO,QAAQ;AAElD,SAAO;AAAA,IACL,GAAGA;AAAAA,IACH;AAAA,EAAA;AAEJ;;"}
@@ -91,4 +91,4 @@ export interface SolidRateLimiter<TFn extends AnyFunction, TSelected = {}> exten
91
91
  * const { remainingInWindow, rejectionCount } = rateLimiter.state();
92
92
  * ```
93
93
  */
94
- export declare function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(fn: TFn, initialOptions: RateLimiterOptions<TFn>, selector?: (state: RateLimiterState) => TSelected): SolidRateLimiter<TFn, TSelected>;
94
+ export declare function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: RateLimiterOptions<TFn>, selector?: (state: RateLimiterState) => TSelected): SolidRateLimiter<TFn, TSelected>;
@@ -3,8 +3,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const throttler = require("@tanstack/pacer/throttler");
4
4
  const solidJs = require("solid-js");
5
5
  const solidStore = require("@tanstack/solid-store");
6
- function createThrottler(fn, initialOptions, selector = () => ({})) {
7
- const asyncThrottler = new throttler.Throttler(fn, initialOptions);
6
+ const PacerProvider = require("../provider/PacerProvider.cjs");
7
+ function createThrottler(fn, options, selector = () => ({})) {
8
+ const mergedOptions = {
9
+ ...PacerProvider.useDefaultPacerOptions().throttler,
10
+ ...options
11
+ };
12
+ const asyncThrottler = new throttler.Throttler(fn, mergedOptions);
8
13
  const state = solidStore.useStore(asyncThrottler.store, selector);
9
14
  solidJs.createEffect(() => {
10
15
  solidJs.onCleanup(() => {
@@ -1 +1 @@
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 { Store } 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<TFn extends AnyFunction, TSelected = {}>\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 * @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<ThrottlerState<TFn>>>\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 * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you\n * to specify which state changes will trigger a re-render, optimizing performance by preventing\n * unnecessary re-renders when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary re-renders and gives you\n * full control over when your component updates. Only when you provide a selector will the\n * component re-render when the selected state values change.\n *\n * Available state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const throttler = createThrottler(setValue, { wait: 1000 });\n *\n * // Opt-in to re-render when isPending changes (optimized for loading states)\n * const throttler = createThrottler(\n * setValue,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to re-render when executionCount changes (optimized for tracking execution)\n * const throttler = createThrottler(\n * setValue,\n * { wait: 1000 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Multiple state properties - re-render when any of these change\n * const throttler = createThrottler(\n * setValue,\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false // Skip trailing edge updates\n * },\n * (state) => ({\n * isPending: state.isPending,\n * executionCount: state.executionCount,\n * lastExecutionTime: state.lastExecutionTime,\n * nextExecutionTime: state.nextExecutionTime\n * })\n * );\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending, executionCount } = throttler.state();\n * ```\n */\nexport function createThrottler<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n initialOptions: ThrottlerOptions<TFn>,\n selector: (state: ThrottlerState<TFn>) => TSelected = () => ({}) as 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":";;;;;AAkGO,SAAS,gBACd,IACA,gBACA,WAAsD,OAAO,CAAA,IAC7B;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,IACjB,CAAC;AAAA,EACH,CAAC;AAED,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,EAAA;AAEJ;;"}
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 { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } 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<TFn extends AnyFunction, TSelected = {}>\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 * @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<ThrottlerState<TFn>>>\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 * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you\n * to specify which state changes will trigger a re-render, optimizing performance by preventing\n * unnecessary re-renders when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary re-renders and gives you\n * full control over when your component updates. Only when you provide a selector will the\n * component re-render when the selected state values change.\n *\n * Available state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const throttler = createThrottler(setValue, { wait: 1000 });\n *\n * // Opt-in to re-render when isPending changes (optimized for loading states)\n * const throttler = createThrottler(\n * setValue,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to re-render when executionCount changes (optimized for tracking execution)\n * const throttler = createThrottler(\n * setValue,\n * { wait: 1000 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Multiple state properties - re-render when any of these change\n * const throttler = createThrottler(\n * setValue,\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false // Skip trailing edge updates\n * },\n * (state) => ({\n * isPending: state.isPending,\n * executionCount: state.executionCount,\n * lastExecutionTime: state.lastExecutionTime,\n * nextExecutionTime: state.nextExecutionTime\n * })\n * );\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending, executionCount } = throttler.state();\n * ```\n */\nexport function createThrottler<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: ThrottlerOptions<TFn>,\n selector: (state: ThrottlerState<TFn>) => TSelected = () => ({}) as TSelected,\n): SolidThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().throttler,\n ...options,\n } as ThrottlerOptions<TFn>\n\n const asyncThrottler = new Throttler<TFn>(fn, mergedOptions)\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":["useDefaultPacerOptions","Throttler","useStore","createEffect","onCleanup"],"mappings":";;;;;;AAmGO,SAAS,gBACd,IACA,SACA,WAAsD,OAAO,CAAA,IAC7B;AAChC,QAAM,gBAAgB;AAAA,IACpB,GAAGA,cAAAA,yBAAyB;AAAA,IAC5B,GAAG;AAAA,EAAA;AAGL,QAAM,iBAAiB,IAAIC,oBAAe,IAAI,aAAa;AAE3D,QAAM,QAAQC,WAAAA,SAAS,eAAe,OAAO,QAAQ;AAErDC,UAAAA,aAAa,MAAM;AACjBC,YAAAA,UAAU,MAAM;AACd,qBAAe,OAAA;AAAA,IACjB,CAAC;AAAA,EACH,CAAC;AAED,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,EAAA;AAEJ;;"}
@@ -87,4 +87,4 @@ export interface SolidThrottler<TFn extends AnyFunction, TSelected = {}> extends
87
87
  * const { isPending, executionCount } = throttler.state();
88
88
  * ```
89
89
  */
90
- export declare function createThrottler<TFn extends AnyFunction, TSelected = {}>(fn: TFn, initialOptions: ThrottlerOptions<TFn>, selector?: (state: ThrottlerState<TFn>) => TSelected): SolidThrottler<TFn, TSelected>;
90
+ export declare function createThrottler<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: ThrottlerOptions<TFn>, selector?: (state: ThrottlerState<TFn>) => TSelected): SolidThrottler<TFn, TSelected>;
@@ -117,4 +117,4 @@ export interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBat
117
117
  * const { items, isExecuting } = asyncBatcher.state();
118
118
  * ```
119
119
  */
120
- export declare function createAsyncBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => Promise<any>, initialOptions?: AsyncBatcherOptions<TValue>, selector?: (state: AsyncBatcherState<TValue>) => TSelected): SolidAsyncBatcher<TValue, TSelected>;
120
+ export declare function createAsyncBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => Promise<any>, options?: AsyncBatcherOptions<TValue>, selector?: (state: AsyncBatcherState<TValue>) => TSelected): SolidAsyncBatcher<TValue, TSelected>;
@@ -1,7 +1,12 @@
1
1
  import { AsyncBatcher } from "@tanstack/pacer/async-batcher";
2
2
  import { useStore } from "@tanstack/solid-store";
3
- function createAsyncBatcher(fn, initialOptions = {}, selector = () => ({})) {
4
- const asyncBatcher = new AsyncBatcher(fn, initialOptions);
3
+ import { useDefaultPacerOptions } from "../provider/PacerProvider.js";
4
+ function createAsyncBatcher(fn, options = {}, selector = () => ({})) {
5
+ const mergedOptions = {
6
+ ...useDefaultPacerOptions().asyncBatcher,
7
+ ...options
8
+ };
9
+ const asyncBatcher = new AsyncBatcher(fn, mergedOptions);
5
10
  const state = useStore(asyncBatcher.store, selector);
6
11
  return {
7
12
  ...asyncBatcher,