@tanstack/preact-pacer 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/README.md +17 -2
  2. package/dist/async-batcher/useAsyncBatchedCallback.cjs.map +1 -1
  3. package/dist/async-batcher/useAsyncBatchedCallback.d.cts +0 -1
  4. package/dist/async-batcher/useAsyncBatchedCallback.d.ts +0 -1
  5. package/dist/async-batcher/useAsyncBatchedCallback.js.map +1 -1
  6. package/dist/async-batcher/useAsyncBatcher.cjs.map +1 -1
  7. package/dist/async-batcher/useAsyncBatcher.d.cts +0 -1
  8. package/dist/async-batcher/useAsyncBatcher.d.ts +0 -1
  9. package/dist/async-batcher/useAsyncBatcher.js.map +1 -1
  10. package/dist/async-debouncer/useAsyncDebouncedCallback.cjs +4 -2
  11. package/dist/async-debouncer/useAsyncDebouncedCallback.cjs.map +1 -1
  12. package/dist/async-debouncer/useAsyncDebouncedCallback.d.cts +5 -4
  13. package/dist/async-debouncer/useAsyncDebouncedCallback.d.ts +5 -4
  14. package/dist/async-debouncer/useAsyncDebouncedCallback.js +4 -2
  15. package/dist/async-debouncer/useAsyncDebouncedCallback.js.map +1 -1
  16. package/dist/async-debouncer/useAsyncDebouncer.cjs.map +1 -1
  17. package/dist/async-debouncer/useAsyncDebouncer.d.cts +0 -1
  18. package/dist/async-debouncer/useAsyncDebouncer.d.ts +0 -1
  19. package/dist/async-debouncer/useAsyncDebouncer.js.map +1 -1
  20. package/dist/async-queuer/useAsyncQueuedState.cjs.map +1 -1
  21. package/dist/async-queuer/useAsyncQueuedState.d.cts +0 -1
  22. package/dist/async-queuer/useAsyncQueuedState.d.ts +0 -1
  23. package/dist/async-queuer/useAsyncQueuedState.js.map +1 -1
  24. package/dist/async-queuer/useAsyncQueuer.cjs.map +1 -1
  25. package/dist/async-queuer/useAsyncQueuer.d.cts +0 -1
  26. package/dist/async-queuer/useAsyncQueuer.d.ts +0 -1
  27. package/dist/async-queuer/useAsyncQueuer.js.map +1 -1
  28. package/dist/async-rate-limiter/useAsyncRateLimitedCallback.cjs.map +1 -1
  29. package/dist/async-rate-limiter/useAsyncRateLimitedCallback.d.cts +1 -2
  30. package/dist/async-rate-limiter/useAsyncRateLimitedCallback.d.ts +1 -2
  31. package/dist/async-rate-limiter/useAsyncRateLimitedCallback.js.map +1 -1
  32. package/dist/async-rate-limiter/useAsyncRateLimiter.cjs.map +1 -1
  33. package/dist/async-rate-limiter/useAsyncRateLimiter.d.cts +0 -1
  34. package/dist/async-rate-limiter/useAsyncRateLimiter.d.ts +0 -1
  35. package/dist/async-rate-limiter/useAsyncRateLimiter.js.map +1 -1
  36. package/dist/async-retryer/index.cjs +0 -1
  37. package/dist/async-throttler/useAsyncThrottledCallback.cjs +5 -4
  38. package/dist/async-throttler/useAsyncThrottledCallback.cjs.map +1 -1
  39. package/dist/async-throttler/useAsyncThrottledCallback.d.cts +6 -6
  40. package/dist/async-throttler/useAsyncThrottledCallback.d.ts +6 -6
  41. package/dist/async-throttler/useAsyncThrottledCallback.js +5 -4
  42. package/dist/async-throttler/useAsyncThrottledCallback.js.map +1 -1
  43. package/dist/async-throttler/useAsyncThrottler.cjs.map +1 -1
  44. package/dist/async-throttler/useAsyncThrottler.d.cts +0 -1
  45. package/dist/async-throttler/useAsyncThrottler.d.ts +0 -1
  46. package/dist/async-throttler/useAsyncThrottler.js.map +1 -1
  47. package/dist/batcher/useBatchedCallback.cjs.map +1 -1
  48. package/dist/batcher/useBatchedCallback.d.cts +0 -1
  49. package/dist/batcher/useBatchedCallback.d.ts +0 -1
  50. package/dist/batcher/useBatchedCallback.js.map +1 -1
  51. package/dist/batcher/useBatcher.cjs.map +1 -1
  52. package/dist/batcher/useBatcher.d.cts +0 -1
  53. package/dist/batcher/useBatcher.d.ts +0 -1
  54. package/dist/batcher/useBatcher.js.map +1 -1
  55. package/dist/debouncer/useDebouncedCallback.cjs.map +1 -1
  56. package/dist/debouncer/useDebouncedCallback.d.cts +0 -1
  57. package/dist/debouncer/useDebouncedCallback.d.ts +0 -1
  58. package/dist/debouncer/useDebouncedCallback.js.map +1 -1
  59. package/dist/debouncer/useDebouncedState.cjs.map +1 -1
  60. package/dist/debouncer/useDebouncedState.d.cts +0 -1
  61. package/dist/debouncer/useDebouncedState.d.ts +0 -1
  62. package/dist/debouncer/useDebouncedState.js.map +1 -1
  63. package/dist/debouncer/useDebouncedValue.cjs.map +1 -1
  64. package/dist/debouncer/useDebouncedValue.d.cts +0 -1
  65. package/dist/debouncer/useDebouncedValue.d.ts +0 -1
  66. package/dist/debouncer/useDebouncedValue.js.map +1 -1
  67. package/dist/debouncer/useDebouncer.cjs.map +1 -1
  68. package/dist/debouncer/useDebouncer.d.cts +0 -1
  69. package/dist/debouncer/useDebouncer.d.ts +0 -1
  70. package/dist/debouncer/useDebouncer.js.map +1 -1
  71. package/dist/provider/PacerProvider.cjs.map +1 -1
  72. package/dist/provider/PacerProvider.d.cts +1 -6
  73. package/dist/provider/PacerProvider.d.ts +1 -6
  74. package/dist/provider/PacerProvider.js.map +1 -1
  75. package/dist/queuer/useQueuedState.cjs.map +1 -1
  76. package/dist/queuer/useQueuedState.d.cts +0 -1
  77. package/dist/queuer/useQueuedState.d.ts +0 -1
  78. package/dist/queuer/useQueuedState.js.map +1 -1
  79. package/dist/queuer/useQueuedValue.cjs.map +1 -1
  80. package/dist/queuer/useQueuedValue.d.cts +0 -1
  81. package/dist/queuer/useQueuedValue.d.ts +0 -1
  82. package/dist/queuer/useQueuedValue.js.map +1 -1
  83. package/dist/queuer/useQueuer.cjs.map +1 -1
  84. package/dist/queuer/useQueuer.d.cts +0 -1
  85. package/dist/queuer/useQueuer.d.ts +0 -1
  86. package/dist/queuer/useQueuer.js.map +1 -1
  87. package/dist/rate-limiter/useRateLimitedCallback.cjs.map +1 -1
  88. package/dist/rate-limiter/useRateLimitedCallback.d.cts +0 -1
  89. package/dist/rate-limiter/useRateLimitedCallback.d.ts +0 -1
  90. package/dist/rate-limiter/useRateLimitedCallback.js.map +1 -1
  91. package/dist/rate-limiter/useRateLimitedState.cjs.map +1 -1
  92. package/dist/rate-limiter/useRateLimitedState.d.cts +0 -1
  93. package/dist/rate-limiter/useRateLimitedState.d.ts +0 -1
  94. package/dist/rate-limiter/useRateLimitedState.js.map +1 -1
  95. package/dist/rate-limiter/useRateLimitedValue.cjs.map +1 -1
  96. package/dist/rate-limiter/useRateLimitedValue.d.cts +0 -1
  97. package/dist/rate-limiter/useRateLimitedValue.d.ts +0 -1
  98. package/dist/rate-limiter/useRateLimitedValue.js.map +1 -1
  99. package/dist/rate-limiter/useRateLimiter.cjs.map +1 -1
  100. package/dist/rate-limiter/useRateLimiter.d.cts +0 -1
  101. package/dist/rate-limiter/useRateLimiter.d.ts +0 -1
  102. package/dist/rate-limiter/useRateLimiter.js.map +1 -1
  103. package/dist/throttler/useThrottledCallback.cjs.map +1 -1
  104. package/dist/throttler/useThrottledCallback.d.cts +0 -1
  105. package/dist/throttler/useThrottledCallback.d.ts +0 -1
  106. package/dist/throttler/useThrottledCallback.js.map +1 -1
  107. package/dist/throttler/useThrottledState.cjs.map +1 -1
  108. package/dist/throttler/useThrottledState.d.cts +0 -1
  109. package/dist/throttler/useThrottledState.d.ts +0 -1
  110. package/dist/throttler/useThrottledState.js.map +1 -1
  111. package/dist/throttler/useThrottledValue.cjs.map +1 -1
  112. package/dist/throttler/useThrottledValue.d.cts +0 -1
  113. package/dist/throttler/useThrottledValue.d.ts +0 -1
  114. package/dist/throttler/useThrottledValue.js.map +1 -1
  115. package/dist/throttler/useThrottler.cjs.map +1 -1
  116. package/dist/throttler/useThrottler.d.cts +0 -1
  117. package/dist/throttler/useThrottler.d.ts +0 -1
  118. package/dist/throttler/useThrottler.js.map +1 -1
  119. package/dist/types/index.cjs +0 -1
  120. package/dist/utils/index.cjs +0 -1
  121. package/package.json +6 -6
  122. package/src/async-debouncer/useAsyncDebouncedCallback.ts +6 -5
  123. package/src/async-rate-limiter/useAsyncRateLimitedCallback.ts +2 -3
  124. package/src/async-throttler/useAsyncThrottledCallback.ts +7 -7
@@ -1,7 +1,5 @@
1
- import * as _$preact from "preact";
2
1
  import { ComponentChildren } from "preact";
3
2
  import { AnyAsyncFunction, AnyFunction, AsyncBatcherOptions, AsyncDebouncerOptions, AsyncQueuerOptions, AsyncRateLimiterOptions, AsyncThrottlerOptions, BatcherOptions, DebouncerOptions, QueuerOptions, RateLimiterOptions, ThrottlerOptions } from "@tanstack/pacer";
4
-
5
3
  //#region src/provider/PacerProvider.d.ts
