@tanstack/solid-pacer 0.8.0 → 0.9.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 (132) hide show
  1. package/dist/cjs/async-batcher/createAsyncBatcher.cjs +14 -0
  2. package/dist/cjs/async-batcher/createAsyncBatcher.cjs.map +1 -0
  3. package/dist/cjs/async-batcher/createAsyncBatcher.d.cts +72 -0
  4. package/dist/cjs/async-batcher/index.cjs +12 -0
  5. package/dist/cjs/{compare → async-batcher}/index.cjs.map +1 -1
  6. package/dist/cjs/async-batcher/index.d.cts +2 -0
  7. package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs +9 -36
  8. package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs.map +1 -1
  9. package/dist/cjs/async-debouncer/createAsyncDebouncer.d.cts +10 -9
  10. package/dist/cjs/async-queuer/createAsyncQueuer.cjs +5 -73
  11. package/dist/cjs/async-queuer/createAsyncQueuer.cjs.map +1 -1
  12. package/dist/cjs/async-queuer/createAsyncQueuer.d.cts +7 -53
  13. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs +5 -52
  14. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs.map +1 -1
  15. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.d.cts +4 -9
  16. package/dist/cjs/async-throttler/createAsyncThrottler.cjs +5 -55
  17. package/dist/cjs/async-throttler/createAsyncThrottler.cjs.map +1 -1
  18. package/dist/cjs/async-throttler/createAsyncThrottler.d.cts +9 -11
  19. package/dist/cjs/batcher/createBatcher.cjs +5 -49
  20. package/dist/cjs/batcher/createBatcher.cjs.map +1 -1
  21. package/dist/cjs/batcher/createBatcher.d.cts +9 -27
  22. package/dist/cjs/debouncer/createDebouncedSignal.cjs +2 -2
  23. package/dist/cjs/debouncer/createDebouncedSignal.cjs.map +1 -1
  24. package/dist/cjs/debouncer/createDebouncedSignal.d.cts +6 -2
  25. package/dist/cjs/debouncer/createDebouncedValue.cjs +3 -2
  26. package/dist/cjs/debouncer/createDebouncedValue.cjs.map +1 -1
  27. package/dist/cjs/debouncer/createDebouncedValue.d.cts +2 -2
  28. package/dist/cjs/debouncer/createDebouncer.cjs +7 -24
  29. package/dist/cjs/debouncer/createDebouncer.cjs.map +1 -1
  30. package/dist/cjs/debouncer/createDebouncer.d.cts +9 -8
  31. package/dist/cjs/index.cjs +2 -0
  32. package/dist/cjs/index.cjs.map +1 -1
  33. package/dist/cjs/index.d.cts +1 -0
  34. package/dist/cjs/queuer/createQueuer.cjs +5 -59
  35. package/dist/cjs/queuer/createQueuer.cjs.map +1 -1
  36. package/dist/cjs/queuer/createQueuer.d.cts +7 -37
  37. package/dist/cjs/rate-limiter/createRateLimitedSignal.cjs +7 -3
  38. package/dist/cjs/rate-limiter/createRateLimitedSignal.cjs.map +1 -1
  39. package/dist/cjs/rate-limiter/createRateLimitedSignal.d.cts +6 -2
  40. package/dist/cjs/rate-limiter/createRateLimitedValue.cjs +2 -2
  41. package/dist/cjs/rate-limiter/createRateLimitedValue.cjs.map +1 -1
  42. package/dist/cjs/rate-limiter/createRateLimitedValue.d.cts +2 -2
  43. package/dist/cjs/rate-limiter/createRateLimiter.cjs +5 -43
  44. package/dist/cjs/rate-limiter/createRateLimiter.cjs.map +1 -1
  45. package/dist/cjs/rate-limiter/createRateLimiter.d.cts +9 -7
  46. package/dist/cjs/throttler/createThrottledSignal.cjs +2 -2
  47. package/dist/cjs/throttler/createThrottledSignal.cjs.map +1 -1
  48. package/dist/cjs/throttler/createThrottledSignal.d.cts +6 -2
  49. package/dist/cjs/throttler/createThrottledValue.cjs +3 -2
  50. package/dist/cjs/throttler/createThrottledValue.cjs.map +1 -1
  51. package/dist/cjs/throttler/createThrottledValue.d.cts +2 -2
  52. package/dist/cjs/throttler/createThrottler.cjs +7 -34
  53. package/dist/cjs/throttler/createThrottler.cjs.map +1 -1
  54. package/dist/cjs/throttler/createThrottler.d.cts +9 -10
  55. package/dist/esm/async-batcher/createAsyncBatcher.d.ts +72 -0
  56. package/dist/esm/async-batcher/createAsyncBatcher.js +14 -0
  57. package/dist/esm/async-batcher/createAsyncBatcher.js.map +1 -0
  58. package/dist/esm/async-batcher/index.d.ts +2 -0
  59. package/dist/esm/async-batcher/index.js +6 -0
  60. package/dist/esm/{compare → async-batcher}/index.js.map +1 -1
  61. package/dist/esm/async-debouncer/createAsyncDebouncer.d.ts +10 -9
  62. package/dist/esm/async-debouncer/createAsyncDebouncer.js +10 -37
  63. package/dist/esm/async-debouncer/createAsyncDebouncer.js.map +1 -1
  64. package/dist/esm/async-queuer/createAsyncQueuer.d.ts +7 -53
  65. package/dist/esm/async-queuer/createAsyncQueuer.js +5 -73
  66. package/dist/esm/async-queuer/createAsyncQueuer.js.map +1 -1
  67. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.d.ts +4 -9
  68. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js +5 -52
  69. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js.map +1 -1
  70. package/dist/esm/async-throttler/createAsyncThrottler.d.ts +9 -11
  71. package/dist/esm/async-throttler/createAsyncThrottler.js +5 -55
  72. package/dist/esm/async-throttler/createAsyncThrottler.js.map +1 -1
  73. package/dist/esm/batcher/createBatcher.d.ts +9 -27
  74. package/dist/esm/batcher/createBatcher.js +5 -49
  75. package/dist/esm/batcher/createBatcher.js.map +1 -1
  76. package/dist/esm/debouncer/createDebouncedSignal.d.ts +6 -2
  77. package/dist/esm/debouncer/createDebouncedSignal.js +2 -2
  78. package/dist/esm/debouncer/createDebouncedSignal.js.map +1 -1
  79. package/dist/esm/debouncer/createDebouncedValue.d.ts +2 -2
  80. package/dist/esm/debouncer/createDebouncedValue.js +3 -2
  81. package/dist/esm/debouncer/createDebouncedValue.js.map +1 -1
  82. package/dist/esm/debouncer/createDebouncer.d.ts +9 -8
  83. package/dist/esm/debouncer/createDebouncer.js +8 -25
  84. package/dist/esm/debouncer/createDebouncer.js.map +1 -1
  85. package/dist/esm/index.d.ts +1 -0
  86. package/dist/esm/index.js +2 -0
  87. package/dist/esm/index.js.map +1 -1
  88. package/dist/esm/queuer/createQueuer.d.ts +7 -37
  89. package/dist/esm/queuer/createQueuer.js +5 -59
  90. package/dist/esm/queuer/createQueuer.js.map +1 -1
  91. package/dist/esm/rate-limiter/createRateLimitedSignal.d.ts +6 -2
  92. package/dist/esm/rate-limiter/createRateLimitedSignal.js +7 -3
  93. package/dist/esm/rate-limiter/createRateLimitedSignal.js.map +1 -1
  94. package/dist/esm/rate-limiter/createRateLimitedValue.d.ts +2 -2
  95. package/dist/esm/rate-limiter/createRateLimitedValue.js +2 -2
  96. package/dist/esm/rate-limiter/createRateLimitedValue.js.map +1 -1
  97. package/dist/esm/rate-limiter/createRateLimiter.d.ts +9 -7
  98. package/dist/esm/rate-limiter/createRateLimiter.js +5 -43
  99. package/dist/esm/rate-limiter/createRateLimiter.js.map +1 -1
  100. package/dist/esm/throttler/createThrottledSignal.d.ts +6 -2
  101. package/dist/esm/throttler/createThrottledSignal.js +2 -2
  102. package/dist/esm/throttler/createThrottledSignal.js.map +1 -1
  103. package/dist/esm/throttler/createThrottledValue.d.ts +2 -2
  104. package/dist/esm/throttler/createThrottledValue.js +3 -2
  105. package/dist/esm/throttler/createThrottledValue.js.map +1 -1
  106. package/dist/esm/throttler/createThrottler.d.ts +9 -10
  107. package/dist/esm/throttler/createThrottler.js +8 -35
  108. package/dist/esm/throttler/createThrottler.js.map +1 -1
  109. package/package.json +14 -3
  110. package/src/async-batcher/createAsyncBatcher.ts +98 -0
  111. package/src/async-batcher/index.ts +3 -0
  112. package/src/async-debouncer/createAsyncDebouncer.ts +31 -56
  113. package/src/async-queuer/createAsyncQueuer.ts +18 -141
  114. package/src/async-rate-limiter/createAsyncRateLimiter.ts +20 -75
  115. package/src/async-throttler/createAsyncThrottler.ts +25 -81
  116. package/src/batcher/createBatcher.ts +17 -94
  117. package/src/debouncer/createDebouncedSignal.ts +15 -4
  118. package/src/debouncer/createDebouncedValue.ts +11 -3
  119. package/src/debouncer/createDebouncer.ts +28 -38
  120. package/src/index.ts +3 -0
  121. package/src/queuer/createQueuer.ts +15 -115
  122. package/src/rate-limiter/createRateLimitedSignal.ts +17 -5
  123. package/src/rate-limiter/createRateLimitedValue.ts +8 -4
  124. package/src/rate-limiter/createRateLimiter.ts +25 -62
  125. package/src/throttler/createThrottledSignal.ts +15 -4
  126. package/src/throttler/createThrottledValue.ts +11 -3
  127. package/src/throttler/createThrottler.ts +28 -56
  128. package/dist/cjs/compare/index.cjs +0 -10
  129. package/dist/cjs/compare/index.d.cts +0 -1
  130. package/dist/esm/compare/index.d.ts +0 -1
  131. package/dist/esm/compare/index.js +0 -2
  132. package/src/compare/index.ts +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"createAsyncThrottler.cjs","sources":["../../../src/async-throttler/createAsyncThrottler.ts"],"sourcesContent":["import { AsyncThrottler } from '@tanstack/pacer/async-throttler'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type { AsyncThrottlerOptions } from '@tanstack/pacer/async-throttler'\n\nexport interface SolidAsyncThrottler<TFn extends AnyAsyncFunction>\n extends Omit<\n AsyncThrottler<TFn>,\n | 'getSuccessCount'\n | 'getSettleCount'\n | 'getErrorCount'\n | 'getIsPending'\n | 'getIsExecuting'\n | 'getLastResult'\n | 'getLastExecutionTime'\n | 'getNextExecutionTime'\n > {\n successCount: Accessor<number>\n settleCount: Accessor<number>\n errorCount: Accessor<number>\n isPending: Accessor<boolean>\n isExecuting: Accessor<boolean>\n lastResult: Accessor<ReturnType<TFn> | undefined>\n lastExecutionTime: Accessor<number>\n nextExecutionTime: Accessor<number>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncThrottler` instance to limit how often an async function can execute.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Async throttling ensures an async function executes at most once within a specified time window,\n * regardless of how many times it is called. This is useful for rate-limiting expensive API calls,\n * database operations, or other async tasks.\n *\n * Unlike the non-async Throttler, this async version supports returning values from the throttled function,\n * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call\n * instead of setting the result on a state variable from within the throttled function.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and throttler instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncThrottler instance\n *\n * @example\n * ```tsx\n * // Basic API call throttling\n * const { maybeExecute } = createAsyncThrottler(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data;\n * },\n * { wait: 1000 }\n * );\n *\n * // With state management\n * const [data, setData] = createSignal(null);\n * const { maybeExecute } = createAsyncThrottler(\n * async (query) => {\n * const result = await searchAPI(query);\n * setData(result);\n * },\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false, // Skip trailing edge updates\n * onError: (error) => {\n * console.error('API call failed:', error);\n * }\n * }\n * );\n * ```\n */\nexport function createAsyncThrottler<TFn extends AnyAsyncFunction>(\n fn: TFn,\n initialOptions: AsyncThrottlerOptions<TFn>,\n): SolidAsyncThrottler<TFn> {\n const asyncThrottler = bindInstanceMethods(\n new AsyncThrottler<TFn>(fn, initialOptions),\n )\n\n const [successCount, setSuccessCount] = createSignal(\n asyncThrottler.getSuccessCount(),\n )\n const [settleCount, setSettleCount] = createSignal(\n asyncThrottler.getSettleCount(),\n )\n const [errorCount, setErrorCount] = createSignal(\n asyncThrottler.getErrorCount(),\n )\n const [isPending, setIsPending] = createSignal(asyncThrottler.getIsPending())\n const [isExecuting, setIsExecuting] = createSignal(\n asyncThrottler.getIsExecuting(),\n )\n const [lastResult, setLastResult] = createSignal(\n asyncThrottler.getLastResult(),\n )\n const [lastExecutionTime, setLastExecutionTime] = createSignal(\n asyncThrottler.getLastExecutionTime(),\n )\n const [nextExecutionTime, setNextExecutionTime] = createSignal(\n asyncThrottler.getNextExecutionTime(),\n )\n\n function setOptions(newOptions: Partial<AsyncThrottlerOptions<TFn>>) {\n asyncThrottler.setOptions({\n ...newOptions,\n onSettled: (throttler) => {\n setSuccessCount(throttler.getSuccessCount())\n setSettleCount(throttler.getSettleCount())\n setErrorCount(throttler.getErrorCount())\n setIsPending(throttler.getIsPending())\n setIsExecuting(throttler.getIsExecuting())\n setLastExecutionTime(throttler.getLastExecutionTime())\n setNextExecutionTime(throttler.getNextExecutionTime())\n setLastResult(throttler.getLastResult())\n\n const onSettled = newOptions.onSettled ?? initialOptions.onSettled\n onSettled?.(throttler)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...asyncThrottler,\n errorCount,\n isExecuting,\n isPending,\n lastExecutionTime,\n lastResult,\n nextExecutionTime,\n setOptions,\n settleCount,\n successCount,\n } as SolidAsyncThrottler<TFn>\n}\n"],"names":["asyncThrottler","bindInstanceMethods","AsyncThrottler","createSignal"],"mappings":";;;;;AA+EgB,SAAA,qBACd,IACA,gBAC0B;AAC1B,QAAMA,mBAAiBC,MAAA;AAAA,IACrB,IAAIC,eAAAA,eAAoB,IAAI,cAAc;AAAA,EAC5C;AAEM,QAAA,CAAC,cAAc,eAAe,IAAIC,QAAA;AAAA,IACtCH,iBAAe,gBAAgB;AAAA,EACjC;AACM,QAAA,CAAC,aAAa,cAAc,IAAIG,QAAA;AAAA,IACpCH,iBAAe,eAAe;AAAA,EAChC;AACM,QAAA,CAAC,YAAY,aAAa,IAAIG,QAAA;AAAA,IAClCH,iBAAe,cAAc;AAAA,EAC/B;AACA,QAAM,CAAC,WAAW,YAAY,IAAIG,QAAAA,aAAaH,iBAAe,cAAc;AACtE,QAAA,CAAC,aAAa,cAAc,IAAIG,QAAA;AAAA,IACpCH,iBAAe,eAAe;AAAA,EAChC;AACM,QAAA,CAAC,YAAY,aAAa,IAAIG,QAAA;AAAA,IAClCH,iBAAe,cAAc;AAAA,EAC/B;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIG,QAAA;AAAA,IAChDH,iBAAe,qBAAqB;AAAA,EACtC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIG,QAAA;AAAA,IAChDH,iBAAe,qBAAqB;AAAA,EACtC;AAEA,WAAS,WAAW,YAAiD;AACnEA,qBAAe,WAAW;AAAA,MACxB,GAAG;AAAA,MACH,WAAW,CAAC,cAAc;AACR,wBAAA,UAAU,iBAAiB;AAC5B,uBAAA,UAAU,gBAAgB;AAC3B,sBAAA,UAAU,eAAe;AAC1B,qBAAA,UAAU,cAAc;AACtB,uBAAA,UAAU,gBAAgB;AACpB,6BAAA,UAAU,sBAAsB;AAChC,6BAAA,UAAU,sBAAsB;AACvC,sBAAA,UAAU,eAAe;AAEjC,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAY;AAAA,MAAS;AAAA,IACvB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAGA;AAAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