6
4
  interface PacerProviderOptions {
7
5
  asyncBatcher?: Partial<AsyncBatcherOptions<any>>;
@@ -22,10 +20,7 @@ interface PacerProviderProps {
22
20
  children: ComponentChildren;
23
21
  defaultOptions?: PacerProviderOptions;
24
22
  }
25
- declare function PacerProvider({
26
- children,
27
- defaultOptions
28
- }: PacerProviderProps): _$preact.JSX.Element;
23
+ declare function PacerProvider({ children, defaultOptions }: PacerProviderProps): import("preact").JSX.Element;
29
24
  declare function usePacerContext(): PacerContextValue | null;
30
25
  declare function useDefaultPacerOptions(): PacerProviderOptions;
31
26
  //#endregion
@@ -1,7 +1,5 @@
1
1
  import { AnyAsyncFunction, AnyFunction, AsyncBatcherOptions, AsyncDebouncerOptions, AsyncQueuerOptions, AsyncRateLimiterOptions, AsyncThrottlerOptions, BatcherOptions, DebouncerOptions, QueuerOptions, RateLimiterOptions, ThrottlerOptions } from "@tanstack/pacer";
2
- import * as _$preact from "preact";
3
2
  import { ComponentChildren } from "preact";
4
-
5
3
  //#region src/provider/PacerProvider.d.ts
6
4
  interface PacerProviderOptions {
7
5
  asyncBatcher?: Partial<AsyncBatcherOptions<any>>;
@@ -22,10 +20,7 @@ interface PacerProviderProps {
22
20
  children: ComponentChildren;
23
21
  defaultOptions?: PacerProviderOptions;
24
22
  }
25
- declare function PacerProvider({
26
- children,
27
- defaultOptions
28
- }: PacerProviderProps): _$preact.JSX.Element;
23
+ declare function PacerProvider({ children, defaultOptions }: PacerProviderProps): import("preact").JSX.Element;
29
24
  declare function usePacerContext(): PacerContextValue | null;
30
25
  declare function useDefaultPacerOptions(): PacerProviderOptions;
31
26
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"PacerProvider.js","names":[],"sources":["../../src/provider/PacerProvider.tsx"],"sourcesContent":["import { useContext, useMemo } from 'preact/hooks'\nimport { createContext } from 'preact'\nimport type { ComponentChildren } from 'preact'\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: ComponentChildren\n defaultOptions?: PacerProviderOptions\n}\n\nconst DEFAULT_OPTIONS: PacerProviderOptions = {}\n\nexport function PacerProvider({\n children,\n defaultOptions = DEFAULT_OPTIONS,\n}: PacerProviderProps) {\n const contextValue: PacerContextValue = useMemo(\n () => ({\n defaultOptions,\n }),\n [defaultOptions],\n )\n\n return (\n <PacerContext.Provider value={contextValue}>\n {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"],"mappings":";;;;;AAmCA,MAAM,eAAe,cAAwC,KAAK;AAOlE,MAAM,kBAAwC,EAAE;AAEhD,SAAgB,cAAc,EAC5B,UACA,iBAAiB,mBACI;CACrB,MAAM,eAAkC,eAC/B,EACL,gBACD,GACD,CAAC,eAAe,CACjB;AAED,QACE,oBAAC,aAAa,UAAd;EAAuB,OAAO;EAC3B;EACqB;;AAI5B,SAAgB,kBAAkB;AAChC,QAAO,WAAW,aAAa;;AAGjC,SAAgB,yBAAyB;AAEvC,QADgB,WAAW,aAAa,EACxB,kBAAkB,EAAE"}
1
+ {"version":3,"file":"PacerProvider.js","names":[],"sources":["../../src/provider/PacerProvider.tsx"],"sourcesContent":["import { useContext, useMemo } from 'preact/hooks'\nimport { createContext } from 'preact'\nimport type { ComponentChildren } from 'preact'\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: ComponentChildren\n defaultOptions?: PacerProviderOptions\n}\n\nconst DEFAULT_OPTIONS: PacerProviderOptions = {}\n\nexport function PacerProvider({\n children,\n defaultOptions = DEFAULT_OPTIONS,\n}: PacerProviderProps) {\n const contextValue: PacerContextValue = useMemo(\n () => ({\n defaultOptions,\n }),\n [defaultOptions],\n )\n\n return (\n <PacerContext.Provider value={contextValue}>\n {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"],"mappings":";;;;;AAmCA,MAAM,eAAe,cAAwC,IAAI;AAOjE,MAAM,kBAAwC,CAAC;AAE/C,SAAgB,cAAc,EAC5B,UACA,iBAAiB,mBACI;CACrB,MAAM,eAAkC,eAC/B,EACL,eACF,IACA,CAAC,cAAc,CACjB;CAEA,OACE,oBAAC,aAAa,UAAd;EAAuB,OAAO;EAC3B;CACoB;AAE3B;AAEA,SAAgB,kBAAkB;CAChC,OAAO,WAAW,YAAY;AAChC;AAEA,SAAgB,yBAAyB;CAEvC,OADgB,WAAW,YACd,CAAC,EAAE,kBAAkB,CAAC;AACrC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useQueuedState.cjs","names":["useQueuer"],"sources":["../../src/queuer/useQueuedState.ts"],"sourcesContent":["import { useQueuer } from './useQueuer'\nimport type { PreactQueuer, PreactQueuerOptions } from './useQueuer'\nimport type { Queuer, QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * A Preact hook that creates a queuer with managed state, combining Preact's useState with queuing functionality.\n * This hook 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 hook.\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 hook 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 hook uses TanStack Store for 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] = useQueuedState(\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] = useQueuedState(\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] = useQueuedState(\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] = useQueuedState(\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 useQueuedState<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (item: TValue) => void,\n options: PreactQueuerOptions<TValue, TSelected> = {},\n selector?: (state: QueuerState<TValue>) => TSelected,\n): [Array<TValue>, Queuer<TValue>['addItem'], PreactQueuer<TValue, TSelected>] {\n const queue = useQueuer(fn, options, selector)\n\n return [queue.state.items, queue.addItem, queue]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsHA,SAAgB,eAOd,IACA,UAAkD,EAAE,EACpD,UAC6E;CAC7E,MAAM,QAAQA,4BAAU,IAAI,SAAS,SAAS;AAE9C,QAAO;EAAC,MAAM,MAAM;EAAO,MAAM;EAAS;EAAM"}
1
+ {"version":3,"file":"useQueuedState.cjs","names":["useQueuer"],"sources":["../../src/queuer/useQueuedState.ts"],"sourcesContent":["import { useQueuer } from './useQueuer'\nimport type { PreactQueuer, PreactQueuerOptions } from './useQueuer'\nimport type { Queuer, QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * A Preact hook that creates a queuer with managed state, combining Preact's useState with queuing functionality.\n * This hook 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 hook.\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 hook 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 hook uses TanStack Store for 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] = useQueuedState(\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] = useQueuedState(\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] = useQueuedState(\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] = useQueuedState(\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 useQueuedState<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (item: TValue) => void,\n options: PreactQueuerOptions<TValue, TSelected> = {},\n selector?: (state: QueuerState<TValue>) => TSelected,\n): [Array<TValue>, Queuer<TValue>['addItem'], PreactQueuer<TValue, TSelected>] {\n const queue = useQueuer(fn, options, selector)\n\n return [queue.state.items, queue.addItem, queue]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsHA,SAAgB,eAOd,IACA,UAAkD,CAAC,GACnD,UAC6E;CAC7E,MAAM,QAAQA,4BAAU,IAAI,SAAS,QAAQ;CAE7C,OAAO;EAAC,MAAM,MAAM;EAAO,MAAM;EAAS;CAAK;AACjD"}
@@ -1,6 +1,5 @@
1
1
  import { PreactQueuer, PreactQueuerOptions } from "./useQueuer.cjs";
2
2
  import { Queuer, QueuerState } from "@tanstack/pacer/queuer";
3
-
4
3
  //#region src/queuer/useQueuedState.d.ts
5
4
  /**
6
5
  * A Preact hook that creates a queuer with managed state, combining Preact's useState with queuing functionality.
@@ -1,6 +1,5 @@
1
1
  import { PreactQueuer, PreactQueuerOptions } from "./useQueuer.js";
2
2
  import { Queuer, QueuerState } from "@tanstack/pacer/queuer";
3
-
4
3
  //#region src/queuer/useQueuedState.d.ts
5
4
  /**
6
5
  * A Preact hook that creates a queuer with managed state, combining Preact's useState with queuing functionality.
@@ -1 +1 @@
1
- {"version":3,"file":"useQueuedState.js","names":[],"sources":["../../src/queuer/useQueuedState.ts"],"sourcesContent":["import { useQueuer } from './useQueuer'\nimport type { PreactQueuer, PreactQueuerOptions } from './useQueuer'\nimport type { Queuer, QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * A Preact hook that creates a queuer with managed state, combining Preact's useState with queuing functionality.\n * This hook 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 hook.\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 hook 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 hook uses TanStack Store for 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] = useQueuedState(\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] = useQueuedState(\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] = useQueuedState(\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] = useQueuedState(\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 useQueuedState<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (item: TValue) => void,\n options: PreactQueuerOptions<TValue, TSelected> = {},\n selector?: (state: QueuerState<TValue>) => TSelected,\n): [Array<TValue>, Queuer<TValue>['addItem'], PreactQueuer<TValue, TSelected>] {\n const queue = useQueuer(fn, options, selector)\n\n return [queue.state.items, queue.addItem, queue]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsHA,SAAgB,eAOd,IACA,UAAkD,EAAE,EACpD,UAC6E;CAC7E,MAAM,QAAQ,UAAU,IAAI,SAAS,SAAS;AAE9C,QAAO;EAAC,MAAM,MAAM;EAAO,MAAM;EAAS;EAAM"}
1
+ {"version":3,"file":"useQueuedState.js","names":[],"sources":["../../src/queuer/useQueuedState.ts"],"sourcesContent":["import { useQueuer } from './useQueuer'\nimport type { PreactQueuer, PreactQueuerOptions } from './useQueuer'\nimport type { Queuer, QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * A Preact hook that creates a queuer with managed state, combining Preact's useState with queuing functionality.\n * This hook 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 hook.\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 hook 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 hook uses TanStack Store for 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] = useQueuedState(\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] = useQueuedState(\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] = useQueuedState(\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] = useQueuedState(\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 useQueuedState<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (item: TValue) => void,\n options: PreactQueuerOptions<TValue, TSelected> = {},\n selector?: (state: QueuerState<TValue>) => TSelected,\n): [Array<TValue>, Queuer<TValue>['addItem'], PreactQueuer<TValue, TSelected>] {\n const queue = useQueuer(fn, options, selector)\n\n return [queue.state.items, queue.addItem, queue]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsHA,SAAgB,eAOd,IACA,UAAkD,CAAC,GACnD,UAC6E;CAC7E,MAAM,QAAQ,UAAU,IAAI,SAAS,QAAQ;CAE7C,OAAO;EAAC,MAAM,MAAM;EAAO,MAAM;EAAS;CAAK;AACjD"}
@@ -1 +1 @@
1
- {"version":3,"file":"useQueuedValue.cjs","names":["useQueuedState"],"sources":["../../src/queuer/useQueuedValue.ts"],"sourcesContent":["import { useEffect, useState } from 'preact/hooks'\nimport { useQueuedState } from './useQueuedState'\nimport type { PreactQueuer, PreactQueuerOptions } from './useQueuer'\nimport type { QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * A Preact hook that creates a queued value that processes state changes in order with an optional delay.\n * This hook uses useQueuer internally to manage a queue of state changes and apply them sequentially.\n *\n * The queued value will process changes in the order they are received, with optional delays between\n * processing each change. This is useful for handling state updates that need to be processed\n * in a specific order, like animations or sequential UI updates.\n *\n * The hook returns a tuple containing:\n * - The current queued value\n * - The queuer instance with control methods\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for 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 [value, queuer] = useQueuedValue(initialValue, {\n * wait: 500, // Wait 500ms between processing each change\n * started: true // Start processing immediately\n * });\n *\n * // Opt-in to re-render when queue processing state changes (optimized for loading indicators)\n * const [value, queuer] = useQueuedValue(\n * initialValue,\n * { wait: 500, started: true },\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 queue contents change (optimized for displaying queue status)\n * const [value, queuer] = useQueuedValue(\n * initialValue,\n * { wait: 500, started: true },\n * (state) => ({\n * size: state.size,\n * isEmpty: state.isEmpty,\n * isFull: state.isFull\n * })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for stats display)\n * const [value, queuer] = useQueuedValue(\n * initialValue,\n * { wait: 500, started: true },\n * (state) => ({\n * executionCount: state.executionCount,\n * expirationCount: state.expirationCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Add changes to the queue\n * const handleChange = (newValue) => {\n * queuer.addItem(newValue);\n * };\n *\n * // Control the queue\n * const pauseProcessing = () => {\n * queuer.stop();\n * };\n *\n * const resumeProcessing = () => {\n * queuer.start();\n * };\n *\n * // Access the selected queuer state (will be empty object {} unless selector provided)\n * const { size, isRunning, executionCount } = queuer.state;\n * ```\n */\nexport function useQueuedValue<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n initialValue: TValue,\n options: PreactQueuerOptions<TValue, TSelected> = {},\n selector?: (state: QueuerState<TValue>) => TSelected,\n): [TValue, PreactQueuer<TValue, TSelected>] {\n const [value, setValue] = useState<TValue>(initialValue)\n\n const [, addItem, queuer] = useQueuedState(\n (item) => {\n setValue(item)\n },\n options,\n selector,\n )\n\n useEffect(() => {\n addItem(initialValue)\n }, [initialValue, addItem])\n\n return [value, queuer]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,SAAgB,eAOd,cACA,UAAkD,EAAE,EACpD,UAC2C;CAC3C,MAAM,CAAC,OAAO,uCAA6B,aAAa;CAExD,MAAM,GAAG,SAAS,UAAUA,uCACzB,SAAS;AACR,WAAS,KAAK;IAEhB,SACA,SACD;AAED,mCAAgB;AACd,UAAQ,aAAa;IACpB,CAAC,cAAc,QAAQ,CAAC;AAE3B,QAAO,CAAC,OAAO,OAAO"}
1
+ {"version":3,"file":"useQueuedValue.cjs","names":["useState","useQueuedState"],"sources":["../../src/queuer/useQueuedValue.ts"],"sourcesContent":["import { useEffect, useState } from 'preact/hooks'\nimport { useQueuedState } from './useQueuedState'\nimport type { PreactQueuer, PreactQueuerOptions } from './useQueuer'\nimport type { QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * A Preact hook that creates a queued value that processes state changes in order with an optional delay.\n * This hook uses useQueuer internally to manage a queue of state changes and apply them sequentially.\n *\n * The queued value will process changes in the order they are received, with optional delays between\n * processing each change. This is useful for handling state updates that need to be processed\n * in a specific order, like animations or sequential UI updates.\n *\n * The hook returns a tuple containing:\n * - The current queued value\n * - The queuer instance with control methods\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for 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 [value, queuer] = useQueuedValue(initialValue, {\n * wait: 500, // Wait 500ms between processing each change\n * started: true // Start processing immediately\n * });\n *\n * // Opt-in to re-render when queue processing state changes (optimized for loading indicators)\n * const [value, queuer] = useQueuedValue(\n * initialValue,\n * { wait: 500, started: true },\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 queue contents change (optimized for displaying queue status)\n * const [value, queuer] = useQueuedValue(\n * initialValue,\n * { wait: 500, started: true },\n * (state) => ({\n * size: state.size,\n * isEmpty: state.isEmpty,\n * isFull: state.isFull\n * })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for stats display)\n * const [value, queuer] = useQueuedValue(\n * initialValue,\n * { wait: 500, started: true },\n * (state) => ({\n * executionCount: state.executionCount,\n * expirationCount: state.expirationCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Add changes to the queue\n * const handleChange = (newValue) => {\n * queuer.addItem(newValue);\n * };\n *\n * // Control the queue\n * const pauseProcessing = () => {\n * queuer.stop();\n * };\n *\n * const resumeProcessing = () => {\n * queuer.start();\n * };\n *\n * // Access the selected queuer state (will be empty object {} unless selector provided)\n * const { size, isRunning, executionCount } = queuer.state;\n * ```\n */\nexport function useQueuedValue<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n initialValue: TValue,\n options: PreactQueuerOptions<TValue, TSelected> = {},\n selector?: (state: QueuerState<TValue>) => TSelected,\n): [TValue, PreactQueuer<TValue, TSelected>] {\n const [value, setValue] = useState<TValue>(initialValue)\n\n const [, addItem, queuer] = useQueuedState(\n (item) => {\n setValue(item)\n },\n options,\n selector,\n )\n\n useEffect(() => {\n addItem(initialValue)\n }, [initialValue, addItem])\n\n return [value, queuer]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,SAAgB,eAOd,cACA,UAAkD,CAAC,GACnD,UAC2C;CAC3C,MAAM,CAAC,OAAO,gBAAYA,uBAAiB,YAAY;CAEvD,MAAM,GAAG,SAAS,UAAUC,uCACzB,SAAS;EACR,SAAS,IAAI;CACf,GACA,SACA,QACF;CAEA,kCAAgB;EACd,QAAQ,YAAY;CACtB,GAAG,CAAC,cAAc,OAAO,CAAC;CAE1B,OAAO,CAAC,OAAO,MAAM;AACvB"}
@@ -1,6 +1,5 @@
1
1
  import { PreactQueuer, PreactQueuerOptions } from "./useQueuer.cjs";
2
2
  import { QueuerState } from "@tanstack/pacer/queuer";
3
-
4
3
  //#region src/queuer/useQueuedValue.d.ts
5
4
  /**
6
5
  * A Preact hook that creates a queued value that processes state changes in order with an optional delay.
@@ -1,6 +1,5 @@
1
1
  import { PreactQueuer, PreactQueuerOptions } from "./useQueuer.js";
2
2
  import { QueuerState } from "@tanstack/pacer/queuer";
3
-
4
3
  //#region src/queuer/useQueuedValue.d.ts
5
4
  /**
6
5
  * A Preact hook that creates a queued value that processes state changes in order with an optional delay.
@@ -1 +1 @@
1
- {"version":3,"file":"useQueuedValue.js","names":[],"sources":["../../src/queuer/useQueuedValue.ts"],"sourcesContent":["import { useEffect, useState } from 'preact/hooks'\nimport { useQueuedState } from './useQueuedState'\nimport type { PreactQueuer, PreactQueuerOptions } from './useQueuer'\nimport type { QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * A Preact hook that creates a queued value that processes state changes in order with an optional delay.\n * This hook uses useQueuer internally to manage a queue of state changes and apply them sequentially.\n *\n * The queued value will process changes in the order they are received, with optional delays between\n * processing each change. This is useful for handling state updates that need to be processed\n * in a specific order, like animations or sequential UI updates.\n *\n * The hook returns a tuple containing:\n * - The current queued value\n * - The queuer instance with control methods\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for 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 [value, queuer] = useQueuedValue(initialValue, {\n * wait: 500, // Wait 500ms between processing each change\n * started: true // Start processing immediately\n * });\n *\n * // Opt-in to re-render when queue processing state changes (optimized for loading indicators)\n * const [value, queuer] = useQueuedValue(\n * initialValue,\n * { wait: 500, started: true },\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 queue contents change (optimized for displaying queue status)\n * const [value, queuer] = useQueuedValue(\n * initialValue,\n * { wait: 500, started: true },\n * (state) => ({\n * size: state.size,\n * isEmpty: state.isEmpty,\n * isFull: state.isFull\n * })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for stats display)\n * const [value, queuer] = useQueuedValue(\n * initialValue,\n * { wait: 500, started: true },\n * (state) => ({\n * executionCount: state.executionCount,\n * expirationCount: state.expirationCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Add changes to the queue\n * const handleChange = (newValue) => {\n * queuer.addItem(newValue);\n * };\n *\n * // Control the queue\n * const pauseProcessing = () => {\n * queuer.stop();\n * };\n *\n * const resumeProcessing = () => {\n * queuer.start();\n * };\n *\n * // Access the selected queuer state (will be empty object {} unless selector provided)\n * const { size, isRunning, executionCount } = queuer.state;\n * ```\n */\nexport function useQueuedValue<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n initialValue: TValue,\n options: PreactQueuerOptions<TValue, TSelected> = {},\n selector?: (state: QueuerState<TValue>) => TSelected,\n): [TValue, PreactQueuer<TValue, TSelected>] {\n const [value, setValue] = useState<TValue>(initialValue)\n\n const [, addItem, queuer] = useQueuedState(\n (item) => {\n setValue(item)\n },\n options,\n selector,\n )\n\n useEffect(() => {\n addItem(initialValue)\n }, [initialValue, addItem])\n\n return [value, queuer]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,SAAgB,eAOd,cACA,UAAkD,EAAE,EACpD,UAC2C;CAC3C,MAAM,CAAC,OAAO,YAAY,SAAiB,aAAa;CAExD,MAAM,GAAG,SAAS,UAAU,gBACzB,SAAS;AACR,WAAS,KAAK;IAEhB,SACA,SACD;AAED,iBAAgB;AACd,UAAQ,aAAa;IACpB,CAAC,cAAc,QAAQ,CAAC;AAE3B,QAAO,CAAC,OAAO,OAAO"}
1
+ {"version":3,"file":"useQueuedValue.js","names":[],"sources":["../../src/queuer/useQueuedValue.ts"],"sourcesContent":["import { useEffect, useState } from 'preact/hooks'\nimport { useQueuedState } from './useQueuedState'\nimport type { PreactQueuer, PreactQueuerOptions } from './useQueuer'\nimport type { QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * A Preact hook that creates a queued value that processes state changes in order with an optional delay.\n * This hook uses useQueuer internally to manage a queue of state changes and apply them sequentially.\n *\n * The queued value will process changes in the order they are received, with optional delays between\n * processing each change. This is useful for handling state updates that need to be processed\n * in a specific order, like animations or sequential UI updates.\n *\n * The hook returns a tuple containing:\n * - The current queued value\n * - The queuer instance with control methods\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for 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 [value, queuer] = useQueuedValue(initialValue, {\n * wait: 500, // Wait 500ms between processing each change\n * started: true // Start processing immediately\n * });\n *\n * // Opt-in to re-render when queue processing state changes (optimized for loading indicators)\n * const [value, queuer] = useQueuedValue(\n * initialValue,\n * { wait: 500, started: true },\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 queue contents change (optimized for displaying queue status)\n * const [value, queuer] = useQueuedValue(\n * initialValue,\n * { wait: 500, started: true },\n * (state) => ({\n * size: state.size,\n * isEmpty: state.isEmpty,\n * isFull: state.isFull\n * })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for stats display)\n * const [value, queuer] = useQueuedValue(\n * initialValue,\n * { wait: 500, started: true },\n * (state) => ({\n * executionCount: state.executionCount,\n * expirationCount: state.expirationCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Add changes to the queue\n * const handleChange = (newValue) => {\n * queuer.addItem(newValue);\n * };\n *\n * // Control the queue\n * const pauseProcessing = () => {\n * queuer.stop();\n * };\n *\n * const resumeProcessing = () => {\n * queuer.start();\n * };\n *\n * // Access the selected queuer state (will be empty object {} unless selector provided)\n * const { size, isRunning, executionCount } = queuer.state;\n * ```\n */\nexport function useQueuedValue<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n initialValue: TValue,\n options: PreactQueuerOptions<TValue, TSelected> = {},\n selector?: (state: QueuerState<TValue>) => TSelected,\n): [TValue, PreactQueuer<TValue, TSelected>] {\n const [value, setValue] = useState<TValue>(initialValue)\n\n const [, addItem, queuer] = useQueuedState(\n (item) => {\n setValue(item)\n },\n options,\n selector,\n )\n\n useEffect(() => {\n addItem(initialValue)\n }, [initialValue, addItem])\n\n return [value, queuer]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,SAAgB,eAOd,cACA,UAAkD,CAAC,GACnD,UAC2C;CAC3C,MAAM,CAAC,OAAO,YAAY,SAAiB,YAAY;CAEvD,MAAM,GAAG,SAAS,UAAU,gBACzB,SAAS;EACR,SAAS,IAAI;CACf,GACA,SACA,QACF;CAEA,gBAAgB;EACd,QAAQ,YAAY;CACtB,GAAG,CAAC,cAAc,OAAO,CAAC;CAE1B,OAAO,CAAC,OAAO,MAAM;AACvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"useQueuer.cjs","names":["useDefaultPacerOptions","Queuer","shallow"],"sources":["../../src/queuer/useQueuer.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'preact/hooks'\nimport { Queuer } from '@tanstack/pacer/queuer'\nimport { shallow, useSelector } from '@tanstack/preact-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/preact-store'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\nimport type { ComponentChildren } from 'preact'\n\nexport interface PreactQueuerOptions<\n TValue,\n TSelected = {},\n> extends QueuerOptions<TValue> {\n /**\n * Optional callback invoked when the component unmounts. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop); use it to call flush(), flushAsBatch(), stop(), add logging, etc.\n */\n onUnmount?: (queuer: PreactQueuer<TValue, TSelected>) => void\n}\n\nexport interface PreactQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * A Preact HOC (Higher Order Component) that allows you to subscribe to the queuer state.\n *\n * This is useful for opting into state re-renders for specific parts of the queuer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <queuer.Subscribe selector={(state) => ({ size: state.size })}>\n * {({ size }) => (\n * <div>Queue Size: {size}</div>\n * )}\n * </queuer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) => ComponentChildren\n /**\n * Reactive state that will be updated and re-rendered when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: 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 `useSelector` hook internally.\n * Although, you can make the state reactive by using the `useSelector` in your own usage.\n */\n readonly store: Store<Readonly<QueuerState<TValue>>>\n}\n\n/**\n * A Preact 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 (useState, Redux, Zustand, etc.) by utilizing the onItemsChange callback.\n *\n * For a hook with built-in state management, see useQueuedState.\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 * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `queuer.Subscribe` HOC (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` HOC to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger a re-render\n * at the hook level, optimizing performance by preventing unnecessary re-renders when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` HOC. This prevents unnecessary\n * re-renders and gives you full control over when your component updates.\n *\n * Available 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 * ## Unmount behavior\n *\n * By default, the hook stops the queuer when the component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending items instead:\n *\n * ```tsx\n * const queue = useQueuer(fn, {\n * started: true,\n * wait: 1000,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const queue = useQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 }\n * );\n *\n * // Subscribe to state changes deep in component tree using Subscribe HOC\n * <queue.Subscribe selector={(state) => ({ size: state.size })}>\n * {({ size }) => (\n * <div>Queue Size: {size}</div>\n * )}\n * </queue.Subscribe>\n *\n * // Opt-in to re-render when queue size changes at hook level (optimized for displaying queue length)\n * const queue = useQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * size: state.size,\n * isEmpty: state.isEmpty,\n * isFull: state.isFull\n * })\n * );\n *\n * // Opt-in to re-render when processing state changes (optimized for loading indicators)\n * const queue = useQueuer(\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 queue = useQueuer(\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 * // Example with custom state management and scheduling\n * const [items, setItems] = useState([]);\n *\n * const queue = useQueuer(\n * (item) => console.log('Processing:', item),\n * {\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * onItemsChange: (queue) => setItems(queue.peekAllItems()),\n * getPriority: (item) => item.priority // Process higher priority items first\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 { size, isRunning, executionCount } = queue.state;\n * ```\n */\nexport function useQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: PreactQueuerOptions<TValue, TSelected> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): PreactQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().queuer,\n ...options,\n } as PreactQueuerOptions<TValue, TSelected>\n\n const [queuer] = useState(() => {\n const queuerInstance = new Queuer<TValue>(\n fn,\n mergedOptions,\n ) as unknown as PreactQueuer<TValue, TSelected>\n\n queuerInstance.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) {\n const selected = useSelector(queuerInstance.store, props.selector, {\n compare: shallow,\n })\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n return queuerInstance\n })\n\n queuer.fn = fn\n queuer.setOptions(mergedOptions)\n\n /* eslint-disable react-hooks/exhaustive-deps -- cleanup only; runs on unmount */\n useEffect(() => {\n return () => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(queuer)\n } else {\n queuer.stop()\n }\n }\n }, [])\n /* eslint-enable react-hooks/exhaustive-deps */\n\n const state = useSelector(queuer.store, selector, { compare: shallow })\n\n return useMemo(\n () =>\n ({\n ...queuer,\n state,\n }) as PreactQueuer<TValue, TSelected>, // omit `store` in favor of `state`\n [queuer, state],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiMA,SAAgB,UACd,IACA,UAAkD,EAAE,EACpD,kBAA6D,EAAE,GAC9B;CACjC,MAAM,gBAAgB;EACpB,GAAGA,8CAAwB,CAAC;EAC5B,GAAG;EACJ;CAED,MAAM,CAAC,2CAAyB;EAC9B,MAAM,iBAAiB,IAAIC,8BACzB,IACA,cACD;AAED,iBAAe,YAAY,SAAS,UAAqB,OAGtD;GACD,MAAM,mDAAuB,eAAe,OAAO,MAAM,UAAU,EACjE,SAASC,gCACV,CAAC;AAEF,UAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;AAGZ,SAAO;GACP;AAEF,QAAO,KAAK;AACZ,QAAO,WAAW,cAAc;AAGhC,mCAAgB;AACd,eAAa;AACX,OAAI,cAAc,UAChB,eAAc,UAAU,OAAO;OAE/B,QAAO,MAAM;;IAGhB,EAAE,CAAC;CAGN,MAAM,gDAAoB,OAAO,OAAO,UAAU,EAAE,SAASA,gCAAS,CAAC;AAEvE,yCAEK;EACC,GAAG;EACH;EACD,GACH,CAAC,QAAQ,MAAM,CAChB"}
1
+ {"version":3,"file":"useQueuer.cjs","names":["useDefaultPacerOptions","useState","Queuer","useSelector","shallow","useMemo"],"sources":["../../src/queuer/useQueuer.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'preact/hooks'\nimport { Queuer } from '@tanstack/pacer/queuer'\nimport { shallow, useSelector } from '@tanstack/preact-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/preact-store'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\nimport type { ComponentChildren } from 'preact'\n\nexport interface PreactQueuerOptions<\n TValue,\n TSelected = {},\n> extends QueuerOptions<TValue> {\n /**\n * Optional callback invoked when the component unmounts. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop); use it to call flush(), flushAsBatch(), stop(), add logging, etc.\n */\n onUnmount?: (queuer: PreactQueuer<TValue, TSelected>) => void\n}\n\nexport interface PreactQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * A Preact HOC (Higher Order Component) that allows you to subscribe to the queuer state.\n *\n * This is useful for opting into state re-renders for specific parts of the queuer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <queuer.Subscribe selector={(state) => ({ size: state.size })}>\n * {({ size }) => (\n * <div>Queue Size: {size}</div>\n * )}\n * </queuer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) => ComponentChildren\n /**\n * Reactive state that will be updated and re-rendered when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: 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 `useSelector` hook internally.\n * Although, you can make the state reactive by using the `useSelector` in your own usage.\n */\n readonly store: Store<Readonly<QueuerState<TValue>>>\n}\n\n/**\n * A Preact 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 (useState, Redux, Zustand, etc.) by utilizing the onItemsChange callback.\n *\n * For a hook with built-in state management, see useQueuedState.\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 * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `queuer.Subscribe` HOC (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` HOC to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger a re-render\n * at the hook level, optimizing performance by preventing unnecessary re-renders when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` HOC. This prevents unnecessary\n * re-renders and gives you full control over when your component updates.\n *\n * Available 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 * ## Unmount behavior\n *\n * By default, the hook stops the queuer when the component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending items instead:\n *\n * ```tsx\n * const queue = useQueuer(fn, {\n * started: true,\n * wait: 1000,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const queue = useQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 }\n * );\n *\n * // Subscribe to state changes deep in component tree using Subscribe HOC\n * <queue.Subscribe selector={(state) => ({ size: state.size })}>\n * {({ size }) => (\n * <div>Queue Size: {size}</div>\n * )}\n * </queue.Subscribe>\n *\n * // Opt-in to re-render when queue size changes at hook level (optimized for displaying queue length)\n * const queue = useQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * size: state.size,\n * isEmpty: state.isEmpty,\n * isFull: state.isFull\n * })\n * );\n *\n * // Opt-in to re-render when processing state changes (optimized for loading indicators)\n * const queue = useQueuer(\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 queue = useQueuer(\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 * // Example with custom state management and scheduling\n * const [items, setItems] = useState([]);\n *\n * const queue = useQueuer(\n * (item) => console.log('Processing:', item),\n * {\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * onItemsChange: (queue) => setItems(queue.peekAllItems()),\n * getPriority: (item) => item.priority // Process higher priority items first\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 { size, isRunning, executionCount } = queue.state;\n * ```\n */\nexport function useQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: PreactQueuerOptions<TValue, TSelected> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): PreactQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().queuer,\n ...options,\n } as PreactQueuerOptions<TValue, TSelected>\n\n const [queuer] = useState(() => {\n const queuerInstance = new Queuer<TValue>(\n fn,\n mergedOptions,\n ) as unknown as PreactQueuer<TValue, TSelected>\n\n queuerInstance.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) {\n const selected = useSelector(queuerInstance.store, props.selector, {\n compare: shallow,\n })\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n return queuerInstance\n })\n\n queuer.fn = fn\n queuer.setOptions(mergedOptions)\n\n /* eslint-disable react-hooks/exhaustive-deps -- cleanup only; runs on unmount */\n useEffect(() => {\n return () => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(queuer)\n } else {\n queuer.stop()\n }\n }\n }, [])\n /* eslint-enable react-hooks/exhaustive-deps */\n\n const state = useSelector(queuer.store, selector, { compare: shallow })\n\n return useMemo(\n () =>\n ({\n ...queuer,\n state,\n }) as PreactQueuer<TValue, TSelected>, // omit `store` in favor of `state`\n [queuer, state],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiMA,SAAgB,UACd,IACA,UAAkD,CAAC,GACnD,kBAA6D,CAAC,IAC7B;CACjC,MAAM,gBAAgB;EACpB,GAAGA,6CAAuB,CAAC,CAAC;EAC5B,GAAG;CACL;CAEA,MAAM,CAAC,cAAUC,6BAAe;EAC9B,MAAM,iBAAiB,IAAIC,8BACzB,IACA,aACF;EAEA,eAAe,YAAY,SAAS,UAAqB,OAGtD;GACD,MAAM,eAAWC,oCAAY,eAAe,OAAO,MAAM,UAAU,EACjE,SAASC,+BACX,CAAC;GAED,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,QAAQ,IACvB,MAAM;EACZ;EAEA,OAAO;CACT,CAAC;CAED,OAAO,KAAK;CACZ,OAAO,WAAW,aAAa;CAG/B,kCAAgB;EACd,aAAa;GACX,IAAI,cAAc,WAChB,cAAc,UAAU,MAAM;QAE9B,OAAO,KAAK;EAEhB;CACF,GAAG,CAAC,CAAC;CAGL,MAAM,YAAQD,oCAAY,OAAO,OAAO,UAAU,EAAE,SAASC,+BAAQ,CAAC;CAEtE,WAAOC,6BAEF;EACC,GAAG;EACH;CACF,IACF,CAAC,QAAQ,KAAK,CAChB;AACF"}
@@ -1,7 +1,6 @@
1
1
  import { Store } from "@tanstack/preact-store";
2
2
  import { ComponentChildren } from "preact";
3
3
  import { Queuer, QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
4
-
5
4
  //#region src/queuer/useQueuer.d.ts
6
5
  interface PreactQueuerOptions<TValue, TSelected = {}> extends QueuerOptions<TValue> {
7
6
  /**
@@ -1,7 +1,6 @@
1
1
  import { ComponentChildren } from "preact";
2
2
  import { Store } from "@tanstack/preact-store";
3
3
  import { Queuer, QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
4
-
5
4
  //#region src/queuer/useQueuer.d.ts
6
5
  interface PreactQueuerOptions<TValue, TSelected = {}> extends QueuerOptions<TValue> {
7
6
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"useQueuer.js","names":[],"sources":["../../src/queuer/useQueuer.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'preact/hooks'\nimport { Queuer } from '@tanstack/pacer/queuer'\nimport { shallow, useSelector } from '@tanstack/preact-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/preact-store'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\nimport type { ComponentChildren } from 'preact'\n\nexport interface PreactQueuerOptions<\n TValue,\n TSelected = {},\n> extends QueuerOptions<TValue> {\n /**\n * Optional callback invoked when the component unmounts. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop); use it to call flush(), flushAsBatch(), stop(), add logging, etc.\n */\n onUnmount?: (queuer: PreactQueuer<TValue, TSelected>) => void\n}\n\nexport interface PreactQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * A Preact HOC (Higher Order Component) that allows you to subscribe to the queuer state.\n *\n * This is useful for opting into state re-renders for specific parts of the queuer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <queuer.Subscribe selector={(state) => ({ size: state.size })}>\n * {({ size }) => (\n * <div>Queue Size: {size}</div>\n * )}\n * </queuer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) => ComponentChildren\n /**\n * Reactive state that will be updated and re-rendered when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: 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 `useSelector` hook internally.\n * Although, you can make the state reactive by using the `useSelector` in your own usage.\n */\n readonly store: Store<Readonly<QueuerState<TValue>>>\n}\n\n/**\n * A Preact 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 (useState, Redux, Zustand, etc.) by utilizing the onItemsChange callback.\n *\n * For a hook with built-in state management, see useQueuedState.\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 * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `queuer.Subscribe` HOC (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` HOC to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger a re-render\n * at the hook level, optimizing performance by preventing unnecessary re-renders when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` HOC. This prevents unnecessary\n * re-renders and gives you full control over when your component updates.\n *\n * Available 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 * ## Unmount behavior\n *\n * By default, the hook stops the queuer when the component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending items instead:\n *\n * ```tsx\n * const queue = useQueuer(fn, {\n * started: true,\n * wait: 1000,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const queue = useQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 }\n * );\n *\n * // Subscribe to state changes deep in component tree using Subscribe HOC\n * <queue.Subscribe selector={(state) => ({ size: state.size })}>\n * {({ size }) => (\n * <div>Queue Size: {size}</div>\n * )}\n * </queue.Subscribe>\n *\n * // Opt-in to re-render when queue size changes at hook level (optimized for displaying queue length)\n * const queue = useQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * size: state.size,\n * isEmpty: state.isEmpty,\n * isFull: state.isFull\n * })\n * );\n *\n * // Opt-in to re-render when processing state changes (optimized for loading indicators)\n * const queue = useQueuer(\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 queue = useQueuer(\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 * // Example with custom state management and scheduling\n * const [items, setItems] = useState([]);\n *\n * const queue = useQueuer(\n * (item) => console.log('Processing:', item),\n * {\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * onItemsChange: (queue) => setItems(queue.peekAllItems()),\n * getPriority: (item) => item.priority // Process higher priority items first\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 { size, isRunning, executionCount } = queue.state;\n * ```\n */\nexport function useQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: PreactQueuerOptions<TValue, TSelected> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): PreactQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().queuer,\n ...options,\n } as PreactQueuerOptions<TValue, TSelected>\n\n const [queuer] = useState(() => {\n const queuerInstance = new Queuer<TValue>(\n fn,\n mergedOptions,\n ) as unknown as PreactQueuer<TValue, TSelected>\n\n queuerInstance.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) {\n const selected = useSelector(queuerInstance.store, props.selector, {\n compare: shallow,\n })\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n return queuerInstance\n })\n\n queuer.fn = fn\n queuer.setOptions(mergedOptions)\n\n /* eslint-disable react-hooks/exhaustive-deps -- cleanup only; runs on unmount */\n useEffect(() => {\n return () => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(queuer)\n } else {\n queuer.stop()\n }\n }\n }, [])\n /* eslint-enable react-hooks/exhaustive-deps */\n\n const state = useSelector(queuer.store, selector, { compare: shallow })\n\n return useMemo(\n () =>\n ({\n ...queuer,\n state,\n }) as PreactQueuer<TValue, TSelected>, // omit `store` in favor of `state`\n [queuer, state],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiMA,SAAgB,UACd,IACA,UAAkD,EAAE,EACpD,kBAA6D,EAAE,GAC9B;CACjC,MAAM,gBAAgB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ;CAED,MAAM,CAAC,UAAU,eAAe;EAC9B,MAAM,iBAAiB,IAAI,OACzB,IACA,cACD;AAED,iBAAe,YAAY,SAAS,UAAqB,OAGtD;GACD,MAAM,WAAW,YAAY,eAAe,OAAO,MAAM,UAAU,EACjE,SAAS,SACV,CAAC;AAEF,UAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;AAGZ,SAAO;GACP;AAEF,QAAO,KAAK;AACZ,QAAO,WAAW,cAAc;AAGhC,iBAAgB;AACd,eAAa;AACX,OAAI,cAAc,UAChB,eAAc,UAAU,OAAO;OAE/B,QAAO,MAAM;;IAGhB,EAAE,CAAC;CAGN,MAAM,QAAQ,YAAY,OAAO,OAAO,UAAU,EAAE,SAAS,SAAS,CAAC;AAEvE,QAAO,eAEF;EACC,GAAG;EACH;EACD,GACH,CAAC,QAAQ,MAAM,CAChB"}
1
+ {"version":3,"file":"useQueuer.js","names":[],"sources":["../../src/queuer/useQueuer.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'preact/hooks'\nimport { Queuer } from '@tanstack/pacer/queuer'\nimport { shallow, useSelector } from '@tanstack/preact-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/preact-store'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\nimport type { ComponentChildren } from 'preact'\n\nexport interface PreactQueuerOptions<\n TValue,\n TSelected = {},\n> extends QueuerOptions<TValue> {\n /**\n * Optional callback invoked when the component unmounts. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop); use it to call flush(), flushAsBatch(), stop(), add logging, etc.\n */\n onUnmount?: (queuer: PreactQueuer<TValue, TSelected>) => void\n}\n\nexport interface PreactQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * A Preact HOC (Higher Order Component) that allows you to subscribe to the queuer state.\n *\n * This is useful for opting into state re-renders for specific parts of the queuer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <queuer.Subscribe selector={(state) => ({ size: state.size })}>\n * {({ size }) => (\n * <div>Queue Size: {size}</div>\n * )}\n * </queuer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) => ComponentChildren\n /**\n * Reactive state that will be updated and re-rendered when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: 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 `useSelector` hook internally.\n * Although, you can make the state reactive by using the `useSelector` in your own usage.\n */\n readonly store: Store<Readonly<QueuerState<TValue>>>\n}\n\n/**\n * A Preact 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 (useState, Redux, Zustand, etc.) by utilizing the onItemsChange callback.\n *\n * For a hook with built-in state management, see useQueuedState.\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 * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `queuer.Subscribe` HOC (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` HOC to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger a re-render\n * at the hook level, optimizing performance by preventing unnecessary re-renders when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` HOC. This prevents unnecessary\n * re-renders and gives you full control over when your component updates.\n *\n * Available 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 * ## Unmount behavior\n *\n * By default, the hook stops the queuer when the component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending items instead:\n *\n * ```tsx\n * const queue = useQueuer(fn, {\n * started: true,\n * wait: 1000,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const queue = useQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 }\n * );\n *\n * // Subscribe to state changes deep in component tree using Subscribe HOC\n * <queue.Subscribe selector={(state) => ({ size: state.size })}>\n * {({ size }) => (\n * <div>Queue Size: {size}</div>\n * )}\n * </queue.Subscribe>\n *\n * // Opt-in to re-render when queue size changes at hook level (optimized for displaying queue length)\n * const queue = useQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * size: state.size,\n * isEmpty: state.isEmpty,\n * isFull: state.isFull\n * })\n * );\n *\n * // Opt-in to re-render when processing state changes (optimized for loading indicators)\n * const queue = useQueuer(\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 queue = useQueuer(\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 * // Example with custom state management and scheduling\n * const [items, setItems] = useState([]);\n *\n * const queue = useQueuer(\n * (item) => console.log('Processing:', item),\n * {\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * onItemsChange: (queue) => setItems(queue.peekAllItems()),\n * getPriority: (item) => item.priority // Process higher priority items first\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 { size, isRunning, executionCount } = queue.state;\n * ```\n */\nexport function useQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: PreactQueuerOptions<TValue, TSelected> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): PreactQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().queuer,\n ...options,\n } as PreactQueuerOptions<TValue, TSelected>\n\n const [queuer] = useState(() => {\n const queuerInstance = new Queuer<TValue>(\n fn,\n mergedOptions,\n ) as unknown as PreactQueuer<TValue, TSelected>\n\n queuerInstance.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) {\n const selected = useSelector(queuerInstance.store, props.selector, {\n compare: shallow,\n })\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n return queuerInstance\n })\n\n queuer.fn = fn\n queuer.setOptions(mergedOptions)\n\n /* eslint-disable react-hooks/exhaustive-deps -- cleanup only; runs on unmount */\n useEffect(() => {\n return () => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(queuer)\n } else {\n queuer.stop()\n }\n }\n }, [])\n /* eslint-enable react-hooks/exhaustive-deps */\n\n const state = useSelector(queuer.store, selector, { compare: shallow })\n\n return useMemo(\n () =>\n ({\n ...queuer,\n state,\n }) as PreactQueuer<TValue, TSelected>, // omit `store` in favor of `state`\n [queuer, state],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiMA,SAAgB,UACd,IACA,UAAkD,CAAC,GACnD,kBAA6D,CAAC,IAC7B;CACjC,MAAM,gBAAgB;EACpB,GAAG,uBAAuB,CAAC,CAAC;EAC5B,GAAG;CACL;CAEA,MAAM,CAAC,UAAU,eAAe;EAC9B,MAAM,iBAAiB,IAAI,OACzB,IACA,aACF;EAEA,eAAe,YAAY,SAAS,UAAqB,OAGtD;GACD,MAAM,WAAW,YAAY,eAAe,OAAO,MAAM,UAAU,EACjE,SAAS,QACX,CAAC;GAED,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,QAAQ,IACvB,MAAM;EACZ;EAEA,OAAO;CACT,CAAC;CAED,OAAO,KAAK;CACZ,OAAO,WAAW,aAAa;CAG/B,gBAAgB;EACd,aAAa;GACX,IAAI,cAAc,WAChB,cAAc,UAAU,MAAM;QAE9B,OAAO,KAAK;EAEhB;CACF,GAAG,CAAC,CAAC;CAGL,MAAM,QAAQ,YAAY,OAAO,OAAO,UAAU,EAAE,SAAS,QAAQ,CAAC;CAEtE,OAAO,eAEF;EACC,GAAG;EACH;CACF,IACF,CAAC,QAAQ,KAAK,CAChB;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"useRateLimitedCallback.cjs","names":["useRateLimiter"],"sources":["../../src/rate-limiter/useRateLimitedCallback.ts"],"sourcesContent":["import { useCallback } from 'preact/hooks'\nimport { useRateLimiter } from './useRateLimiter'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { PreactRateLimiterOptions } from './useRateLimiter'\n\n/**\n * A Preact hook that creates a rate-limited version of a callback function.\n * This hook is essentially a wrapper around the basic `rateLimiter` function\n * that is exported from `@tanstack/pacer`,\n * but optimized for Preact with reactive options and a stable function reference.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all calls until the limit\n * is reached, then blocks subsequent calls until the window resets. Unlike throttling\n * or debouncing, it does not attempt to space out or intelligently collapse calls.\n * This can lead to bursts of rapid executions followed by periods where all calls\n * are blocked.\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, consider:\n * - useThrottledCallback: When you want consistent spacing between executions (e.g. UI updates)\n * - useDebouncedCallback: When you want to collapse rapid calls into a single execution (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits,\n * like API rate limits or other scenarios requiring hard caps on execution frequency.\n *\n * This hook provides a simpler API compared to `useRateLimiter`, making it ideal for basic\n * rate limiting needs. However, it does not expose the underlying RateLimiter instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - Custom useCallback dependencies\n *\n * Consider using the `useRateLimiter` hook instead.\n *\n * @example\n * ```tsx\n * // Rate limit API calls to maximum 5 calls per minute with a sliding window\n * const makeApiCall = useRateLimitedCallback(\n * (data: ApiData) => {\n * return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) });\n * },\n * {\n * limit: 5,\n * window: 60000, // 1 minute\n * windowType: 'sliding',\n * onReject: () => {\n * console.warn('API rate limit reached. Please wait before trying again.');\n * }\n * }\n * );\n * ```\n */\nexport function useRateLimitedCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: PreactRateLimiterOptions<TFn, {}>,\n): (...args: Parameters<TFn>) => boolean {\n const rateLimitedFn = useRateLimiter(fn, options).maybeExecute\n return useCallback(\n (...args: Parameters<TFn>) => rateLimitedFn(...args),\n [rateLimitedFn],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,uBACd,IACA,SACuC;CACvC,MAAM,gBAAgBA,sCAAe,IAAI,QAAQ,CAAC;AAClD,uCACG,GAAG,SAA0B,cAAc,GAAG,KAAK,EACpD,CAAC,cAAc,CAChB"}
1
+ {"version":3,"file":"useRateLimitedCallback.cjs","names":["useRateLimiter","useCallback"],"sources":["../../src/rate-limiter/useRateLimitedCallback.ts"],"sourcesContent":["import { useCallback } from 'preact/hooks'\nimport { useRateLimiter } from './useRateLimiter'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { PreactRateLimiterOptions } from './useRateLimiter'\n\n/**\n * A Preact hook that creates a rate-limited version of a callback function.\n * This hook is essentially a wrapper around the basic `rateLimiter` function\n * that is exported from `@tanstack/pacer`,\n * but optimized for Preact with reactive options and a stable function reference.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all calls until the limit\n * is reached, then blocks subsequent calls until the window resets. Unlike throttling\n * or debouncing, it does not attempt to space out or intelligently collapse calls.\n * This can lead to bursts of rapid executions followed by periods where all calls\n * are blocked.\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, consider:\n * - useThrottledCallback: When you want consistent spacing between executions (e.g. UI updates)\n * - useDebouncedCallback: When you want to collapse rapid calls into a single execution (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits,\n * like API rate limits or other scenarios requiring hard caps on execution frequency.\n *\n * This hook provides a simpler API compared to `useRateLimiter`, making it ideal for basic\n * rate limiting needs. However, it does not expose the underlying RateLimiter instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - Custom useCallback dependencies\n *\n * Consider using the `useRateLimiter` hook instead.\n *\n * @example\n * ```tsx\n * // Rate limit API calls to maximum 5 calls per minute with a sliding window\n * const makeApiCall = useRateLimitedCallback(\n * (data: ApiData) => {\n * return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) });\n * },\n * {\n * limit: 5,\n * window: 60000, // 1 minute\n * windowType: 'sliding',\n * onReject: () => {\n * console.warn('API rate limit reached. Please wait before trying again.');\n * }\n * }\n * );\n * ```\n */\nexport function useRateLimitedCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: PreactRateLimiterOptions<TFn, {}>,\n): (...args: Parameters<TFn>) => boolean {\n const rateLimitedFn = useRateLimiter(fn, options).maybeExecute\n return useCallback(\n (...args: Parameters<TFn>) => rateLimitedFn(...args),\n [rateLimitedFn],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,uBACd,IACA,SACuC;CACvC,MAAM,gBAAgBA,sCAAe,IAAI,OAAO,CAAC,CAAC;CAClD,WAAOC,2BACJ,GAAG,SAA0B,cAAc,GAAG,IAAI,GACnD,CAAC,aAAa,CAChB;AACF"}
@@ -1,6 +1,5 @@
1
1
  import { PreactRateLimiterOptions } from "./useRateLimiter.cjs";
2
2
  import { AnyFunction } from "@tanstack/pacer/types";
3
-
4
3
  //#region src/rate-limiter/useRateLimitedCallback.d.ts
5
4
  /**
6
5
  * A Preact hook that creates a rate-limited version of a callback function.
@@ -1,6 +1,5 @@
1
1
  import { PreactRateLimiterOptions } from "./useRateLimiter.js";
2
2
  import { AnyFunction } from "@tanstack/pacer/types";
3
-
4
3
  //#region src/rate-limiter/useRateLimitedCallback.d.ts
5
4
  /**
6
5
  * A Preact hook that creates a rate-limited version of a callback function.
@@ -1 +1 @@
1
- {"version":3,"file":"useRateLimitedCallback.js","names":[],"sources":["../../src/rate-limiter/useRateLimitedCallback.ts"],"sourcesContent":["import { useCallback } from 'preact/hooks'\nimport { useRateLimiter } from './useRateLimiter'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { PreactRateLimiterOptions } from './useRateLimiter'\n\n/**\n * A Preact hook that creates a rate-limited version of a callback function.\n * This hook is essentially a wrapper around the basic `rateLimiter` function\n * that is exported from `@tanstack/pacer`,\n * but optimized for Preact with reactive options and a stable function reference.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all calls until the limit\n * is reached, then blocks subsequent calls until the window resets. Unlike throttling\n * or debouncing, it does not attempt to space out or intelligently collapse calls.\n * This can lead to bursts of rapid executions followed by periods where all calls\n * are blocked.\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, consider:\n * - useThrottledCallback: When you want consistent spacing between executions (e.g. UI updates)\n * - useDebouncedCallback: When you want to collapse rapid calls into a single execution (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits,\n * like API rate limits or other scenarios requiring hard caps on execution frequency.\n *\n * This hook provides a simpler API compared to `useRateLimiter`, making it ideal for basic\n * rate limiting needs. However, it does not expose the underlying RateLimiter instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - Custom useCallback dependencies\n *\n * Consider using the `useRateLimiter` hook instead.\n *\n * @example\n * ```tsx\n * // Rate limit API calls to maximum 5 calls per minute with a sliding window\n * const makeApiCall = useRateLimitedCallback(\n * (data: ApiData) => {\n * return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) });\n * },\n * {\n * limit: 5,\n * window: 60000, // 1 minute\n * windowType: 'sliding',\n * onReject: () => {\n * console.warn('API rate limit reached. Please wait before trying again.');\n * }\n * }\n * );\n * ```\n */\nexport function useRateLimitedCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: PreactRateLimiterOptions<TFn, {}>,\n): (...args: Parameters<TFn>) => boolean {\n const rateLimitedFn = useRateLimiter(fn, options).maybeExecute\n return useCallback(\n (...args: Parameters<TFn>) => rateLimitedFn(...args),\n [rateLimitedFn],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,uBACd,IACA,SACuC;CACvC,MAAM,gBAAgB,eAAe,IAAI,QAAQ,CAAC;AAClD,QAAO,aACJ,GAAG,SAA0B,cAAc,GAAG,KAAK,EACpD,CAAC,cAAc,CAChB"}
1
+ {"version":3,"file":"useRateLimitedCallback.js","names":[],"sources":["../../src/rate-limiter/useRateLimitedCallback.ts"],"sourcesContent":["import { useCallback } from 'preact/hooks'\nimport { useRateLimiter } from './useRateLimiter'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { PreactRateLimiterOptions } from './useRateLimiter'\n\n/**\n * A Preact hook that creates a rate-limited version of a callback function.\n * This hook is essentially a wrapper around the basic `rateLimiter` function\n * that is exported from `@tanstack/pacer`,\n * but optimized for Preact with reactive options and a stable function reference.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all calls until the limit\n * is reached, then blocks subsequent calls until the window resets. Unlike throttling\n * or debouncing, it does not attempt to space out or intelligently collapse calls.\n * This can lead to bursts of rapid executions followed by periods where all calls\n * are blocked.\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, consider:\n * - useThrottledCallback: When you want consistent spacing between executions (e.g. UI updates)\n * - useDebouncedCallback: When you want to collapse rapid calls into a single execution (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits,\n * like API rate limits or other scenarios requiring hard caps on execution frequency.\n *\n * This hook provides a simpler API compared to `useRateLimiter`, making it ideal for basic\n * rate limiting needs. However, it does not expose the underlying RateLimiter instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - Custom useCallback dependencies\n *\n * Consider using the `useRateLimiter` hook instead.\n *\n * @example\n * ```tsx\n * // Rate limit API calls to maximum 5 calls per minute with a sliding window\n * const makeApiCall = useRateLimitedCallback(\n * (data: ApiData) => {\n * return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) });\n * },\n * {\n * limit: 5,\n * window: 60000, // 1 minute\n * windowType: 'sliding',\n * onReject: () => {\n * console.warn('API rate limit reached. Please wait before trying again.');\n * }\n * }\n * );\n * ```\n */\nexport function useRateLimitedCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: PreactRateLimiterOptions<TFn, {}>,\n): (...args: Parameters<TFn>) => boolean {\n const rateLimitedFn = useRateLimiter(fn, options).maybeExecute\n return useCallback(\n (...args: Parameters<TFn>) => rateLimitedFn(...args),\n [rateLimitedFn],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,uBACd,IACA,SACuC;CACvC,MAAM,gBAAgB,eAAe,IAAI,OAAO,CAAC,CAAC;CAClD,OAAO,aACJ,GAAG,SAA0B,cAAc,GAAG,IAAI,GACnD,CAAC,aAAa,CAChB;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"useRateLimitedState.cjs","names":["useRateLimiter"],"sources":["../../src/rate-limiter/useRateLimitedState.ts"],"sourcesContent":["import { useState } from 'preact/hooks'\nimport { useRateLimiter } from './useRateLimiter'\nimport type {\n PreactRateLimiter,\n PreactRateLimiterOptions,\n} from './useRateLimiter'\nimport type { Dispatch, StateUpdater } from 'preact/hooks'\nimport type { RateLimiterState } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A Preact hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.\n * This hook combines Preact's useState with rate limiting functionality to provide controlled state updates.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\n *\n * For smoother update patterns, consider:\n * - useThrottledState: When you want consistent spacing between updates (e.g. UI changes)\n * - useDebouncedState: 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\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 useRateLimiter 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 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 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 [value, setValue, rateLimiter] = useRateLimitedState(0, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to re-render when execution count changes (optimized for tracking successful updates)\n * const [value, setValue, rateLimiter] = useRateLimitedState(\n * 0,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to re-render when rejection count changes (optimized for tracking rate limit violations)\n * const [value, setValue, rateLimiter] = useRateLimitedState(\n * 0,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to re-render when execution times change (optimized for window calculations)\n * const [value, setValue, rateLimiter] = useRateLimitedState(\n * 0,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // With rejection callback and fixed window\n * const [value, setValue] = useRateLimitedState(0, {\n * limit: 3,\n * window: 5000,\n * windowType: 'fixed',\n * onReject: (rateLimiter) => {\n * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access rateLimiter methods if needed\n * const handleSubmit = () => {\n * const remaining = rateLimiter.getRemainingInWindow();\n * if (remaining > 0) {\n * setValue(newValue);\n * } else {\n * showRateLimitWarning();\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 useRateLimitedState<TValue, TSelected = RateLimiterState>(\n value: TValue,\n options: PreactRateLimiterOptions<Dispatch<StateUpdater<TValue>>, TSelected>,\n selector?: (state: RateLimiterState) => TSelected,\n): [\n TValue,\n Dispatch<StateUpdater<TValue>>,\n PreactRateLimiter<Dispatch<StateUpdater<TValue>>, TSelected>,\n] {\n const [rateLimitedValue, setRateLimitedValue] = useState(value)\n const rateLimiter = useRateLimiter(setRateLimitedValue, options, selector)\n return [\n rateLimitedValue,\n rateLimiter.maybeExecute as Dispatch<StateUpdater<TValue>>,\n rateLimiter,\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2GA,SAAgB,oBACd,OACA,SACA,UAKA;CACA,MAAM,CAAC,kBAAkB,kDAAgC,MAAM;CAC/D,MAAM,cAAcA,sCAAe,qBAAqB,SAAS,SAAS;AAC1E,QAAO;EACL;EACA,YAAY;EACZ;EACD"}
1
+ {"version":3,"file":"useRateLimitedState.cjs","names":["useState","useRateLimiter"],"sources":["../../src/rate-limiter/useRateLimitedState.ts"],"sourcesContent":["import { useState } from 'preact/hooks'\nimport { useRateLimiter } from './useRateLimiter'\nimport type {\n PreactRateLimiter,\n PreactRateLimiterOptions,\n} from './useRateLimiter'\nimport type { Dispatch, StateUpdater } from 'preact/hooks'\nimport type { RateLimiterState } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A Preact hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.\n * This hook combines Preact's useState with rate limiting functionality to provide controlled state updates.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\n *\n * For smoother update patterns, consider:\n * - useThrottledState: When you want consistent spacing between updates (e.g. UI changes)\n * - useDebouncedState: 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\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 useRateLimiter 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 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 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 [value, setValue, rateLimiter] = useRateLimitedState(0, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to re-render when execution count changes (optimized for tracking successful updates)\n * const [value, setValue, rateLimiter] = useRateLimitedState(\n * 0,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to re-render when rejection count changes (optimized for tracking rate limit violations)\n * const [value, setValue, rateLimiter] = useRateLimitedState(\n * 0,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to re-render when execution times change (optimized for window calculations)\n * const [value, setValue, rateLimiter] = useRateLimitedState(\n * 0,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // With rejection callback and fixed window\n * const [value, setValue] = useRateLimitedState(0, {\n * limit: 3,\n * window: 5000,\n * windowType: 'fixed',\n * onReject: (rateLimiter) => {\n * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access rateLimiter methods if needed\n * const handleSubmit = () => {\n * const remaining = rateLimiter.getRemainingInWindow();\n * if (remaining > 0) {\n * setValue(newValue);\n * } else {\n * showRateLimitWarning();\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 useRateLimitedState<TValue, TSelected = RateLimiterState>(\n value: TValue,\n options: PreactRateLimiterOptions<Dispatch<StateUpdater<TValue>>, TSelected>,\n selector?: (state: RateLimiterState) => TSelected,\n): [\n TValue,\n Dispatch<StateUpdater<TValue>>,\n PreactRateLimiter<Dispatch<StateUpdater<TValue>>, TSelected>,\n] {\n const [rateLimitedValue, setRateLimitedValue] = useState(value)\n const rateLimiter = useRateLimiter(setRateLimitedValue, options, selector)\n return [\n rateLimitedValue,\n rateLimiter.maybeExecute as Dispatch<StateUpdater<TValue>>,\n rateLimiter,\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2GA,SAAgB,oBACd,OACA,SACA,UAKA;CACA,MAAM,CAAC,kBAAkB,2BAAuBA,uBAAS,KAAK;CAC9D,MAAM,cAAcC,sCAAe,qBAAqB,SAAS,QAAQ;CACzE,OAAO;EACL;EACA,YAAY;EACZ;CACF;AACF"}
@@ -1,7 +1,6 @@
1
1
  import { PreactRateLimiter, PreactRateLimiterOptions } from "./useRateLimiter.cjs";
2
2
  import { Dispatch, StateUpdater } from "preact/hooks";
3
3
  import { RateLimiterState } from "@tanstack/pacer/rate-limiter";
4
-
5
4
  //#region src/rate-limiter/useRateLimitedState.d.ts
6
5
  /**
7
6
  * A Preact hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.
@@ -1,7 +1,6 @@
1
1
  import { PreactRateLimiter, PreactRateLimiterOptions } from "./useRateLimiter.js";
2
2
  import { Dispatch, StateUpdater } from "preact/hooks";
3
3
  import { RateLimiterState } from "@tanstack/pacer/rate-limiter";
4
-
5
4
  //#region src/rate-limiter/useRateLimitedState.d.ts
6
5
  /**
7
6
  * A Preact hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.
@@ -1 +1 @@
1
- {"version":3,"file":"useRateLimitedState.js","names":[],"sources":["../../src/rate-limiter/useRateLimitedState.ts"],"sourcesContent":["import { useState } from 'preact/hooks'\nimport { useRateLimiter } from './useRateLimiter'\nimport type {\n PreactRateLimiter,\n PreactRateLimiterOptions,\n} from './useRateLimiter'\nimport type { Dispatch, StateUpdater } from 'preact/hooks'\nimport type { RateLimiterState } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A Preact hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.\n * This hook combines Preact's useState with rate limiting functionality to provide controlled state updates.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\n *\n * For smoother update patterns, consider:\n * - useThrottledState: When you want consistent spacing between updates (e.g. UI changes)\n * - useDebouncedState: 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\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 useRateLimiter 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 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 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 [value, setValue, rateLimiter] = useRateLimitedState(0, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to re-render when execution count changes (optimized for tracking successful updates)\n * const [value, setValue, rateLimiter] = useRateLimitedState(\n * 0,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to re-render when rejection count changes (optimized for tracking rate limit violations)\n * const [value, setValue, rateLimiter] = useRateLimitedState(\n * 0,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to re-render when execution times change (optimized for window calculations)\n * const [value, setValue, rateLimiter] = useRateLimitedState(\n * 0,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // With rejection callback and fixed window\n * const [value, setValue] = useRateLimitedState(0, {\n * limit: 3,\n * window: 5000,\n * windowType: 'fixed',\n * onReject: (rateLimiter) => {\n * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access rateLimiter methods if needed\n * const handleSubmit = () => {\n * const remaining = rateLimiter.getRemainingInWindow();\n * if (remaining > 0) {\n * setValue(newValue);\n * } else {\n * showRateLimitWarning();\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 useRateLimitedState<TValue, TSelected = RateLimiterState>(\n value: TValue,\n options: PreactRateLimiterOptions<Dispatch<StateUpdater<TValue>>, TSelected>,\n selector?: (state: RateLimiterState) => TSelected,\n): [\n TValue,\n Dispatch<StateUpdater<TValue>>,\n PreactRateLimiter<Dispatch<StateUpdater<TValue>>, TSelected>,\n] {\n const [rateLimitedValue, setRateLimitedValue] = useState(value)\n const rateLimiter = useRateLimiter(setRateLimitedValue, options, selector)\n return [\n rateLimitedValue,\n rateLimiter.maybeExecute as Dispatch<StateUpdater<TValue>>,\n rateLimiter,\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2GA,SAAgB,oBACd,OACA,SACA,UAKA;CACA,MAAM,CAAC,kBAAkB,uBAAuB,SAAS,MAAM;CAC/D,MAAM,cAAc,eAAe,qBAAqB,SAAS,SAAS;AAC1E,QAAO;EACL;EACA,YAAY;EACZ;EACD"}
1
+ {"version":3,"file":"useRateLimitedState.js","names":[],"sources":["../../src/rate-limiter/useRateLimitedState.ts"],"sourcesContent":["import { useState } from 'preact/hooks'\nimport { useRateLimiter } from './useRateLimiter'\nimport type {\n PreactRateLimiter,\n PreactRateLimiterOptions,\n} from './useRateLimiter'\nimport type { Dispatch, StateUpdater } from 'preact/hooks'\nimport type { RateLimiterState } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A Preact hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.\n * This hook combines Preact's useState with rate limiting functionality to provide controlled state updates.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\n *\n * For smoother update patterns, consider:\n * - useThrottledState: When you want consistent spacing between updates (e.g. UI changes)\n * - useDebouncedState: 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\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 useRateLimiter 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 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 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 [value, setValue, rateLimiter] = useRateLimitedState(0, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to re-render when execution count changes (optimized for tracking successful updates)\n * const [value, setValue, rateLimiter] = useRateLimitedState(\n * 0,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to re-render when rejection count changes (optimized for tracking rate limit violations)\n * const [value, setValue, rateLimiter] = useRateLimitedState(\n * 0,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to re-render when execution times change (optimized for window calculations)\n * const [value, setValue, rateLimiter] = useRateLimitedState(\n * 0,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // With rejection callback and fixed window\n * const [value, setValue] = useRateLimitedState(0, {\n * limit: 3,\n * window: 5000,\n * windowType: 'fixed',\n * onReject: (rateLimiter) => {\n * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access rateLimiter methods if needed\n * const handleSubmit = () => {\n * const remaining = rateLimiter.getRemainingInWindow();\n * if (remaining > 0) {\n * setValue(newValue);\n * } else {\n * showRateLimitWarning();\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 useRateLimitedState<TValue, TSelected = RateLimiterState>(\n value: TValue,\n options: PreactRateLimiterOptions<Dispatch<StateUpdater<TValue>>, TSelected>,\n selector?: (state: RateLimiterState) => TSelected,\n): [\n TValue,\n Dispatch<StateUpdater<TValue>>,\n PreactRateLimiter<Dispatch<StateUpdater<TValue>>, TSelected>,\n] {\n const [rateLimitedValue, setRateLimitedValue] = useState(value)\n const rateLimiter = useRateLimiter(setRateLimitedValue, options, selector)\n return [\n rateLimitedValue,\n rateLimiter.maybeExecute as Dispatch<StateUpdater<TValue>>,\n rateLimiter,\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2GA,SAAgB,oBACd,OACA,SACA,UAKA;CACA,MAAM,CAAC,kBAAkB,uBAAuB,SAAS,KAAK;CAC9D,MAAM,cAAc,eAAe,qBAAqB,SAAS,QAAQ;CACzE,OAAO;EACL;EACA,YAAY;EACZ;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"useRateLimitedValue.cjs","names":["useRateLimitedState"],"sources":["../../src/rate-limiter/useRateLimitedValue.ts"],"sourcesContent":["import { useEffect } from 'preact/hooks'\nimport { useRateLimitedState } from './useRateLimitedState'\nimport type {\n PreactRateLimiter,\n PreactRateLimiterOptions,\n} from './useRateLimiter'\nimport type { Dispatch, StateUpdater } from 'preact/hooks'\nimport type { RateLimiterState } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A high-level Preact 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 Preact's useState 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 * - useThrottledValue: When you want consistent spacing between updates (e.g. UI changes)\n * - useDebouncedValue: 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 value that updates according to the configured rate limit\n * - The rate limiter instance with control methods\n *\n * For more direct control over rate limiting behavior without Preact state management,\n * consider using the lower-level useRateLimiter 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 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 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] = useRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to re-render when execution count changes (optimized for tracking successful updates)\n * const [rateLimitedValue, rateLimiter] = useRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to re-render when rejection count changes (optimized for tracking rate limit violations)\n * const [rateLimitedValue, rateLimiter] = useRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to re-render when execution times change (optimized for window calculations)\n * const [rateLimitedValue, rateLimiter] = useRateLimitedValue(\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] = useRateLimitedValue(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 useRateLimitedValue<TValue, TSelected = RateLimiterState>(\n value: TValue,\n options: PreactRateLimiterOptions<Dispatch<StateUpdater<TValue>>, TSelected>,\n selector?: (state: RateLimiterState) => TSelected,\n): [TValue, PreactRateLimiter<Dispatch<StateUpdater<TValue>>, TSelected>] {\n const [rateLimitedValue, setRateLimitedValue, rateLimiter] =\n useRateLimitedState(value, options, selector)\n\n useEffect(() => {\n ;(setRateLimitedValue as (value: TValue) => void)(value)\n }, [value, setRateLimitedValue])\n\n return [rateLimitedValue, rateLimiter]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,SAAgB,oBACd,OACA,SACA,UACwE;CACxE,MAAM,CAAC,kBAAkB,qBAAqB,eAC5CA,gDAAoB,OAAO,SAAS,SAAS;AAE/C,mCAAgB;AACb,EAAC,oBAAgD,MAAM;IACvD,CAAC,OAAO,oBAAoB,CAAC;AAEhC,QAAO,CAAC,kBAAkB,YAAY"}
1
+ {"version":3,"file":"useRateLimitedValue.cjs","names":["useRateLimitedState"],"sources":["../../src/rate-limiter/useRateLimitedValue.ts"],"sourcesContent":["import { useEffect } from 'preact/hooks'\nimport { useRateLimitedState } from './useRateLimitedState'\nimport type {\n PreactRateLimiter,\n PreactRateLimiterOptions,\n} from './useRateLimiter'\nimport type { Dispatch, StateUpdater } from 'preact/hooks'\nimport type { RateLimiterState } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A high-level Preact 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 Preact's useState 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 * - useThrottledValue: When you want consistent spacing between updates (e.g. UI changes)\n * - useDebouncedValue: 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 value that updates according to the configured rate limit\n * - The rate limiter instance with control methods\n *\n * For more direct control over rate limiting behavior without Preact state management,\n * consider using the lower-level useRateLimiter 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 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 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] = useRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to re-render when execution count changes (optimized for tracking successful updates)\n * const [rateLimitedValue, rateLimiter] = useRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to re-render when rejection count changes (optimized for tracking rate limit violations)\n * const [rateLimitedValue, rateLimiter] = useRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to re-render when execution times change (optimized for window calculations)\n * const [rateLimitedValue, rateLimiter] = useRateLimitedValue(\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] = useRateLimitedValue(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 useRateLimitedValue<TValue, TSelected = RateLimiterState>(\n value: TValue,\n options: PreactRateLimiterOptions<Dispatch<StateUpdater<TValue>>, TSelected>,\n selector?: (state: RateLimiterState) => TSelected,\n): [TValue, PreactRateLimiter<Dispatch<StateUpdater<TValue>>, TSelected>] {\n const [rateLimitedValue, setRateLimitedValue, rateLimiter] =\n useRateLimitedState(value, options, selector)\n\n useEffect(() => {\n ;(setRateLimitedValue as (value: TValue) => void)(value)\n }, [value, setRateLimitedValue])\n\n return [rateLimitedValue, rateLimiter]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,SAAgB,oBACd,OACA,SACA,UACwE;CACxE,MAAM,CAAC,kBAAkB,qBAAqB,eAC5CA,gDAAoB,OAAO,SAAS,QAAQ;CAE9C,kCAAgB;EACb,AAAC,oBAAgD,KAAK;CACzD,GAAG,CAAC,OAAO,mBAAmB,CAAC;CAE/B,OAAO,CAAC,kBAAkB,WAAW;AACvC"}
@@ -1,7 +1,6 @@
1
1
  import { PreactRateLimiter, PreactRateLimiterOptions } from "./useRateLimiter.cjs";
2
2
  import { Dispatch, StateUpdater } from "preact/hooks";
3
3
  import { RateLimiterState } from "@tanstack/pacer/rate-limiter";
4
-
5
4
  //#region src/rate-limiter/useRateLimitedValue.d.ts
6
5
  /**
7
6
  * A high-level Preact hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window.
@@ -1,7 +1,6 @@
1
1
  import { PreactRateLimiter, PreactRateLimiterOptions } from "./useRateLimiter.js";
2
2
  import { Dispatch, StateUpdater } from "preact/hooks";
3
3
  import { RateLimiterState } from "@tanstack/pacer/rate-limiter";
4
-
5
4
  //#region src/rate-limiter/useRateLimitedValue.d.ts
6
5
  /**
7
6
  * A high-level Preact hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window.
@@ -1 +1 @@
1
- {"version":3,"file":"useRateLimitedValue.js","names":[],"sources":["../../src/rate-limiter/useRateLimitedValue.ts"],"sourcesContent":["import { useEffect } from 'preact/hooks'\nimport { useRateLimitedState } from './useRateLimitedState'\nimport type {\n PreactRateLimiter,\n PreactRateLimiterOptions,\n} from './useRateLimiter'\nimport type { Dispatch, StateUpdater } from 'preact/hooks'\nimport type { RateLimiterState } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A high-level Preact 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 Preact's useState 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 * - useThrottledValue: When you want consistent spacing between updates (e.g. UI changes)\n * - useDebouncedValue: 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 value that updates according to the configured rate limit\n * - The rate limiter instance with control methods\n *\n * For more direct control over rate limiting behavior without Preact state management,\n * consider using the lower-level useRateLimiter 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 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 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] = useRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to re-render when execution count changes (optimized for tracking successful updates)\n * const [rateLimitedValue, rateLimiter] = useRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to re-render when rejection count changes (optimized for tracking rate limit violations)\n * const [rateLimitedValue, rateLimiter] = useRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to re-render when execution times change (optimized for window calculations)\n * const [rateLimitedValue, rateLimiter] = useRateLimitedValue(\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] = useRateLimitedValue(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 useRateLimitedValue<TValue, TSelected = RateLimiterState>(\n value: TValue,\n options: PreactRateLimiterOptions<Dispatch<StateUpdater<TValue>>, TSelected>,\n selector?: (state: RateLimiterState) => TSelected,\n): [TValue, PreactRateLimiter<Dispatch<StateUpdater<TValue>>, TSelected>] {\n const [rateLimitedValue, setRateLimitedValue, rateLimiter] =\n useRateLimitedState(value, options, selector)\n\n useEffect(() => {\n ;(setRateLimitedValue as (value: TValue) => void)(value)\n }, [value, setRateLimitedValue])\n\n return [rateLimitedValue, rateLimiter]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,SAAgB,oBACd,OACA,SACA,UACwE;CACxE,MAAM,CAAC,kBAAkB,qBAAqB,eAC5C,oBAAoB,OAAO,SAAS,SAAS;AAE/C,iBAAgB;AACb,EAAC,oBAAgD,MAAM;IACvD,CAAC,OAAO,oBAAoB,CAAC;AAEhC,QAAO,CAAC,kBAAkB,YAAY"}
1
+ {"version":3,"file":"useRateLimitedValue.js","names":[],"sources":["../../src/rate-limiter/useRateLimitedValue.ts"],"sourcesContent":["import { useEffect } from 'preact/hooks'\nimport { useRateLimitedState } from './useRateLimitedState'\nimport type {\n PreactRateLimiter,\n PreactRateLimiterOptions,\n} from './useRateLimiter'\nimport type { Dispatch, StateUpdater } from 'preact/hooks'\nimport type { RateLimiterState } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A high-level Preact 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 Preact's useState 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 * - useThrottledValue: When you want consistent spacing between updates (e.g. UI changes)\n * - useDebouncedValue: 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 value that updates according to the configured rate limit\n * - The rate limiter instance with control methods\n *\n * For more direct control over rate limiting behavior without Preact state management,\n * consider using the lower-level useRateLimiter 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 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 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] = useRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to re-render when execution count changes (optimized for tracking successful updates)\n * const [rateLimitedValue, rateLimiter] = useRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to re-render when rejection count changes (optimized for tracking rate limit violations)\n * const [rateLimitedValue, rateLimiter] = useRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to re-render when execution times change (optimized for window calculations)\n * const [rateLimitedValue, rateLimiter] = useRateLimitedValue(\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] = useRateLimitedValue(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 useRateLimitedValue<TValue, TSelected = RateLimiterState>(\n value: TValue,\n options: PreactRateLimiterOptions<Dispatch<StateUpdater<TValue>>, TSelected>,\n selector?: (state: RateLimiterState) => TSelected,\n): [TValue, PreactRateLimiter<Dispatch<StateUpdater<TValue>>, TSelected>] {\n const [rateLimitedValue, setRateLimitedValue, rateLimiter] =\n useRateLimitedState(value, options, selector)\n\n useEffect(() => {\n ;(setRateLimitedValue as (value: TValue) => void)(value)\n }, [value, setRateLimitedValue])\n\n return [rateLimitedValue, rateLimiter]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,SAAgB,oBACd,OACA,SACA,UACwE;CACxE,MAAM,CAAC,kBAAkB,qBAAqB,eAC5C,oBAAoB,OAAO,SAAS,QAAQ;CAE9C,gBAAgB;EACb,AAAC,oBAAgD,KAAK;CACzD,GAAG,CAAC,OAAO,mBAAmB,CAAC;CAE/B,OAAO,CAAC,kBAAkB,WAAW;AACvC"}