1
+ {"version":3,"file":"createAsyncThrottler.cjs","sources":["../../../src/async-throttler/createAsyncThrottler.ts"],"sourcesContent":["import { AsyncThrottler } from '@tanstack/pacer/async-throttler'\nimport { useStore } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncThrottlerOptions,\n AsyncThrottlerState,\n} from '@tanstack/pacer/async-throttler'\n\nexport interface SolidAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = AsyncThrottlerState<TFn>,\n> extends Omit<AsyncThrottler<TFn>, 'store'> {\n /**\n * Reactive state that will be updated and re-rendered when the throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncThrottler` instance to limit how often an async function can execute.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Async throttling ensures an async function executes at most once within a specified time window,\n * regardless of how many times it is called. This is useful for rate-limiting expensive API calls,\n * database operations, or other async tasks.\n *\n * Unlike the non-async Throttler, this async version supports returning values from the throttled function,\n * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call\n * instead of setting the result on a state variable from within the throttled function.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and throttler instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncThrottler instance\n *\n * @example\n * ```tsx\n * // Basic API call throttling\n * const { maybeExecute } = createAsyncThrottler(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data;\n * },\n * { wait: 1000 }\n * );\n *\n * // With state management\n * const [data, setData] = createSignal(null);\n * const { maybeExecute } = createAsyncThrottler(\n * async (query) => {\n * const result = await searchAPI(query);\n * setData(result);\n * },\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false, // Skip trailing edge updates\n * onError: (error) => {\n * console.error('API call failed:', error);\n * }\n * }\n * );\n * ```\n */\nexport function createAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = AsyncThrottlerState<TFn>,\n>(\n fn: TFn,\n initialOptions: AsyncThrottlerOptions<TFn>,\n selector?: (state: AsyncThrottlerState<TFn>) => TSelected,\n): SolidAsyncThrottler<TFn, TSelected> {\n const asyncThrottler = new AsyncThrottler(fn, initialOptions)\n\n const state = useStore(asyncThrottler.store, selector)\n\n return {\n ...asyncThrottler,\n state,\n } as SolidAsyncThrottler<TFn, TSelected>\n}\n"],"names":["asyncThrottler","AsyncThrottler","useStore"],"mappings":";;;;AAuEO,SAAS,qBAId,IACA,gBACA,UACqC;AACrC,QAAMA,mBAAiB,IAAIC,8BAAe,IAAI,cAAc;AAE5D,QAAM,QAAQC,WAAAA,SAASF,iBAAe,OAAO,QAAQ;AAErD,SAAO;AAAA,IACL,GAAGA;AAAAA,IACH;AAAA,EAAA;AAEJ;;"}
@@ -1,15 +1,13 @@
1
- import { AsyncThrottler, AsyncThrottlerOptions } from '@tanstack/pacer/async-throttler';
1
+ import { AsyncThrottler, AsyncThrottlerOptions, AsyncThrottlerState } from '@tanstack/pacer/async-throttler';
2
2
  import { Accessor } from 'solid-js';
3
3
  import { AnyAsyncFunction } from '@tanstack/pacer/types';
4
- export interface SolidAsyncThrottler<TFn extends AnyAsyncFunction> extends Omit<AsyncThrottler<TFn>, 'getSuccessCount' | 'getSettleCount' | 'getErrorCount' | 'getIsPending' | 'getIsExecuting' | 'getLastResult' | 'getLastExecutionTime' | 'getNextExecutionTime'> {
5
- successCount: Accessor<number>;
6
- settleCount: Accessor<number>;
7
- errorCount: Accessor<number>;
8
- isPending: Accessor<boolean>;
9
- isExecuting: Accessor<boolean>;
10
- lastResult: Accessor<ReturnType<TFn> | undefined>;
11
- lastExecutionTime: Accessor<number>;
12
- nextExecutionTime: Accessor<number>;
4
+ export interface SolidAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = AsyncThrottlerState<TFn>> extends Omit<AsyncThrottler<TFn>, 'store'> {
5
+ /**
6
+ * Reactive state that will be updated and re-rendered when the throttler state changes
7
+ *
8
+ * Use this instead of `throttler.store.state`
9
+ */
10
+ readonly state: Accessor<Readonly<TSelected>>;
13
11
  }
14
12
  /**
15
13
  * A low-level Solid hook that creates an `AsyncThrottler` instance to limit how often an async function can execute.
@@ -61,4 +59,4 @@ export interface SolidAsyncThrottler<TFn extends AnyAsyncFunction> extends Omit<
61
59
  * );
62
60
  * ```
63
61
  */
64
- export declare function createAsyncThrottler<TFn extends AnyAsyncFunction>(fn: TFn, initialOptions: AsyncThrottlerOptions<TFn>): SolidAsyncThrottler<TFn>;
62
+ export declare function createAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = AsyncThrottlerState<TFn>>(fn: TFn, initialOptions: AsyncThrottlerOptions<TFn>, selector?: (state: AsyncThrottlerState<TFn>) => TSelected): SolidAsyncThrottler<TFn, TSelected>;
@@ -1,57 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const batcher = require("@tanstack/pacer/batcher");
4
- const solidJs = require("solid-js");
5
- const utils = require("@tanstack/pacer/utils");
6
- function createBatcher(fn, initialOptions = {}) {
7
- const batcher$1 = utils.bindInstanceMethods(new batcher.Batcher(fn, initialOptions));
8
- const [allItems, setAllItems] = solidJs.createSignal(
9
- batcher$1.peekAllItems()
10
- );
11
- const [batchExecutionCount, setBatchExecutionCount] = solidJs.createSignal(
12
- batcher$1.getBatchExecutionCount()
13
- );
14
- const [itemExecutionCount, setItemExecutionCount] = solidJs.createSignal(
15
- batcher$1.getItemExecutionCount()
16
- );
17
- const [isEmpty, setIsEmpty] = solidJs.createSignal(batcher$1.getIsEmpty());
18
- const [isRunning, setIsRunning] = solidJs.createSignal(batcher$1.getIsRunning());
19
- const [size, setSize] = solidJs.createSignal(batcher$1.getSize());
20
- function setOptions(newOptions) {
21
- batcher$1.setOptions({
22
- ...newOptions,
23
- onItemsChange: (batcher2) => {
24
- setAllItems(batcher2.peekAllItems());
25
- setBatchExecutionCount(batcher2.getBatchExecutionCount());
26
- setItemExecutionCount(batcher2.getItemExecutionCount());
27
- setIsEmpty(batcher2.getIsEmpty());
28
- setSize(batcher2.getSize());
29
- const onItemsChange = newOptions.onItemsChange ?? initialOptions.onItemsChange;
30
- onItemsChange == null ? void 0 : onItemsChange(batcher2);
31
- },
32
- onExecute: (batcher2) => {
33
- setBatchExecutionCount(batcher2.getBatchExecutionCount());
34
- setItemExecutionCount(batcher2.getItemExecutionCount());
35
- const onExecute = newOptions.onExecute ?? initialOptions.onExecute;
36
- onExecute == null ? void 0 : onExecute(batcher2);
37
- },
38
- onIsRunningChange: (batcher2) => {
39
- setIsRunning(batcher2.getIsRunning());
40
- const onIsRunningChange = newOptions.onIsRunningChange ?? initialOptions.onIsRunningChange;
41
- onIsRunningChange == null ? void 0 : onIsRunningChange(batcher2);
42
- }
43
- });
44
- }
45
- setOptions(initialOptions);
4
+ const solidStore = require("@tanstack/solid-store");
5
+ function createBatcher(fn, initialOptions = {}, selector) {
6
+ const batcher$1 = new batcher.Batcher(fn, initialOptions);
7
+ const state = solidStore.useStore(batcher$1.store, selector);
46
8
  return {
47
9
  ...batcher$1,
48
- allItems,
49
- batchExecutionCount,
50
- isEmpty,
51
- isRunning,
52
- itemExecutionCount,
53
- size,
54
- setOptions
10
+ state
55
11
  };
56
12
  }
57
13
  exports.createBatcher = createBatcher;
@@ -1 +1 @@
1
- {"version":3,"file":"createBatcher.cjs","sources":["../../../src/batcher/createBatcher.ts"],"sourcesContent":["import { Batcher } from '@tanstack/pacer/batcher'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { BatcherOptions } from '@tanstack/pacer/batcher'\n\nexport interface SolidBatcher<TValue>\n extends Omit<\n Batcher<TValue>,\n | 'peekAllItems'\n | 'getBatchExecutionCount'\n | 'getIsEmpty'\n | 'getIsRunning'\n | 'getItemExecutionCount'\n | 'getSize'\n > {\n /**\n * Signal version of `peekAllItems`\n */\n allItems: Accessor<Array<TValue>>\n /**\n * Signal version of `getBatchExecutionCount`\n */\n batchExecutionCount: Accessor<number>\n /**\n * Signal version of `getIsEmpty`\n */\n isEmpty: Accessor<boolean>\n /**\n * Signal version of `getIsRunning`\n */\n isRunning: Accessor<boolean>\n /**\n * Signal version of `getItemExecutionCount`\n */\n itemExecutionCount: Accessor<number>\n /**\n * Signal version of `getSize`\n */\n size: Accessor<number>\n}\n\n/**\n * Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Batch processing of items using the provided `fn` function\n * - Configurable batch size and wait time\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The batcher collects items and processes them in batches based on:\n * - Maximum batch size\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\n *\n * Example usage:\n * ```tsx\n * const batcher = createBatcher(\n * (items) => {\n * // Process batch of items\n * console.log('Processing batch:', items);\n * },\n * {\n * maxSize: 5,\n * wait: 2000,\n * onExecute: (batcher) => console.log('Batch executed'),\n * getShouldExecute: (items) => items.length >= 3\n * }\n * );\n *\n * // Add items to batch\n * batcher.addItem('task1');\n * batcher.addItem('task2');\n *\n * // Control the batcher\n * batcher.stop(); // Pause processing\n * batcher.start(); // Resume processing\n *\n * // Access batcher state via signals\n * console.log('Items:', batcher.allItems());\n * console.log('Size:', batcher.size());\n * console.log('Is empty:', batcher.isEmpty());\n * console.log('Is running:', batcher.isRunning());\n * console.log('Batch count:', batcher.batchExecutionCount());\n * console.log('Item count:', batcher.itemExecutionCount());\n * ```\n */\nexport function createBatcher<TValue>(\n fn: (items: Array<TValue>) => void,\n initialOptions: BatcherOptions<TValue> = {},\n): SolidBatcher<TValue> {\n const batcher = bindInstanceMethods(new Batcher<TValue>(fn, initialOptions))\n\n const [allItems, setAllItems] = createSignal<Array<TValue>>(\n batcher.peekAllItems(),\n )\n const [batchExecutionCount, setBatchExecutionCount] = createSignal(\n batcher.getBatchExecutionCount(),\n )\n const [itemExecutionCount, setItemExecutionCount] = createSignal(\n batcher.getItemExecutionCount(),\n )\n const [isEmpty, setIsEmpty] = createSignal(batcher.getIsEmpty())\n const [isRunning, setIsRunning] = createSignal(batcher.getIsRunning())\n const [size, setSize] = createSignal(batcher.getSize())\n\n function setOptions(newOptions: Partial<BatcherOptions<TValue>>) {\n batcher.setOptions({\n ...newOptions,\n onItemsChange: (batcher) => {\n setAllItems(batcher.peekAllItems())\n setBatchExecutionCount(batcher.getBatchExecutionCount())\n setItemExecutionCount(batcher.getItemExecutionCount())\n setIsEmpty(batcher.getIsEmpty())\n setSize(batcher.getSize())\n\n const onItemsChange =\n newOptions.onItemsChange ?? initialOptions.onItemsChange\n onItemsChange?.(batcher)\n },\n onExecute: (batcher) => {\n setBatchExecutionCount(batcher.getBatchExecutionCount())\n setItemExecutionCount(batcher.getItemExecutionCount())\n\n const onExecute = newOptions.onExecute ?? initialOptions.onExecute\n onExecute?.(batcher)\n },\n onIsRunningChange: (batcher) => {\n setIsRunning(batcher.getIsRunning())\n\n const onIsRunningChange =\n newOptions.onIsRunningChange ?? initialOptions.onIsRunningChange\n onIsRunningChange?.(batcher)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...batcher,\n allItems,\n batchExecutionCount,\n isEmpty,\n isRunning,\n itemExecutionCount,\n size,\n setOptions,\n } as SolidBatcher<TValue>\n}\n"],"names":["batcher","bindInstanceMethods","Batcher","createSignal"],"mappings":";;;;;AAyFO,SAAS,cACd,IACA,iBAAyC,IACnB;AACtB,QAAMA,YAAUC,MAAAA,oBAAoB,IAAIC,QAAgB,QAAA,IAAI,cAAc,CAAC;AAErE,QAAA,CAAC,UAAU,WAAW,IAAIC,QAAA;AAAA,IAC9BH,UAAQ,aAAa;AAAA,EACvB;AACM,QAAA,CAAC,qBAAqB,sBAAsB,IAAIG,QAAA;AAAA,IACpDH,UAAQ,uBAAuB;AAAA,EACjC;AACM,QAAA,CAAC,oBAAoB,qBAAqB,IAAIG,QAAA;AAAA,IAClDH,UAAQ,sBAAsB;AAAA,EAChC;AACA,QAAM,CAAC,SAAS,UAAU,IAAIG,QAAAA,aAAaH,UAAQ,YAAY;AAC/D,QAAM,CAAC,WAAW,YAAY,IAAIG,QAAAA,aAAaH,UAAQ,cAAc;AACrE,QAAM,CAAC,MAAM,OAAO,IAAIG,QAAAA,aAAaH,UAAQ,SAAS;AAEtD,WAAS,WAAW,YAA6C;AAC/DA,cAAQ,WAAW;AAAA,MACjB,GAAG;AAAA,MACH,eAAe,CAACA,aAAY;AACdA,oBAAAA,SAAQ,cAAc;AACXA,+BAAAA,SAAQ,wBAAwB;AACjCA,8BAAAA,SAAQ,uBAAuB;AAC1CA,mBAAAA,SAAQ,YAAY;AACvBA,gBAAAA,SAAQ,SAAS;AAEnB,cAAA,gBACJ,WAAW,iBAAiB,eAAe;AAC7C,uDAAgBA;AAAAA,MAClB;AAAA,MACA,WAAW,CAACA,aAAY;AACCA,+BAAAA,SAAQ,wBAAwB;AACjCA,8BAAAA,SAAQ,uBAAuB;AAE/C,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MACd;AAAA,MACA,mBAAmB,CAACA,aAAY;AACjBA,qBAAAA,SAAQ,cAAc;AAE7B,cAAA,oBACJ,WAAW,qBAAqB,eAAe;AACjD,+DAAoBA;AAAAA,MAAO;AAAA,IAC7B,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAGA;AAAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
1
+ {"version":3,"file":"createBatcher.cjs","sources":["../../../src/batcher/createBatcher.ts"],"sourcesContent":["import { Batcher } from '@tanstack/pacer/batcher'\nimport { useStore } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type { BatcherOptions, BatcherState } from '@tanstack/pacer/batcher'\n\nexport interface SolidBatcher<TValue, TSelected = BatcherState<TValue>>\n extends Omit<Batcher<TValue>, 'store'> {\n /**\n * Reactive state that will be updated when the batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n}\n\n/**\n * Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Batch processing of items using the provided `fn` function\n * - Configurable batch size and wait time\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The batcher collects items and processes them in batches based on:\n * - Maximum batch size\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\n *\n * Example usage:\n * ```tsx\n * const batcher = createBatcher(\n * (items) => {\n * // Process batch of items\n * console.log('Processing batch:', items);\n * },\n * {\n * maxSize: 5,\n * wait: 2000,\n * onExecute: (batcher) => console.log('Batch executed'),\n * getShouldExecute: (items) => items.length >= 3\n * }\n * );\n *\n * // Add items to batch\n * batcher.addItem('task1');\n * batcher.addItem('task2');\n *\n * // Control the batcher\n * batcher.stop(); // Pause processing\n * batcher.start(); // Resume processing\n *\n * // Access batcher state via signals\n * console.log('Items:', batcher.allItems());\n * console.log('Size:', batcher.size());\n * console.log('Is empty:', batcher.isEmpty());\n * console.log('Is running:', batcher.isRunning());\n * console.log('Batch count:', batcher.executionCount());\n * console.log('Item count:', batcher.totalItemsProcessed());\n * ```\n */\nexport function createBatcher<TValue, TSelected = BatcherState<TValue>>(\n fn: (items: Array<TValue>) => void,\n initialOptions: BatcherOptions<TValue> = {},\n selector?: (state: BatcherState<TValue>) => TSelected,\n): SolidBatcher<TValue, TSelected> {\n const batcher = new Batcher(fn, initialOptions)\n\n const state = useStore(batcher.store, selector)\n return {\n ...batcher,\n state,\n } as SolidBatcher<TValue, TSelected>\n}\n"],"names":["batcher","Batcher","useStore"],"mappings":";;;;AA8DO,SAAS,cACd,IACA,iBAAyC,CAAA,GACzC,UACiC;AACjC,QAAMA,YAAU,IAAIC,gBAAQ,IAAI,cAAc;AAE9C,QAAM,QAAQC,WAAAA,SAASF,UAAQ,OAAO,QAAQ;AAC9C,SAAO;AAAA,IACL,GAAGA;AAAAA,IACH;AAAA,EAAA;AAEJ;;"}
@@ -1,30 +1,12 @@
1
- import { Batcher, BatcherOptions } from '@tanstack/pacer/batcher';
1
+ import { Batcher, BatcherOptions, BatcherState } from '@tanstack/pacer/batcher';
2
2
  import { Accessor } from 'solid-js';
3
- export interface SolidBatcher<TValue> extends Omit<Batcher<TValue>, 'peekAllItems' | 'getBatchExecutionCount' | 'getIsEmpty' | 'getIsRunning' | 'getItemExecutionCount' | 'getSize'> {
3
+ export interface SolidBatcher<TValue, TSelected = BatcherState<TValue>> extends Omit<Batcher<TValue>, 'store'> {
4
4
  /**
5
- * Signal version of `peekAllItems`
5
+ * Reactive state that will be updated when the batcher state changes
6
+ *
7
+ * Use this instead of `batcher.store.state`
6
8
  */
7
- allItems: Accessor<Array<TValue>>;
8
- /**
9
- * Signal version of `getBatchExecutionCount`
10
- */
11
- batchExecutionCount: Accessor<number>;
12
- /**
13
- * Signal version of `getIsEmpty`
14
- */
15
- isEmpty: Accessor<boolean>;
16
- /**
17
- * Signal version of `getIsRunning`
18
- */
19
- isRunning: Accessor<boolean>;
20
- /**
21
- * Signal version of `getItemExecutionCount`
22
- */
23
- itemExecutionCount: Accessor<number>;
24
- /**
25
- * Signal version of `getSize`
26
- */
27
- size: Accessor<number>;
9
+ readonly state: Accessor<Readonly<TSelected>>;
28
10
  }
29
11
  /**
30
12
  * Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.
@@ -69,8 +51,8 @@ export interface SolidBatcher<TValue> extends Omit<Batcher<TValue>, 'peekAllItem
69
51
  * console.log('Size:', batcher.size());
70
52
  * console.log('Is empty:', batcher.isEmpty());
71
53
  * console.log('Is running:', batcher.isRunning());
72
- * console.log('Batch count:', batcher.batchExecutionCount());
73
- * console.log('Item count:', batcher.itemExecutionCount());
54
+ * console.log('Batch count:', batcher.executionCount());
55
+ * console.log('Item count:', batcher.totalItemsProcessed());
74
56
  * ```
75
57
  */
76
- export declare function createBatcher<TValue>(fn: (items: Array<TValue>) => void, initialOptions?: BatcherOptions<TValue>): SolidBatcher<TValue>;
58
+ export declare function createBatcher<TValue, TSelected = BatcherState<TValue>>(fn: (items: Array<TValue>) => void, initialOptions?: BatcherOptions<TValue>, selector?: (state: BatcherState<TValue>) => TSelected): SolidBatcher<TValue, TSelected>;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const solidJs = require("solid-js");
4
4
  const createDebouncer = require("./createDebouncer.cjs");
5
- function createDebouncedSignal(value, initialOptions) {
5
+ function createDebouncedSignal(value, initialOptions, selector) {
6
6
  const [debouncedValue, setDebouncedValue] = solidJs.createSignal(value);
7
- const debouncer = createDebouncer.createDebouncer(setDebouncedValue, initialOptions);
7
+ const debouncer = createDebouncer.createDebouncer(setDebouncedValue, initialOptions, selector);
8
8
  return [debouncedValue, debouncer.maybeExecute, debouncer];
9
9
  }
10
10
  exports.createDebouncedSignal = createDebouncedSignal;
@@ -1 +1 @@
1
- {"version":3,"file":"createDebouncedSignal.cjs","sources":["../../../src/debouncer/createDebouncedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createDebouncer } from './createDebouncer'\nimport type { SolidDebouncer } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { DebouncerOptions } from '@tanstack/pacer/debouncer'\n\n/**\n * A Solid hook that creates a debounced state value, combining Solid's createSignal with debouncing functionality.\n * This hook provides both the current debounced value and methods to update it.\n *\n * The state value is only updated after the specified wait time has elapsed since the last update attempt.\n * If another update is attempted before the wait time expires, the timer resets and starts waiting again.\n * This is useful for handling frequent state updates that should be throttled, like search input values\n * or window resize dimensions.\n *\n * The hook returns a tuple containing:\n * - The current debounced value accessor\n * - A function to update the debounced value\n * - The debouncer instance with additional control methods and state signals\n *\n * @example\n * ```tsx\n * // Debounced search input\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {\n * wait: 500 // Wait 500ms after last keystroke\n * });\n *\n * // Update value - will be debounced\n * const handleChange = (e) => {\n * setSearchTerm(e.target.value);\n * };\n *\n * // Access debouncer state via signals\n * console.log('Executions:', debouncer.executionCount());\n * console.log('Is pending:', debouncer.isPending());\n *\n * // In onExecute callback, use get* methods\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {\n * wait: 500,\n * onExecute: (debouncer) => {\n * console.log('Total executions:', debouncer.getExecutionCount());\n * }\n * });\n * ```\n */\nexport function createDebouncedSignal<TValue>(\n value: TValue,\n initialOptions: DebouncerOptions<Setter<TValue>>,\n): [Accessor<TValue>, Setter<TValue>, SolidDebouncer<Setter<TValue>>] {\n const [debouncedValue, setDebouncedValue] = createSignal<TValue>(value)\n\n const debouncer = createDebouncer(setDebouncedValue, initialOptions)\n\n return [debouncedValue, debouncer.maybeExecute as Setter<TValue>, debouncer]\n}\n"],"names":["createSignal","createDebouncer"],"mappings":";;;;AA6CgB,SAAA,sBACd,OACA,gBACoE;AACpE,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,QAAAA,aAAqB,KAAK;AAEhE,QAAA,YAAYC,gBAAAA,gBAAgB,mBAAmB,cAAc;AAEnE,SAAO,CAAC,gBAAgB,UAAU,cAAgC,SAAS;AAC7E;;"}
1
+ {"version":3,"file":"createDebouncedSignal.cjs","sources":["../../../src/debouncer/createDebouncedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createDebouncer } from './createDebouncer'\nimport type { SolidDebouncer } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\n/**\n * A Solid hook that creates a debounced state value, combining Solid's createSignal with debouncing functionality.\n * This hook provides both the current debounced value and methods to update it.\n *\n * The state value is only updated after the specified wait time has elapsed since the last update attempt.\n * If another update is attempted before the wait time expires, the timer resets and starts waiting again.\n * This is useful for handling frequent state updates that should be throttled, like search input values\n * or window resize dimensions.\n *\n * The hook returns a tuple containing:\n * - The current debounced value accessor\n * - A function to update the debounced value\n * - The debouncer instance with additional control methods and state signals\n *\n * @example\n * ```tsx\n * // Debounced search input\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {\n * wait: 500 // Wait 500ms after last keystroke\n * });\n *\n * // Update value - will be debounced\n * const handleChange = (e) => {\n * setSearchTerm(e.target.value);\n * };\n *\n * // Access debouncer state via signals\n * console.log('Executions:', debouncer.executionCount());\n * console.log('Is pending:', debouncer.isPending());\n *\n * // In onExecute callback, use get* methods\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {\n * wait: 500,\n * onExecute: (debouncer) => {\n * console.log('Total executions:', debouncer.getExecutionCount());\n * }\n * });\n * ```\n */\nexport function createDebouncedSignal<\n TValue,\n TSelected = DebouncerState<Setter<TValue>>,\n>(\n value: TValue,\n initialOptions: DebouncerOptions<Setter<TValue>>,\n selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidDebouncer<Setter<TValue>, TSelected>,\n] {\n const [debouncedValue, setDebouncedValue] = createSignal<TValue>(value)\n\n const debouncer = createDebouncer(setDebouncedValue, initialOptions, selector)\n\n return [debouncedValue, debouncer.maybeExecute as Setter<TValue>, debouncer]\n}\n"],"names":["createSignal","createDebouncer"],"mappings":";;;;AAgDO,SAAS,sBAId,OACA,gBACA,UAKA;AACA,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,QAAAA,aAAqB,KAAK;AAEtE,QAAM,YAAYC,gBAAAA,gBAAgB,mBAAmB,gBAAgB,QAAQ;AAE7E,SAAO,CAAC,gBAAgB,UAAU,cAAgC,SAAS;AAC7E;;"}
@@ -1,6 +1,6 @@
1
1
  import { SolidDebouncer } from './createDebouncer.cjs';
2
2
  import { Accessor, Setter } from 'solid-js';
3
- import { DebouncerOptions } from '@tanstack/pacer/debouncer';
3
+ import { DebouncerOptions, DebouncerState } from '@tanstack/pacer/debouncer';
4
4
  /**
5
5
  * A Solid hook that creates a debounced state value, combining Solid's createSignal with debouncing functionality.
6
6
  * This hook provides both the current debounced value and methods to update it.
@@ -40,4 +40,8 @@ import { DebouncerOptions } from '@tanstack/pacer/debouncer';
40
40
  * });
41
41
  * ```
42
42
  */
43
- export declare function createDebouncedSignal<TValue>(value: TValue, initialOptions: DebouncerOptions<Setter<TValue>>): [Accessor<TValue>, Setter<TValue>, SolidDebouncer<Setter<TValue>>];
43
+ export declare function createDebouncedSignal<TValue, TSelected = DebouncerState<Setter<TValue>>>(value: TValue, initialOptions: DebouncerOptions<Setter<TValue>>, selector?: (state: DebouncerState<Setter<TValue>>) => TSelected): [
44
+ Accessor<TValue>,
45
+ Setter<TValue>,
46
+ SolidDebouncer<Setter<TValue>, TSelected>
47
+ ];
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const solidJs = require("solid-js");
4
4
  const createDebouncedSignal = require("./createDebouncedSignal.cjs");
5
- function createDebouncedValue(value, initialOptions) {
5
+ function createDebouncedValue(value, initialOptions, selector) {
6
6
  const [debouncedValue, setDebouncedValue, debouncer] = createDebouncedSignal.createDebouncedSignal(
7
7
  value(),
8
- initialOptions
8
+ initialOptions,
9
+ selector
9
10
  );
10
11
  solidJs.createEffect(() => {
11
12
  setDebouncedValue(value());
@@ -1 +1 @@
1
- {"version":3,"file":"createDebouncedValue.cjs","sources":["../../../src/debouncer/createDebouncedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createDebouncedSignal } from './createDebouncedSignal'\nimport type { SolidDebouncer } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { DebouncerOptions } from '@tanstack/pacer/debouncer'\n\n/**\n * A Solid hook that creates a debounced value that updates only after a specified delay.\n * Unlike createDebouncedSignal, this hook automatically tracks changes to the input value\n * and updates the debounced value accordingly.\n *\n * The debounced value will only update after the specified wait time has elapsed since\n * the last change to the input value. If the input value changes again before the wait\n * time expires, the timer resets and starts waiting again.\n *\n * This is useful for deriving debounced values from props or state that change frequently,\n * like search queries or form inputs, where you want to limit how often downstream effects\n * or calculations occur.\n *\n * The hook returns a tuple containing:\n * - An Accessor that provides the current debounced value\n * - The debouncer instance with control methods\n *\n * @example\n * ```tsx\n * // Debounce a search query\n * const [searchQuery, setSearchQuery] = createSignal('');\n * const [debouncedQuery, debouncer] = createDebouncedValue(searchQuery, {\n * wait: 500 // Wait 500ms after last change\n * });\n *\n * // debouncedQuery will update 500ms after searchQuery stops changing\n * createEffect(() => {\n * fetchSearchResults(debouncedQuery());\n * });\n *\n * // Control the debouncer\n * debouncer.cancel(); // Cancel any pending updates\n * ```\n */\nexport function createDebouncedValue<TValue>(\n value: Accessor<TValue>,\n initialOptions: DebouncerOptions<Setter<TValue>>,\n): [Accessor<TValue>, SolidDebouncer<Setter<TValue>>] {\n const [debouncedValue, setDebouncedValue, debouncer] = createDebouncedSignal(\n value(),\n initialOptions,\n )\n\n createEffect(() => {\n setDebouncedValue(value() as any)\n })\n\n return [debouncedValue, debouncer]\n}\n"],"names":["createDebouncedSignal","createEffect"],"mappings":";;;;AAwCgB,SAAA,qBACd,OACA,gBACoD;AACpD,QAAM,CAAC,gBAAgB,mBAAmB,SAAS,IAAIA,sBAAA;AAAA,IACrD,MAAM;AAAA,IACN;AAAA,EACF;AAEAC,UAAAA,aAAa,MAAM;AACjB,sBAAkB,OAAc;AAAA,EAAA,CACjC;AAEM,SAAA,CAAC,gBAAgB,SAAS;AACnC;;"}
1
+ {"version":3,"file":"createDebouncedValue.cjs","sources":["../../../src/debouncer/createDebouncedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createDebouncedSignal } from './createDebouncedSignal'\nimport type { SolidDebouncer } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\n/**\n * A Solid hook that creates a debounced value that updates only after a specified delay.\n * Unlike createDebouncedSignal, this hook automatically tracks changes to the input value\n * and updates the debounced value accordingly.\n *\n * The debounced value will only update after the specified wait time has elapsed since\n * the last change to the input value. If the input value changes again before the wait\n * time expires, the timer resets and starts waiting again.\n *\n * This is useful for deriving debounced values from props or state that change frequently,\n * like search queries or form inputs, where you want to limit how often downstream effects\n * or calculations occur.\n *\n * The hook returns a tuple containing:\n * - An Accessor that provides the current debounced value\n * - The debouncer instance with control methods\n *\n * @example\n * ```tsx\n * // Debounce a search query\n * const [searchQuery, setSearchQuery] = createSignal('');\n * const [debouncedQuery, debouncer] = createDebouncedValue(searchQuery, {\n * wait: 500 // Wait 500ms after last change\n * });\n *\n * // debouncedQuery will update 500ms after searchQuery stops changing\n * createEffect(() => {\n * fetchSearchResults(debouncedQuery());\n * });\n *\n * // Control the debouncer\n * debouncer.cancel(); // Cancel any pending updates\n * ```\n */\nexport function createDebouncedValue<\n TValue,\n TSelected = DebouncerState<Setter<TValue>>,\n>(\n value: Accessor<TValue>,\n initialOptions: DebouncerOptions<Setter<TValue>>,\n selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): [Accessor<TValue>, SolidDebouncer<Setter<TValue>, TSelected>] {\n const [debouncedValue, setDebouncedValue, debouncer] = createDebouncedSignal(\n value(),\n initialOptions,\n selector,\n )\n\n createEffect(() => {\n setDebouncedValue(value() as any)\n })\n\n return [debouncedValue, debouncer]\n}\n"],"names":["createDebouncedSignal","createEffect"],"mappings":";;;;AA2CO,SAAS,qBAId,OACA,gBACA,UAC+D;AAC/D,QAAM,CAAC,gBAAgB,mBAAmB,SAAS,IAAIA,sBAAAA;AAAAA,IACrD,MAAA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGFC,UAAAA,aAAa,MAAM;AACjB,sBAAkB,OAAc;AAAA,EAAA,CACjC;AAED,SAAO,CAAC,gBAAgB,SAAS;AACnC;;"}
@@ -1,6 +1,6 @@
1
1
  import { SolidDebouncer } from './createDebouncer.cjs';
2
2
  import { Accessor, Setter } from 'solid-js';
3
- import { DebouncerOptions } from '@tanstack/pacer/debouncer';
3
+ import { DebouncerOptions, DebouncerState } from '@tanstack/pacer/debouncer';
4
4
  /**
5
5
  * A Solid hook that creates a debounced value that updates only after a specified delay.
6
6
  * Unlike createDebouncedSignal, this hook automatically tracks changes to the input value
@@ -35,4 +35,4 @@ import { DebouncerOptions } from '@tanstack/pacer/debouncer';
35
35
  * debouncer.cancel(); // Cancel any pending updates
36
36
  * ```
37
37
  */
38
- export declare function createDebouncedValue<TValue>(value: Accessor<TValue>, initialOptions: DebouncerOptions<Setter<TValue>>): [Accessor<TValue>, SolidDebouncer<Setter<TValue>>];
38
+ export declare function createDebouncedValue<TValue, TSelected = DebouncerState<Setter<TValue>>>(value: Accessor<TValue>, initialOptions: DebouncerOptions<Setter<TValue>>, selector?: (state: DebouncerState<Setter<TValue>>) => TSelected): [Accessor<TValue>, SolidDebouncer<Setter<TValue>, TSelected>];
@@ -2,35 +2,18 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const debouncer = require("@tanstack/pacer/debouncer");
4
4
  const solidJs = require("solid-js");
5
- const utils = require("@tanstack/pacer/utils");
6
- function createDebouncer(fn, initialOptions) {
7
- const debouncer$1 = utils.bindInstanceMethods(new debouncer.Debouncer(fn, initialOptions));
8
- const [executionCount, setExecutionCount] = solidJs.createSignal(
9
- debouncer$1.getExecutionCount()
10
- );
11
- const [isPending, setIsPending] = solidJs.createSignal(debouncer$1.getIsPending());
12
- function setOptions(newOptions) {
13
- debouncer$1.setOptions({
14
- ...newOptions,
15
- onExecute: (debouncer2) => {
16
- setExecutionCount(debouncer2.getExecutionCount());
17
- setIsPending(debouncer2.getIsPending());
18
- const onExecute = newOptions.onExecute ?? initialOptions.onExecute;
19
- onExecute == null ? void 0 : onExecute(debouncer2);
20
- }
21
- });
22
- }
23
- setOptions(initialOptions);
5
+ const solidStore = require("@tanstack/solid-store");
6
+ function createDebouncer(fn, initialOptions, selector) {
7
+ const asyncDebouncer = new debouncer.Debouncer(fn, initialOptions);
8
+ const state = solidStore.useStore(asyncDebouncer.store, selector);
24
9
  solidJs.createEffect(() => {
25
10
  solidJs.onCleanup(() => {
26
- debouncer$1.cancel();
11
+ asyncDebouncer.cancel();
27
12
  });
28
13
  });
29
14
  return {
30
- ...debouncer$1,
31
- executionCount,
32
- isPending,
33
- setOptions
15
+ ...asyncDebouncer,
16
+ state
34
17
  };
35
18
  }
36
19
  exports.createDebouncer = createDebouncer;
@@ -1 +1 @@
1
- {"version":3,"file":"createDebouncer.cjs","sources":["../../../src/debouncer/createDebouncer.ts"],"sourcesContent":["import { Debouncer } from '@tanstack/pacer/debouncer'\nimport { createEffect, createSignal, onCleanup } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { DebouncerOptions } from '@tanstack/pacer/debouncer'\n\n/**\n * An extension of the Debouncer class that adds Solid signals to access the internal state of the debouncer\n */\nexport interface SolidDebouncer<TFn extends AnyFunction>\n extends Omit<Debouncer<TFn>, 'getExecutionCount' | 'getIsPending'> {\n executionCount: Accessor<number>\n isPending: Accessor<boolean>\n}\n\n/**\n * A Solid hook that creates and manages a Debouncer instance.\n *\n * This is a lower-level hook that provides direct access to the Debouncer's functionality without\n * any built-in state management. This allows you to integrate it with any state management solution\n * you prefer (createSignal, Redux, Zustand, etc.).\n *\n * This hook provides debouncing functionality to limit how often a function can be called,\n * waiting for a specified delay before executing the latest call. This is useful for handling\n * frequent events like window resizing, scroll events, or real-time search inputs.\n *\n * The debouncer will only execute the function after the specified wait time has elapsed\n * since the last call. If the function is called again before the wait time expires, the\n * timer resets and starts waiting again.\n *\n * @example\n * ```tsx\n * // Debounce a search function to limit API calls\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 } // Wait 500ms after last keystroke\n * );\n *\n * // In an event handler\n * const handleChange = (e) => {\n * debouncer.maybeExecute(e.target.value);\n * };\n *\n * // Access debouncer state via signals\n * console.log('Executions:', debouncer.executionCount());\n * console.log('Is pending:', debouncer.isPending());\n *\n * // Update options\n * debouncer.setOptions({ wait: 1000 });\n * ```\n */\nexport function createDebouncer<TFn extends AnyFunction>(\n fn: TFn,\n initialOptions: DebouncerOptions<TFn>,\n): SolidDebouncer<TFn> {\n const debouncer = bindInstanceMethods(new Debouncer<TFn>(fn, initialOptions))\n\n const [executionCount, setExecutionCount] = createSignal(\n debouncer.getExecutionCount(),\n )\n const [isPending, setIsPending] = createSignal(debouncer.getIsPending())\n\n function setOptions(newOptions: Partial<DebouncerOptions<TFn>>) {\n debouncer.setOptions({\n ...newOptions,\n onExecute: (debouncer) => {\n setExecutionCount(debouncer.getExecutionCount())\n setIsPending(debouncer.getIsPending())\n\n const onExecute = newOptions.onExecute ?? initialOptions.onExecute\n onExecute?.(debouncer)\n },\n })\n }\n\n setOptions(initialOptions)\n\n createEffect(() => {\n onCleanup(() => {\n debouncer.cancel()\n })\n })\n\n return {\n ...debouncer,\n executionCount,\n isPending,\n setOptions,\n } as SolidDebouncer<TFn>\n}\n"],"names":["debouncer","bindInstanceMethods","Debouncer","createSignal","createEffect","onCleanup"],"mappings":";;;;;AAoDgB,SAAA,gBACd,IACA,gBACqB;AACrB,QAAMA,cAAYC,MAAAA,oBAAoB,IAAIC,UAAe,UAAA,IAAI,cAAc,CAAC;AAEtE,QAAA,CAAC,gBAAgB,iBAAiB,IAAIC,QAAA;AAAA,IAC1CH,YAAU,kBAAkB;AAAA,EAC9B;AACA,QAAM,CAAC,WAAW,YAAY,IAAIG,QAAAA,aAAaH,YAAU,cAAc;AAEvE,WAAS,WAAW,YAA4C;AAC9DA,gBAAU,WAAW;AAAA,MACnB,GAAG;AAAA,MACH,WAAW,CAACA,eAAc;AACNA,0BAAAA,WAAU,mBAAmB;AAClCA,qBAAAA,WAAU,cAAc;AAE/B,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MAAS;AAAA,IACvB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAEzBI,UAAAA,aAAa,MAAM;AACjBC,YAAAA,UAAU,MAAM;AACdL,kBAAU,OAAO;AAAA,IAAA,CAClB;AAAA,EAAA,CACF;AAEM,SAAA;AAAA,IACL,GAAGA;AAAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
1
+ {"version":3,"file":"createDebouncer.cjs","sources":["../../../src/debouncer/createDebouncer.ts"],"sourcesContent":["import { Debouncer } from '@tanstack/pacer/debouncer'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { useStore } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\nexport interface SolidDebouncer<\n TFn extends AnyFunction,\n TSelected = DebouncerState<TFn>,\n> extends Omit<Debouncer<TFn>, 'store'> {\n /**\n * Reactive state that will be updated when the debouncer state changes\n *\n * Use this instead of `debouncer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n}\n\n/**\n * A Solid hook that creates and manages a Debouncer instance.\n *\n * This is a lower-level hook that provides direct access to the Debouncer's functionality without\n * any built-in state management. This allows you to integrate it with any state management solution\n * you prefer (createSignal, Redux, Zustand, etc.).\n *\n * This hook provides debouncing functionality to limit how often a function can be called,\n * waiting for a specified delay before executing the latest call. This is useful for handling\n * frequent events like window resizing, scroll events, or real-time search inputs.\n *\n * The debouncer will only execute the function after the specified wait time has elapsed\n * since the last call. If the function is called again before the wait time expires, the\n * timer resets and starts waiting again.\n *\n * @example\n * ```tsx\n * // Debounce a search function to limit API calls\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 } // Wait 500ms after last keystroke\n * );\n *\n * // In an event handler\n * const handleChange = (e) => {\n * debouncer.maybeExecute(e.target.value);\n * };\n *\n * // Access debouncer state via signals\n * console.log('Executions:', debouncer.executionCount());\n * console.log('Is pending:', debouncer.isPending());\n *\n * // Update options\n * debouncer.setOptions({ wait: 1000 });\n * ```\n */\nexport function createDebouncer<\n TFn extends AnyFunction,\n TSelected = DebouncerState<TFn>,\n>(\n fn: TFn,\n initialOptions: DebouncerOptions<TFn>,\n selector?: (state: DebouncerState<TFn>) => TSelected,\n): SolidDebouncer<TFn, TSelected> {\n const asyncDebouncer = new Debouncer<TFn>(fn, initialOptions)\n\n const state = useStore(asyncDebouncer.store, selector)\n\n createEffect(() => {\n onCleanup(() => {\n asyncDebouncer.cancel()\n })\n })\n\n return {\n ...asyncDebouncer,\n state,\n } as SolidDebouncer<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"names":["Debouncer","useStore","createEffect","onCleanup"],"mappings":";;;;;AA0DO,SAAS,gBAId,IACA,gBACA,UACgC;AAChC,QAAM,iBAAiB,IAAIA,oBAAe,IAAI,cAAc;AAE5D,QAAM,QAAQC,WAAAA,SAAS,eAAe,OAAO,QAAQ;AAErDC,UAAAA,aAAa,MAAM;AACjBC,YAAAA,UAAU,MAAM;AACd,qBAAe,OAAA;AAAA,IAAO,CACvB;AAAA,EAAA,CACF;AAED,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,EAAA;AAEJ;;"}
@@ -1,12 +1,13 @@
1
- import { Debouncer, DebouncerOptions } from '@tanstack/pacer/debouncer';
1
+ import { Debouncer, DebouncerOptions, DebouncerState } from '@tanstack/pacer/debouncer';
2
2
  import { Accessor } from 'solid-js';
3
3
  import { AnyFunction } from '@tanstack/pacer/types';
4
- /**
5
- * An extension of the Debouncer class that adds Solid signals to access the internal state of the debouncer
6
- */
7
- export interface SolidDebouncer<TFn extends AnyFunction> extends Omit<Debouncer<TFn>, 'getExecutionCount' | 'getIsPending'> {
8
- executionCount: Accessor<number>;
9
- isPending: Accessor<boolean>;
4
+ export interface SolidDebouncer<TFn extends AnyFunction, TSelected = DebouncerState<TFn>> extends Omit<Debouncer<TFn>, 'store'> {
5
+ /**
6
+ * Reactive state that will be updated when the debouncer state changes
7
+ *
8
+ * Use this instead of `debouncer.store.state`
9
+ */
10
+ readonly state: Accessor<Readonly<TSelected>>;
10
11
  }
11
12
  /**
12
13
  * A Solid hook that creates and manages a Debouncer instance.
@@ -44,4 +45,4 @@ export interface SolidDebouncer<TFn extends AnyFunction> extends Omit<Debouncer<
44
45
  * debouncer.setOptions({ wait: 1000 });
45
46
  * ```
46
47
  */
47
- export declare function createDebouncer<TFn extends AnyFunction>(fn: TFn, initialOptions: DebouncerOptions<TFn>): SolidDebouncer<TFn>;
48
+ export declare function createDebouncer<TFn extends AnyFunction, TSelected = DebouncerState<TFn>>(fn: TFn, initialOptions: DebouncerOptions<TFn>, selector?: (state: DebouncerState<TFn>) => TSelected): SolidDebouncer<TFn, TSelected>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const pacer = require("@tanstack/pacer");
4
+ const createAsyncBatcher = require("./async-batcher/createAsyncBatcher.cjs");
4
5
  const createAsyncDebouncer = require("./async-debouncer/createAsyncDebouncer.cjs");
5
6
  const createAsyncQueuer = require("./async-queuer/createAsyncQueuer.cjs");
6
7
  const createAsyncRateLimiter = require("./async-rate-limiter/createAsyncRateLimiter.cjs");
@@ -16,6 +17,7 @@ const createRateLimitedValue = require("./rate-limiter/createRateLimitedValue.cj
16
17
  const createThrottledSignal = require("./throttler/createThrottledSignal.cjs");
17
18
  const createThrottledValue = require("./throttler/createThrottledValue.cjs");
18
19
  const createThrottler = require("./throttler/createThrottler.cjs");
20
+ exports.createAsyncBatcher = createAsyncBatcher.createAsyncBatcher;
19
21
  exports.createAsyncDebouncer = createAsyncDebouncer.createAsyncDebouncer;
20
22
  exports.createAsyncQueuer = createAsyncQueuer.createAsyncQueuer;
21
23
  exports.createAsyncRateLimiter = createAsyncRateLimiter.createAsyncRateLimiter;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -2,6 +2,7 @@ export * from '@tanstack/pacer';
2
2
  /**
3
3
  * Export every hook individually - DON'T export from barrel files
4
4
  */
5
+ export * from './async-batcher/createAsyncBatcher.cjs';
5
6
  export * from './async-debouncer/createAsyncDebouncer.cjs';
6
7
  export * from './async-queuer/createAsyncQueuer.cjs';
7
8
  export * from './async-rate-limiter/createAsyncRateLimiter.cjs';
@@ -1,67 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const queuer = require("@tanstack/pacer/queuer");
4
- const solidJs = require("solid-js");
5
- const utils = require("@tanstack/pacer/utils");
6
- function createQueuer(fn, initialOptions = {}) {
7
- const queuer$1 = utils.bindInstanceMethods(new queuer.Queuer(fn, initialOptions));
8
- const [allItems, setAllItems] = solidJs.createSignal(
9
- queuer$1.peekAllItems()
10
- );
11
- const [executionCount, setExecutionCount] = solidJs.createSignal(
12
- queuer$1.getExecutionCount()
13
- );
14
- const [rejectionCount, setRejectionCount] = solidJs.createSignal(
15
- queuer$1.getRejectionCount()
16
- );
17
- const [isEmpty, setIsEmpty] = solidJs.createSignal(queuer$1.getIsEmpty());
18
- const [isFull, setIsFull] = solidJs.createSignal(queuer$1.getIsFull());
19
- const [isIdle, setIsIdle] = solidJs.createSignal(queuer$1.getIsIdle());
20
- const [isRunning, setIsRunning] = solidJs.createSignal(queuer$1.getIsRunning());
21
- const [nextItem, setNextItem] = solidJs.createSignal(
22
- queuer$1.peekNextItem()
23
- );
24
- const [size, setSize] = solidJs.createSignal(queuer$1.getSize());
25
- function setOptions(newOptions) {
26
- queuer$1.setOptions({
27
- ...newOptions,
28
- onItemsChange: (queuer2) => {
29
- setAllItems(queuer2.peekAllItems());
30
- setExecutionCount(queuer2.getExecutionCount());
31
- setIsEmpty(queuer2.getIsEmpty());
32
- setIsFull(queuer2.getIsFull());
33
- setIsIdle(queuer2.getIsIdle());
34
- setNextItem(() => queuer2.peekNextItem());
35
- setSize(queuer2.getSize());
36
- const onItemsChange = newOptions.onItemsChange ?? initialOptions.onItemsChange;
37
- onItemsChange == null ? void 0 : onItemsChange(queuer2);
38
- },
39
- onIsRunningChange: (queuer2) => {
40
- setIsRunning(queuer2.getIsRunning());
41
- setIsIdle(queuer2.getIsIdle());
42
- const onIsRunningChange = newOptions.onIsRunningChange ?? initialOptions.onIsRunningChange;
43
- onIsRunningChange == null ? void 0 : onIsRunningChange(queuer2);
44
- },
45
- onReject: (item, queuer2) => {
46
- setRejectionCount(queuer2.getRejectionCount());
47
- const onReject = newOptions.onReject ?? initialOptions.onReject;
48
- onReject == null ? void 0 : onReject(item, queuer2);
49
- }
50
- });
51
- }
52
- setOptions(initialOptions);
4
+ const solidStore = require("@tanstack/solid-store");
5
+ function createQueuer(fn, initialOptions = {}, selector) {
6
+ const queuer$1 = new queuer.Queuer(fn, initialOptions);
7
+ const state = solidStore.useStore(queuer$1.store, selector);
53
8
  return {
54
9
  ...queuer$1,
55
- allItems,
56
- executionCount,
57
- isEmpty,
58
- isFull,
59
- isIdle,
60
- isRunning,
61
- nextItem,
62
- rejectionCount,
63
- size,
64
- setOptions
10
+ state
65
11
  };
66
12
  }
67
13
  exports.createQueuer = createQueuer;
@@ -1 +1 @@
1
- {"version":3,"file":"createQueuer.cjs","sources":["../../../src/queuer/createQueuer.ts"],"sourcesContent":["import { Queuer } from '@tanstack/pacer/queuer'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { QueuerOptions } from '@tanstack/pacer/queuer'\n\nexport interface SolidQueuer<TValue>\n extends Omit<\n Queuer<TValue>,\n | 'getExecutionCount'\n | 'getIsEmpty'\n | 'getIsFull'\n | 'getIsIdle'\n | 'getIsRunning'\n | 'getSize'\n | 'peekAllItems'\n | 'peekNextItem'\n > {\n /**\n * Signal version of `peekAllItems`\n */\n allItems: Accessor<Array<TValue>>\n /**\n * Signal version of `getExecutionCount`\n */\n executionCount: Accessor<number>\n /**\n * Signal version of `getIsEmpty`\n */\n isEmpty: Accessor<boolean>\n /**\n * Signal version of `getIsFull`\n */\n isFull: Accessor<boolean>\n /**\n * Signal version of `getIsIdle`\n */\n isIdle: Accessor<boolean>\n /**\n * Signal version of `getIsRunning`\n */\n isRunning: Accessor<boolean>\n /**\n * Signal version of `peekNextItem`\n */\n nextItem: Accessor<TValue | undefined>\n /**\n * Signal version of `getRejectionCount`\n */\n rejectionCount: Accessor<number>\n /**\n * Signal version of `getSize`\n */\n size: Accessor<number>\n}\n\n/**\n * Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Synchronous processing of items using the provided `fn` function\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Priority queueing via `getPriority` or item `priority` property\n * - Item expiration and removal of stale items\n * - Configurable wait time between processing items\n * - Pause/resume processing\n * - Callbacks for queue state changes, execution, rejection, and expiration\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The queue processes items synchronously in order, with optional delays between each item. When started, it will process one item per tick, with an optional wait time between ticks. You can pause and resume processing with `stop()` and `start()`.\n *\n * By default, the queue uses FIFO behavior, but you can configure LIFO or double-ended queueing by specifying the position when adding or removing items.\n *\n * Example usage:\n * ```tsx\n * // Example with Solid signals and scheduling\n * const [items, setItems] = createSignal([]);\n *\n * const queue = createQueuer(\n * (item) => {\n * // process item synchronously\n * console.log('Processing', item);\n * },\n * {\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * 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 queue state via signals\n * console.log('Items:', queue.allItems());\n * console.log('Size:', queue.size());\n * console.log('Is empty:', queue.isEmpty());\n * console.log('Is running:', queue.isRunning());\n * console.log('Next item:', queue.nextItem());\n * ```\n */\nexport function createQueuer<TValue>(\n fn: (item: TValue) => void,\n initialOptions: QueuerOptions<TValue> = {},\n): SolidQueuer<TValue> {\n const queuer = bindInstanceMethods(new Queuer<TValue>(fn, initialOptions))\n\n const [allItems, setAllItems] = createSignal<Array<TValue>>(\n queuer.peekAllItems(),\n )\n const [executionCount, setExecutionCount] = createSignal(\n queuer.getExecutionCount(),\n )\n const [rejectionCount, setRejectionCount] = createSignal(\n queuer.getRejectionCount(),\n )\n const [isEmpty, setIsEmpty] = createSignal(queuer.getIsEmpty())\n const [isFull, setIsFull] = createSignal(queuer.getIsFull())\n const [isIdle, setIsIdle] = createSignal(queuer.getIsIdle())\n const [isRunning, setIsRunning] = createSignal(queuer.getIsRunning())\n const [nextItem, setNextItem] = createSignal<TValue | undefined>(\n queuer.peekNextItem(),\n )\n const [size, setSize] = createSignal(queuer.getSize())\n\n function setOptions(newOptions: Partial<QueuerOptions<TValue>>) {\n queuer.setOptions({\n ...newOptions,\n onItemsChange: (queuer) => {\n setAllItems(queuer.peekAllItems())\n setExecutionCount(queuer.getExecutionCount())\n setIsEmpty(queuer.getIsEmpty())\n setIsFull(queuer.getIsFull())\n setIsIdle(queuer.getIsIdle())\n setNextItem(() => queuer.peekNextItem())\n setSize(queuer.getSize())\n\n const onItemsChange =\n newOptions.onItemsChange ?? initialOptions.onItemsChange\n onItemsChange?.(queuer)\n },\n onIsRunningChange: (queuer) => {\n setIsRunning(queuer.getIsRunning())\n setIsIdle(queuer.getIsIdle())\n\n const onIsRunningChange =\n newOptions.onIsRunningChange ?? initialOptions.onIsRunningChange\n onIsRunningChange?.(queuer)\n },\n onReject: (item, queuer) => {\n setRejectionCount(queuer.getRejectionCount())\n\n const onReject = newOptions.onReject ?? initialOptions.onReject\n onReject?.(item, queuer)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...queuer,\n allItems,\n executionCount,\n isEmpty,\n isFull,\n isIdle,\n isRunning,\n nextItem,\n rejectionCount,\n size,\n setOptions,\n } as SolidQueuer<TValue>\n}\n"],"names":["queuer","bindInstanceMethods","Queuer","createSignal"],"mappings":";;;;;AA2GO,SAAS,aACd,IACA,iBAAwC,IACnB;AACrB,QAAMA,WAASC,MAAAA,oBAAoB,IAAIC,OAAe,OAAA,IAAI,cAAc,CAAC;AAEnE,QAAA,CAAC,UAAU,WAAW,IAAIC,QAAA;AAAA,IAC9BH,SAAO,aAAa;AAAA,EACtB;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAIG,QAAA;AAAA,IAC1CH,SAAO,kBAAkB;AAAA,EAC3B;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAIG,QAAA;AAAA,IAC1CH,SAAO,kBAAkB;AAAA,EAC3B;AACA,QAAM,CAAC,SAAS,UAAU,IAAIG,QAAAA,aAAaH,SAAO,YAAY;AAC9D,QAAM,CAAC,QAAQ,SAAS,IAAIG,QAAAA,aAAaH,SAAO,WAAW;AAC3D,QAAM,CAAC,QAAQ,SAAS,IAAIG,QAAAA,aAAaH,SAAO,WAAW;AAC3D,QAAM,CAAC,WAAW,YAAY,IAAIG,QAAAA,aAAaH,SAAO,cAAc;AAC9D,QAAA,CAAC,UAAU,WAAW,IAAIG,QAAA;AAAA,IAC9BH,SAAO,aAAa;AAAA,EACtB;AACA,QAAM,CAAC,MAAM,OAAO,IAAIG,QAAAA,aAAaH,SAAO,SAAS;AAErD,WAAS,WAAW,YAA4C;AAC9DA,aAAO,WAAW;AAAA,MAChB,GAAG;AAAA,MACH,eAAe,CAACA,YAAW;AACbA,oBAAAA,QAAO,cAAc;AACfA,0BAAAA,QAAO,mBAAmB;AACjCA,mBAAAA,QAAO,YAAY;AACpBA,kBAAAA,QAAO,WAAW;AAClBA,kBAAAA,QAAO,WAAW;AAChB,oBAAA,MAAMA,QAAO,cAAc;AAC/BA,gBAAAA,QAAO,SAAS;AAElB,cAAA,gBACJ,WAAW,iBAAiB,eAAe;AAC7C,uDAAgBA;AAAAA,MAClB;AAAA,MACA,mBAAmB,CAACA,YAAW;AAChBA,qBAAAA,QAAO,cAAc;AACxBA,kBAAAA,QAAO,WAAW;AAEtB,cAAA,oBACJ,WAAW,qBAAqB,eAAe;AACjD,+DAAoBA;AAAAA,MACtB;AAAA,MACA,UAAU,CAAC,MAAMA,YAAW;AACRA,0BAAAA,QAAO,mBAAmB;AAEtC,cAAA,WAAW,WAAW,YAAY,eAAe;AACvD,6CAAW,MAAMA;AAAAA,MAAM;AAAA,IACzB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAGA;AAAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
1
+ {"version":3,"file":"createQueuer.cjs","sources":["../../../src/queuer/createQueuer.ts"],"sourcesContent":["import { Queuer } from '@tanstack/pacer/queuer'\nimport { useStore } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface SolidQueuer<TValue, TSelected = QueuerState<TValue>>\n extends Omit<Queuer<TValue>, 'store'> {\n /**\n * Reactive state that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n}\n\n/**\n * Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Synchronous processing of items using the provided `fn` function\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Priority queueing via `getPriority` or item `priority` property\n * - Item expiration and removal of stale items\n * - Configurable wait time between processing items\n * - Pause/resume processing\n * - Callbacks for queue state changes, execution, rejection, and expiration\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The queue processes items synchronously in order, with optional delays between each item. When started, it will process one item per tick, with an optional wait time between ticks. You can pause and resume processing with `stop()` and `start()`.\n *\n * By default, the queue uses FIFO behavior, but you can configure LIFO or double-ended queueing by specifying the position when adding or removing items.\n *\n * Example usage:\n * ```tsx\n * // Example with Solid signals and scheduling\n * const [items, setItems] = createSignal([]);\n *\n * const queue = createQueuer(\n * (item) => {\n * // process item synchronously\n * console.log('Processing', item);\n * },\n * {\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * 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 queue state via signals\n * console.log('Items:', queue.allItems());\n * console.log('Size:', queue.size());\n * console.log('Is empty:', queue.isEmpty());\n * console.log('Is running:', queue.isRunning());\n * console.log('Next item:', queue.nextItem());\n * ```\n */\nexport function createQueuer<TValue, TSelected = QueuerState<TValue>>(\n fn: (item: TValue) => void,\n initialOptions: QueuerOptions<TValue> = {},\n selector?: (state: QueuerState<TValue>) => TSelected,\n): SolidQueuer<TValue, TSelected> {\n const queuer = new Queuer(fn, initialOptions)\n\n const state = useStore(queuer.store, selector)\n\n return {\n ...queuer,\n state,\n } as unknown as SolidQueuer<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"names":["queuer","Queuer","useStore"],"mappings":";;;;AAkEO,SAAS,aACd,IACA,iBAAwC,CAAA,GACxC,UACgC;AAChC,QAAMA,WAAS,IAAIC,cAAO,IAAI,cAAc;AAE5C,QAAM,QAAQC,WAAAA,SAASF,SAAO,OAAO,QAAQ;AAE7C,SAAO;AAAA,IACL,GAAGA;AAAAA,IACH;AAAA,EAAA;AAEJ;;"}
@@ -1,42 +1,12 @@
1
- import { Queuer, QueuerOptions } from '@tanstack/pacer/queuer';
1
+ import { Queuer, QueuerOptions, QueuerState } from '@tanstack/pacer/queuer';
2
2
  import { Accessor } from 'solid-js';
3
- export interface SolidQueuer<TValue> extends Omit<Queuer<TValue>, 'getExecutionCount' | 'getIsEmpty' | 'getIsFull' | 'getIsIdle' | 'getIsRunning' | 'getSize' | 'peekAllItems' | 'peekNextItem'> {
3
+ export interface SolidQueuer<TValue, TSelected = QueuerState<TValue>> extends Omit<Queuer<TValue>, 'store'> {
4
4
  /**
5
- * Signal version of `peekAllItems`
5
+ * Reactive state that will be updated when the queuer state changes
6
+ *
7
+ * Use this instead of `queuer.store.state`
6
8
  */
7
- allItems: Accessor<Array<TValue>>;
8
- /**
9
- * Signal version of `getExecutionCount`
10
- */
11
- executionCount: Accessor<number>;
12
- /**
13
- * Signal version of `getIsEmpty`
14
- */
15
- isEmpty: Accessor<boolean>;
16
- /**
17
- * Signal version of `getIsFull`
18
- */
19
- isFull: Accessor<boolean>;
20
- /**
21
- * Signal version of `getIsIdle`
22
- */
23
- isIdle: Accessor<boolean>;
24
- /**
25
- * Signal version of `getIsRunning`
26
- */
27
- isRunning: Accessor<boolean>;
28
- /**
29
- * Signal version of `peekNextItem`
30
- */
31
- nextItem: Accessor<TValue | undefined>;
32
- /**
33
- * Signal version of `getRejectionCount`
34
- */
35
- rejectionCount: Accessor<number>;
36
- /**
37
- * Signal version of `getSize`
38
- */
39
- size: Accessor<number>;
9
+ readonly state: Accessor<Readonly<TSelected>>;
40
10
  }
41
11
  /**
42
12
  * Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.
@@ -89,4 +59,4 @@ export interface SolidQueuer<TValue> extends Omit<Queuer<TValue>, 'getExecutionC
89
59
  * console.log('Next item:', queue.nextItem());
90
60
  * ```
91
61
  */
92
- export declare function createQueuer<TValue>(fn: (item: TValue) => void, initialOptions?: QueuerOptions<TValue>): SolidQueuer<TValue>;
62
+ export declare function createQueuer<TValue, TSelected = QueuerState<TValue>>(fn: (item: TValue) => void, initialOptions?: QueuerOptions<TValue>, selector?: (state: QueuerState<TValue>) => TSelected): SolidQueuer<TValue, TSelected>;
@@ -2,12 +2,16 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const solidJs = require("solid-js");
4
4
  const createRateLimiter = require("./createRateLimiter.cjs");
5
- function createRateLimitedSignal(value, initialOptions) {
5
+ function createRateLimitedSignal(value, initialOptions, selector) {
6
6
  const [rateLimitedValue, setRateLimitedValue] = solidJs.createSignal(value);
7
- const rateLimiter = createRateLimiter.createRateLimiter(setRateLimitedValue, initialOptions);
7
+ const rateLimiter = createRateLimiter.createRateLimiter(
8
+ setRateLimitedValue,
9
+ initialOptions,
10
+ selector
11
+ );
8
12
  return [
9
13
  rateLimitedValue,
10
- rateLimiter.maybeExecute.bind(rateLimiter),
14
+ rateLimiter.maybeExecute,
11
15
  rateLimiter
12
16
  ];
13
17
  }