@tanstack/solid-pacer 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs +22 -7
  2. package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs.map +1 -1
  3. package/dist/cjs/async-debouncer/createAsyncDebouncer.d.cts +6 -3
  4. package/dist/cjs/async-queuer/createAsyncQueuer.cjs.map +1 -1
  5. package/dist/cjs/async-queuer/createAsyncQueuer.d.cts +5 -1
  6. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs +20 -9
  7. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs.map +1 -1
  8. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.d.cts +19 -6
  9. package/dist/cjs/async-throttler/createAsyncThrottler.cjs +32 -10
  10. package/dist/cjs/async-throttler/createAsyncThrottler.cjs.map +1 -1
  11. package/dist/cjs/async-throttler/createAsyncThrottler.d.cts +7 -3
  12. package/dist/cjs/debouncer/createDebouncedSignal.cjs.map +1 -1
  13. package/dist/cjs/debouncer/createDebouncedSignal.d.cts +1 -5
  14. package/dist/cjs/debouncer/createDebouncedValue.cjs +0 -3
  15. package/dist/cjs/debouncer/createDebouncedValue.cjs.map +1 -1
  16. package/dist/cjs/debouncer/createDebouncedValue.d.cts +5 -11
  17. package/dist/cjs/debouncer/createDebouncer.cjs +7 -2
  18. package/dist/cjs/debouncer/createDebouncer.cjs.map +1 -1
  19. package/dist/cjs/debouncer/createDebouncer.d.cts +2 -2
  20. package/dist/cjs/queuer/createQueuer.cjs +2 -2
  21. package/dist/cjs/queuer/createQueuer.cjs.map +1 -1
  22. package/dist/cjs/queuer/createQueuer.d.cts +4 -0
  23. package/dist/cjs/rate-limiter/createRateLimitedSignal.cjs.map +1 -1
  24. package/dist/cjs/rate-limiter/createRateLimitedSignal.d.cts +12 -8
  25. package/dist/cjs/rate-limiter/createRateLimitedValue.cjs.map +1 -1
  26. package/dist/cjs/rate-limiter/createRateLimitedValue.d.cts +18 -22
  27. package/dist/cjs/rate-limiter/createRateLimiter.cjs +4 -2
  28. package/dist/cjs/rate-limiter/createRateLimiter.cjs.map +1 -1
  29. package/dist/cjs/rate-limiter/createRateLimiter.d.cts +10 -3
  30. package/dist/cjs/throttler/createThrottledSignal.cjs.map +1 -1
  31. package/dist/cjs/throttler/createThrottledSignal.d.cts +1 -5
  32. package/dist/cjs/throttler/createThrottledValue.cjs +0 -3
  33. package/dist/cjs/throttler/createThrottledValue.cjs.map +1 -1
  34. package/dist/cjs/throttler/createThrottledValue.d.cts +10 -14
  35. package/dist/cjs/throttler/createThrottler.cjs +7 -2
  36. package/dist/cjs/throttler/createThrottler.cjs.map +1 -1
  37. package/dist/cjs/throttler/createThrottler.d.cts +2 -2
  38. package/dist/esm/async-debouncer/createAsyncDebouncer.d.ts +6 -3
  39. package/dist/esm/async-debouncer/createAsyncDebouncer.js +22 -7
  40. package/dist/esm/async-debouncer/createAsyncDebouncer.js.map +1 -1
  41. package/dist/esm/async-queuer/createAsyncQueuer.d.ts +5 -1
  42. package/dist/esm/async-queuer/createAsyncQueuer.js.map +1 -1
  43. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.d.ts +19 -6
  44. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js +20 -9
  45. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js.map +1 -1
  46. package/dist/esm/async-throttler/createAsyncThrottler.d.ts +7 -3
  47. package/dist/esm/async-throttler/createAsyncThrottler.js +32 -10
  48. package/dist/esm/async-throttler/createAsyncThrottler.js.map +1 -1
  49. package/dist/esm/debouncer/createDebouncedSignal.d.ts +1 -5
  50. package/dist/esm/debouncer/createDebouncedSignal.js.map +1 -1
  51. package/dist/esm/debouncer/createDebouncedValue.d.ts +5 -11
  52. package/dist/esm/debouncer/createDebouncedValue.js +1 -4
  53. package/dist/esm/debouncer/createDebouncedValue.js.map +1 -1
  54. package/dist/esm/debouncer/createDebouncer.d.ts +2 -2
  55. package/dist/esm/debouncer/createDebouncer.js +8 -3
  56. package/dist/esm/debouncer/createDebouncer.js.map +1 -1
  57. package/dist/esm/queuer/createQueuer.d.ts +4 -0
  58. package/dist/esm/queuer/createQueuer.js +2 -2
  59. package/dist/esm/queuer/createQueuer.js.map +1 -1
  60. package/dist/esm/rate-limiter/createRateLimitedSignal.d.ts +12 -8
  61. package/dist/esm/rate-limiter/createRateLimitedSignal.js.map +1 -1
  62. package/dist/esm/rate-limiter/createRateLimitedValue.d.ts +18 -22
  63. package/dist/esm/rate-limiter/createRateLimitedValue.js.map +1 -1
  64. package/dist/esm/rate-limiter/createRateLimiter.d.ts +10 -3
  65. package/dist/esm/rate-limiter/createRateLimiter.js +4 -2
  66. package/dist/esm/rate-limiter/createRateLimiter.js.map +1 -1
  67. package/dist/esm/throttler/createThrottledSignal.d.ts +1 -5
  68. package/dist/esm/throttler/createThrottledSignal.js.map +1 -1
  69. package/dist/esm/throttler/createThrottledValue.d.ts +10 -14
  70. package/dist/esm/throttler/createThrottledValue.js +1 -4
  71. package/dist/esm/throttler/createThrottledValue.js.map +1 -1
  72. package/dist/esm/throttler/createThrottler.d.ts +2 -2
  73. package/dist/esm/throttler/createThrottler.js +8 -3
  74. package/dist/esm/throttler/createThrottler.js.map +1 -1
  75. package/package.json +3 -3
  76. package/src/async-debouncer/createAsyncDebouncer.ts +40 -24
  77. package/src/async-queuer/createAsyncQueuer.ts +6 -2
  78. package/src/async-rate-limiter/createAsyncRateLimiter.ts +48 -29
  79. package/src/async-throttler/createAsyncThrottler.ts +49 -24
  80. package/src/debouncer/createDebouncedSignal.ts +2 -6
  81. package/src/debouncer/createDebouncedValue.ts +7 -16
  82. package/src/debouncer/createDebouncer.ts +16 -15
  83. package/src/queuer/createQueuer.ts +7 -3
  84. package/src/rate-limiter/createRateLimitedSignal.ts +13 -9
  85. package/src/rate-limiter/createRateLimitedValue.ts +19 -23
  86. package/src/rate-limiter/createRateLimiter.ts +22 -16
  87. package/src/throttler/createThrottledSignal.ts +2 -6
  88. package/src/throttler/createThrottledValue.ts +12 -19
  89. package/src/throttler/createThrottler.ts +17 -16
@@ -1 +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 | 'getAllItems'\n | 'getExecutionCount'\n | 'getIsEmpty'\n | 'getIsFull'\n | 'getIsIdle'\n | 'getIsRunning'\n | 'getPeek'\n | 'getSize'\n > {\n /**\n * Signal version of `getAllItems`\n */\n allItems: Accessor<Array<TValue>>\n /**\n * Signal version of `getExecutionCount`\n */\n executionCount: Accessor<number>\n /**\n * Signal version of `getIsEmpty`\n */\n isEmpty: Accessor<boolean>\n /**\n * Signal version of `getIsFull`\n */\n isFull: Accessor<boolean>\n /**\n * Signal version of `getIsIdle`\n */\n isIdle: Accessor<boolean>\n /**\n * Signal version of `getIsRunning`\n */\n isRunning: Accessor<boolean>\n /**\n * Signal version of `getPeek`\n */\n peek: Accessor<TValue | undefined>\n /**\n * Signal version of `getSize`\n */\n size: Accessor<number>\n}\n\n/**\n * A Solid hook that creates and manages a Queuer instance.\n *\n * This is a lower-level hook that provides direct access to the Queuer's functionality without\n * any built-in state management. This allows you to integrate it with any state management solution\n * you prefer (createSignal, Redux, Zustand, etc.) by utilizing the onItemsChange callback.\n *\n * For a hook with built-in state management, see createQueuerSignal.\n *\n * The Queuer extends the base Queue to add processing capabilities. Items are processed\n * synchronously in order, with optional delays between processing each item. The queuer includes\n * an internal tick mechanism that can be started and stopped, making it useful as a scheduler.\n * When started, it will process one item per tick, with an optional wait time between ticks.\n *\n * By default uses FIFO (First In First Out) behavior, but can be configured for LIFO\n * (Last In First Out) by specifying 'front' position when adding items.\n *\n * @example\n * ```tsx\n * // Example with custom state management and scheduling\n * const [items, setItems] = createSignal([]);\n *\n * const queue = createQueuer({\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * onItemsChange: (queue) => setItems(queue.getAllItems()),\n * getPriority: (item) => item.priority // Process higher priority items first\n * });\n *\n * // Add items to process - they'll be handled automatically\n * queue.addItem('task1');\n * queue.addItem('task2');\n *\n * // Control the scheduler\n * queue.stop(); // Pause processing\n * queue.start(); // Resume processing\n *\n * // Access queue state via signals\n * console.log('Items:', queue.allItems());\n * console.log('Size:', queue.size());\n * console.log('Is empty:', queue.isEmpty());\n * console.log('Is running:', queue.isRunning());\n * console.log('Next item:', queue.peek());\n * ```\n */\nexport function createQueuer<TValue>(\n initialOptions: QueuerOptions<TValue> = {},\n): SolidQueuer<TValue> {\n const queuer = new Queuer<TValue>(initialOptions)\n\n const [allItems, setAllItems] = createSignal<Array<TValue>>(\n queuer.getAllItems(),\n )\n const [executionCount, setExecutionCount] = createSignal(\n queuer.getExecutionCount(),\n )\n const [rejectionCount, setRejectionCount] = createSignal(\n queuer.getRejectionCount(),\n )\n const [isEmpty, setIsEmpty] = createSignal(queuer.getIsEmpty())\n const [isFull, setIsFull] = createSignal(queuer.getIsFull())\n const [isIdle, setIsIdle] = createSignal(queuer.getIsIdle())\n const [isRunning, setIsRunning] = createSignal(queuer.getIsRunning())\n const [peek, setPeek] = createSignal<TValue | undefined>(queuer.getPeek())\n const [size, setSize] = createSignal(queuer.getSize())\n\n function setOptions(newOptions: Partial<QueuerOptions<TValue>>) {\n queuer.setOptions({\n ...newOptions,\n onItemsChange: (queuer) => {\n setAllItems(queuer.getAllItems())\n setExecutionCount(queuer.getExecutionCount())\n setIsEmpty(queuer.getIsEmpty())\n setIsFull(queuer.getIsFull())\n setIsIdle(queuer.getIsIdle())\n setPeek(() => queuer.getPeek())\n setSize(queuer.getSize())\n\n const onItemsChange =\n newOptions.onItemsChange ?? initialOptions.onItemsChange\n onItemsChange?.(queuer)\n },\n onIsRunningChange: (queuer) => {\n setIsRunning(queuer.getIsRunning())\n setIsIdle(queuer.getIsIdle())\n\n const onIsRunningChange =\n newOptions.onIsRunningChange ?? initialOptions.onIsRunningChange\n onIsRunningChange?.(queuer)\n },\n onReject: (item, queuer) => {\n setRejectionCount(queuer.getRejectionCount())\n\n const onReject = newOptions.onReject ?? initialOptions.onReject\n onReject?.(item, queuer)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...bindInstanceMethods(queuer),\n allItems,\n executionCount,\n isEmpty,\n isFull,\n isIdle,\n isRunning,\n peek,\n rejectionCount,\n size,\n setOptions,\n }\n}\n"],"names":["queuer","Queuer","createSignal","bindInstanceMethods"],"mappings":";;;;;AAiGgB,SAAA,aACd,iBAAwC,IACnB;AACf,QAAAA,WAAS,IAAIC,OAAA,OAAe,cAAc;AAE1C,QAAA,CAAC,UAAU,WAAW,IAAIC,QAAA;AAAA,IAC9BF,SAAO,YAAY;AAAA,EACrB;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAIE,QAAA;AAAA,IAC1CF,SAAO,kBAAkB;AAAA,EAC3B;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAIE,QAAA;AAAA,IAC1CF,SAAO,kBAAkB;AAAA,EAC3B;AACA,QAAM,CAAC,SAAS,UAAU,IAAIE,QAAAA,aAAaF,SAAO,YAAY;AAC9D,QAAM,CAAC,QAAQ,SAAS,IAAIE,QAAAA,aAAaF,SAAO,WAAW;AAC3D,QAAM,CAAC,QAAQ,SAAS,IAAIE,QAAAA,aAAaF,SAAO,WAAW;AAC3D,QAAM,CAAC,WAAW,YAAY,IAAIE,QAAAA,aAAaF,SAAO,cAAc;AACpE,QAAM,CAAC,MAAM,OAAO,IAAIE,QAAAA,aAAiCF,SAAO,SAAS;AACzE,QAAM,CAAC,MAAM,OAAO,IAAIE,QAAAA,aAAaF,SAAO,SAAS;AAErD,WAAS,WAAW,YAA4C;AAC9DA,aAAO,WAAW;AAAA,MAChB,GAAG;AAAA,MACH,eAAe,CAACA,YAAW;AACbA,oBAAAA,QAAO,aAAa;AACdA,0BAAAA,QAAO,mBAAmB;AACjCA,mBAAAA,QAAO,YAAY;AACpBA,kBAAAA,QAAO,WAAW;AAClBA,kBAAAA,QAAO,WAAW;AACpB,gBAAA,MAAMA,QAAO,SAAS;AACtBA,gBAAAA,QAAO,SAAS;AAElB,cAAA,gBACJ,WAAW,iBAAiB,eAAe;AAC7C,uDAAgBA;AAAAA,MAClB;AAAA,MACA,mBAAmB,CAACA,YAAW;AAChBA,qBAAAA,QAAO,cAAc;AACxBA,kBAAAA,QAAO,WAAW;AAEtB,cAAA,oBACJ,WAAW,qBAAqB,eAAe;AACjD,+DAAoBA;AAAAA,MACtB;AAAA,MACA,UAAU,CAAC,MAAMA,YAAW;AACRA,0BAAAA,QAAO,mBAAmB;AAEtC,cAAA,WAAW,WAAW,YAAY,eAAe;AACvD,6CAAW,MAAMA;AAAAA,MAAM;AAAA,IACzB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAGG,MAAAA,oBAAoBH,QAAM;AAAA,IAC7B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
1
+ {"version":3,"file":"createQueuer.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 | 'getAllItems'\n | 'getExecutionCount'\n | 'getIsEmpty'\n | 'getIsFull'\n | 'getIsIdle'\n | 'getIsRunning'\n | 'getPeek'\n | 'getSize'\n > {\n /**\n * Signal version of `getAllItems`\n */\n allItems: Accessor<Array<TValue>>\n /**\n * Signal version of `getExecutionCount`\n */\n executionCount: Accessor<number>\n /**\n * Signal version of `getIsEmpty`\n */\n isEmpty: Accessor<boolean>\n /**\n * Signal version of `getIsFull`\n */\n isFull: Accessor<boolean>\n /**\n * Signal version of `getIsIdle`\n */\n isIdle: Accessor<boolean>\n /**\n * Signal version of `getIsRunning`\n */\n isRunning: Accessor<boolean>\n /**\n * Signal version of `getPeek`\n */\n peek: Accessor<TValue | undefined>\n /**\n * Signal version of `getRejectionCount`\n */\n rejectionCount: Accessor<number>\n /**\n * Signal version of `getSize`\n */\n size: Accessor<number>\n}\n\n/**\n * A Solid hook that creates and manages a Queuer instance.\n *\n * This is a lower-level hook that provides direct access to the Queuer's functionality without\n * any built-in state management. This allows you to integrate it with any state management solution\n * you prefer (createSignal, Redux, Zustand, etc.) by utilizing the onItemsChange callback.\n *\n * For a hook with built-in state management, see createQueuerSignal.\n *\n * The Queuer extends the base Queue to add processing capabilities. Items are processed\n * synchronously in order, with optional delays between processing each item. The queuer includes\n * an internal tick mechanism that can be started and stopped, making it useful as a scheduler.\n * When started, it will process one item per tick, with an optional wait time between ticks.\n *\n * By default uses FIFO (First In First Out) behavior, but can be configured for LIFO\n * (Last In First Out) by specifying 'front' position when adding items.\n *\n * @example\n * ```tsx\n * // Example with custom state management and scheduling\n * const [items, setItems] = createSignal([]);\n *\n * const queue = createQueuer({\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * onItemsChange: (queue) => setItems(queue.getAllItems()),\n * getPriority: (item) => item.priority // Process higher priority items first\n * });\n *\n * // Add items to process - they'll be handled automatically\n * queue.addItem('task1');\n * queue.addItem('task2');\n *\n * // Control the scheduler\n * queue.stop(); // Pause processing\n * queue.start(); // Resume processing\n *\n * // Access queue state via signals\n * console.log('Items:', queue.allItems());\n * console.log('Size:', queue.size());\n * console.log('Is empty:', queue.isEmpty());\n * console.log('Is running:', queue.isRunning());\n * console.log('Next item:', queue.peek());\n * ```\n */\nexport function createQueuer<TValue>(\n initialOptions: QueuerOptions<TValue> = {},\n): SolidQueuer<TValue> {\n const queuer = bindInstanceMethods(new Queuer<TValue>(initialOptions))\n\n const [allItems, setAllItems] = createSignal<Array<TValue>>(\n queuer.getAllItems(),\n )\n const [executionCount, setExecutionCount] = createSignal(\n queuer.getExecutionCount(),\n )\n const [rejectionCount, setRejectionCount] = createSignal(\n queuer.getRejectionCount(),\n )\n const [isEmpty, setIsEmpty] = createSignal(queuer.getIsEmpty())\n const [isFull, setIsFull] = createSignal(queuer.getIsFull())\n const [isIdle, setIsIdle] = createSignal(queuer.getIsIdle())\n const [isRunning, setIsRunning] = createSignal(queuer.getIsRunning())\n const [peek, setPeek] = createSignal<TValue | undefined>(queuer.getPeek())\n const [size, setSize] = createSignal(queuer.getSize())\n\n function setOptions(newOptions: Partial<QueuerOptions<TValue>>) {\n queuer.setOptions({\n ...newOptions,\n onItemsChange: (queuer) => {\n setAllItems(queuer.getAllItems())\n setExecutionCount(queuer.getExecutionCount())\n setIsEmpty(queuer.getIsEmpty())\n setIsFull(queuer.getIsFull())\n setIsIdle(queuer.getIsIdle())\n setPeek(() => queuer.getPeek())\n setSize(queuer.getSize())\n\n const onItemsChange =\n newOptions.onItemsChange ?? initialOptions.onItemsChange\n onItemsChange?.(queuer)\n },\n onIsRunningChange: (queuer) => {\n setIsRunning(queuer.getIsRunning())\n setIsIdle(queuer.getIsIdle())\n\n const onIsRunningChange =\n newOptions.onIsRunningChange ?? initialOptions.onIsRunningChange\n onIsRunningChange?.(queuer)\n },\n onReject: (item, queuer) => {\n setRejectionCount(queuer.getRejectionCount())\n\n const onReject = newOptions.onReject ?? initialOptions.onReject\n onReject?.(item, queuer)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...queuer,\n allItems,\n executionCount,\n isEmpty,\n isFull,\n isIdle,\n isRunning,\n peek,\n rejectionCount,\n size,\n setOptions,\n } as SolidQueuer<TValue>\n}\n"],"names":["queuer","bindInstanceMethods","Queuer","createSignal"],"mappings":";;;;;AAqGgB,SAAA,aACd,iBAAwC,IACnB;AACrB,QAAMA,WAASC,MAAA,oBAAoB,IAAIC,OAAA,OAAe,cAAc,CAAC;AAE/D,QAAA,CAAC,UAAU,WAAW,IAAIC,QAAA;AAAA,IAC9BH,SAAO,YAAY;AAAA,EACrB;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;AACpE,QAAM,CAAC,MAAM,OAAO,IAAIG,QAAAA,aAAiCH,SAAO,SAAS;AACzE,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,aAAa;AACdA,0BAAAA,QAAO,mBAAmB;AACjCA,mBAAAA,QAAO,YAAY;AACpBA,kBAAAA,QAAO,WAAW;AAClBA,kBAAAA,QAAO,WAAW;AACpB,gBAAA,MAAMA,QAAO,SAAS;AACtBA,gBAAAA,QAAO,SAAS;AAElB,cAAA,gBACJ,WAAW,iBAAiB,eAAe;AAC7C,uDAAgBA;AAAAA,MAClB;AAAA,MACA,mBAAmB,CAACA,YAAW;AAChBA,qBAAAA,QAAO,cAAc;AACxBA,kBAAAA,QAAO,WAAW;AAEtB,cAAA,oBACJ,WAAW,qBAAqB,eAAe;AACjD,+DAAoBA;AAAAA,MACtB;AAAA,MACA,UAAU,CAAC,MAAMA,YAAW;AACRA,0BAAAA,QAAO,mBAAmB;AAEtC,cAAA,WAAW,WAAW,YAAY,eAAe;AACvD,6CAAW,MAAMA;AAAAA,MAAM;AAAA,IACzB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAGA;AAAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
@@ -29,6 +29,10 @@ export interface SolidQueuer<TValue> extends Omit<Queuer<TValue>, 'getAllItems'
29
29
  * Signal version of `getPeek`
30
30
  */
31
31
  peek: Accessor<TValue | undefined>;
32
+ /**
33
+ * Signal version of `getRejectionCount`
34
+ */
35
+ rejectionCount: Accessor<number>;
32
36
  /**
33
37
  * Signal version of `getSize`
34
38
  */
@@ -1 +1 @@
1
- {"version":3,"file":"createRateLimitedSignal.cjs","sources":["../../../src/rate-limiter/createRateLimitedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createRateLimiter } from './createRateLimiter'\nimport type { SolidRateLimiter } from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.\n * This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * For smoother update patterns, consider:\n * - createThrottledSignal: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedSignal: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns a tuple containing:\n * - The rate-limited state value accessor\n * - A rate-limited setter function that respects the configured limits\n * - The rateLimiter instance for additional control\n *\n * For more direct control over rate limiting without state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * @example\n * ```tsx\n * // Basic rate limiting - update state at most 5 times per minute\n * const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {\n * limit: 5,\n * window: 60000\n * });\n *\n * // With rejection callback\n * const [value, setValue] = createRateLimitedSignal(0, {\n * limit: 3,\n * window: 5000,\n * onReject: (rateLimiter) => {\n * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access rateLimiter state via signals\n * const handleSubmit = () => {\n * const remaining = rateLimiter.remainingInWindow();\n * if (remaining > 0) {\n * setValue(newValue);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n * ```\n */\nexport function createRateLimitedSignal<TValue>(\n value: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>, [Accessor<TValue>]>,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidRateLimiter<Setter<TValue>, [Accessor<TValue>]>,\n] {\n const [rateLimitedValue, setRateLimitedValue] = createSignal<TValue>(value)\n\n const rateLimiter = createRateLimiter(setRateLimitedValue, initialOptions)\n\n return [\n rateLimitedValue,\n rateLimiter.maybeExecute.bind(rateLimiter) as Setter<TValue>,\n rateLimiter,\n ]\n}\n"],"names":["createSignal","createRateLimiter"],"mappings":";;;;AAwDgB,SAAA,wBACd,OACA,gBAKA;AACA,QAAM,CAAC,kBAAkB,mBAAmB,IAAIA,QAAAA,aAAqB,KAAK;AAEpE,QAAA,cAAcC,kBAAAA,kBAAkB,qBAAqB,cAAc;AAElE,SAAA;AAAA,IACL;AAAA,IACA,YAAY,aAAa,KAAK,WAAW;AAAA,IACzC;AAAA,EACF;AACF;;"}
1
+ {"version":3,"file":"createRateLimitedSignal.cjs","sources":["../../../src/rate-limiter/createRateLimitedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createRateLimiter } from './createRateLimiter'\nimport type { SolidRateLimiter } from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.\n * This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\n *\n * For smoother update patterns, consider:\n * - createThrottledSignal: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedSignal: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns a tuple containing:\n * - The rate-limited state value accessor\n * - A rate-limited setter function that respects the configured limits\n * - The rateLimiter instance for additional control\n *\n * For more direct control over rate limiting without state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * @example\n * ```tsx\n * // Basic rate limiting - update state at most 5 times per minute with a sliding window\n * const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // With rejection callback and fixed window\n * const [value, setValue] = createRateLimitedSignal(0, {\n * limit: 3,\n * window: 5000,\n * windowType: 'fixed',\n * onReject: (rateLimiter) => {\n * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access rateLimiter state via signals\n * const handleSubmit = () => {\n * const remaining = rateLimiter.remainingInWindow();\n * if (remaining > 0) {\n * setValue(newValue);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n * ```\n */\nexport function createRateLimitedSignal<TValue>(\n value: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n): [Accessor<TValue>, Setter<TValue>, SolidRateLimiter<Setter<TValue>>] {\n const [rateLimitedValue, setRateLimitedValue] = createSignal<TValue>(value)\n\n const rateLimiter = createRateLimiter(setRateLimitedValue, initialOptions)\n\n return [\n rateLimitedValue,\n rateLimiter.maybeExecute.bind(rateLimiter) as Setter<TValue>,\n rateLimiter,\n ]\n}\n"],"names":["createSignal","createRateLimiter"],"mappings":";;;;AAgEgB,SAAA,wBACd,OACA,gBACsE;AACtE,QAAM,CAAC,kBAAkB,mBAAmB,IAAIA,QAAAA,aAAqB,KAAK;AAEpE,QAAA,cAAcC,kBAAAA,kBAAkB,qBAAqB,cAAc;AAElE,SAAA;AAAA,IACL;AAAA,IACA,YAAY,aAAa,KAAK,WAAW;AAAA,IACzC;AAAA,EACF;AACF;;"}
@@ -9,6 +9,12 @@ import { RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
9
9
  * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out
10
10
  * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.
11
11
  *
12
+ * The rate limiter supports two types of windows:
13
+ * - 'fixed': A strict window that resets after the window period. All updates within the window count
14
+ * towards the limit, and the window resets completely after the period.
15
+ * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more
16
+ * consistent rate of updates over time.
17
+ *
12
18
  * For smoother update patterns, consider:
13
19
  * - createThrottledSignal: When you want consistent spacing between updates (e.g. UI changes)
14
20
  * - createDebouncedSignal: When you want to collapse rapid updates into a single update (e.g. search input)
@@ -25,16 +31,18 @@ import { RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
25
31
  *
26
32
  * @example
27
33
  * ```tsx
28
- * // Basic rate limiting - update state at most 5 times per minute
34
+ * // Basic rate limiting - update state at most 5 times per minute with a sliding window
29
35
  * const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {
30
36
  * limit: 5,
31
- * window: 60000
37
+ * window: 60000,
38
+ * windowType: 'sliding'
32
39
  * });
33
40
  *
34
- * // With rejection callback
41
+ * // With rejection callback and fixed window
35
42
  * const [value, setValue] = createRateLimitedSignal(0, {
36
43
  * limit: 3,
37
44
  * window: 5000,
45
+ * windowType: 'fixed',
38
46
  * onReject: (rateLimiter) => {
39
47
  * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
40
48
  * }
@@ -51,8 +59,4 @@ import { RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
51
59
  * };
52
60
  * ```
53
61
  */
54
- export declare function createRateLimitedSignal<TValue>(value: TValue, initialOptions: RateLimiterOptions<Setter<TValue>, [Accessor<TValue>]>): [
55
- Accessor<TValue>,
56
- Setter<TValue>,
57
- SolidRateLimiter<Setter<TValue>, [Accessor<TValue>]>
58
- ];
62
+ export declare function createRateLimitedSignal<TValue>(value: TValue, initialOptions: RateLimiterOptions<Setter<TValue>>): [Accessor<TValue>, Setter<TValue>, SolidRateLimiter<Setter<TValue>>];
@@ -1 +1 @@
1
- {"version":3,"file":"createRateLimitedValue.cjs","sources":["../../../src/rate-limiter/createRateLimitedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createRateLimitedSignal } from './createRateLimitedSignal'\nimport type { SolidRateLimiter } from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A high-level Solid hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window.\n * This hook uses Solid's createSignal internally to manage the rate-limited state.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * For smoother update patterns, consider:\n * - createThrottledValue: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedValue: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns both the rate-limited value and the underlying rateLimiter instance for additional control.\n *\n * For more direct control over rate limiting behavior without Solid state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * @example\n * ```tsx\n * // Basic rate limiting - update at most 5 times per minute\n * const [rateLimitedValue] = createRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000\n * });\n *\n * // With rejection callback\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 3,\n * window: 5000,\n * onReject: (rateLimiter) => {\n * console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Optionally access rateLimiter state via signals\n * const handleSubmit = () => {\n * const remaining = rateLimiter.remainingInWindow();\n * if (remaining > 0) {\n * console.log(`${remaining} updates remaining in this window`);\n * } else {\n * console.log('Rate limit reached for this window');\n * }\n * };\n * ```\n */\nexport function createRateLimitedValue<TValue>(\n value: Accessor<TValue>,\n initialOptions: RateLimiterOptions<Setter<TValue>, [Accessor<TValue>]>,\n): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, [Accessor<TValue>]>] {\n const [rateLimitedValue, setRateLimitedValue, rateLimiter] =\n createRateLimitedSignal(value(), initialOptions)\n\n createEffect(() => {\n setRateLimitedValue(value() as any)\n })\n\n return [rateLimitedValue, rateLimiter]\n}\n"],"names":["createRateLimitedSignal","createEffect"],"mappings":";;;;AAqDgB,SAAA,uBACd,OACA,gBAC0E;AACpE,QAAA,CAAC,kBAAkB,qBAAqB,WAAW,IACvDA,gDAAwB,SAAS,cAAc;AAEjDC,UAAAA,aAAa,MAAM;AACjB,wBAAoB,OAAc;AAAA,EAAA,CACnC;AAEM,SAAA,CAAC,kBAAkB,WAAW;AACvC;;"}
1
+ {"version":3,"file":"createRateLimitedValue.cjs","sources":["../../../src/rate-limiter/createRateLimitedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createRateLimitedSignal } from './createRateLimitedSignal'\nimport type { SolidRateLimiter } from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A high-level Solid hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window.\n * This hook uses Solid's createSignal internally to manage the rate-limited state.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\n *\n * For smoother update patterns, consider:\n * - createThrottledValue: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedValue: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns a tuple containing:\n * - An accessor function that provides the rate-limited value\n * - The rate limiter instance with control methods\n *\n * For more direct control over rate limiting behavior without Solid state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * @example\n * ```tsx\n * // Basic rate limiting - update at most 5 times per minute with a sliding window\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Use the rate-limited value\n * console.log(rateLimitedValue()); // Access the current rate-limited value\n *\n * // Control the rate limiter\n * rateLimiter.reset(); // Reset the rate limit window\n * ```\n */\nexport function createRateLimitedValue<TValue>(\n value: Accessor<TValue>,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>>] {\n const [rateLimitedValue, setRateLimitedValue, rateLimiter] =\n createRateLimitedSignal(value(), initialOptions)\n\n createEffect(() => {\n setRateLimitedValue(value() as any)\n })\n\n return [rateLimitedValue, rateLimiter]\n}\n"],"names":["createRateLimitedSignal","createEffect"],"mappings":";;;;AAiDgB,SAAA,uBACd,OACA,gBACsD;AAChD,QAAA,CAAC,kBAAkB,qBAAqB,WAAW,IACvDA,gDAAwB,SAAS,cAAc;AAEjDC,UAAAA,aAAa,MAAM;AACjB,wBAAoB,OAAc;AAAA,EAAA,CACnC;AAEM,SAAA,CAAC,kBAAkB,WAAW;AACvC;;"}
@@ -9,43 +9,39 @@ import { RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
9
9
  * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out
10
10
  * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.
11
11
  *
12
+ * The rate limiter supports two types of windows:
13
+ * - 'fixed': A strict window that resets after the window period. All updates within the window count
14
+ * towards the limit, and the window resets completely after the period.
15
+ * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more
16
+ * consistent rate of updates over time.
17
+ *
12
18
  * For smoother update patterns, consider:
13
19
  * - createThrottledValue: When you want consistent spacing between updates (e.g. UI changes)
14
20
  * - createDebouncedValue: When you want to collapse rapid updates into a single update (e.g. search input)
15
21
  *
16
22
  * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.
17
23
  *
18
- * The hook returns both the rate-limited value and the underlying rateLimiter instance for additional control.
24
+ * The hook returns a tuple containing:
25
+ * - An accessor function that provides the rate-limited value
26
+ * - The rate limiter instance with control methods
19
27
  *
20
28
  * For more direct control over rate limiting behavior without Solid state management,
21
29
  * consider using the lower-level createRateLimiter hook instead.
22
30
  *
23
31
  * @example
24
32
  * ```tsx
25
- * // Basic rate limiting - update at most 5 times per minute
26
- * const [rateLimitedValue] = createRateLimitedValue(rawValue, {
33
+ * // Basic rate limiting - update at most 5 times per minute with a sliding window
34
+ * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
27
35
  * limit: 5,
28
- * window: 60000
36
+ * window: 60000,
37
+ * windowType: 'sliding'
29
38
  * });
30
39
  *
31
- * // With rejection callback
32
- * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
33
- * limit: 3,
34
- * window: 5000,
35
- * onReject: (rateLimiter) => {
36
- * console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
37
- * }
38
- * });
40
+ * // Use the rate-limited value
41
+ * console.log(rateLimitedValue()); // Access the current rate-limited value
39
42
  *
40
- * // Optionally access rateLimiter state via signals
41
- * const handleSubmit = () => {
42
- * const remaining = rateLimiter.remainingInWindow();
43
- * if (remaining > 0) {
44
- * console.log(`${remaining} updates remaining in this window`);
45
- * } else {
46
- * console.log('Rate limit reached for this window');
47
- * }
48
- * };
43
+ * // Control the rate limiter
44
+ * rateLimiter.reset(); // Reset the rate limit window
49
45
  * ```
50
46
  */
51
- export declare function createRateLimitedValue<TValue>(value: Accessor<TValue>, initialOptions: RateLimiterOptions<Setter<TValue>, [Accessor<TValue>]>): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, [Accessor<TValue>]>];
47
+ export declare function createRateLimitedValue<TValue>(value: Accessor<TValue>, initialOptions: RateLimiterOptions<Setter<TValue>>): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>>];
@@ -4,7 +4,9 @@ const rateLimiter = require("@tanstack/pacer/rate-limiter");
4
4
  const solidJs = require("solid-js");
5
5
  const utils = require("@tanstack/pacer/utils");
6
6
  function createRateLimiter(fn, initialOptions) {
7
- const rateLimiter$1 = new rateLimiter.RateLimiter(fn, initialOptions);
7
+ const rateLimiter$1 = utils.bindInstanceMethods(
8
+ new rateLimiter.RateLimiter(fn, initialOptions)
9
+ );
8
10
  const [executionCount, setExecutionCount] = solidJs.createSignal(
9
11
  rateLimiter$1.getExecutionCount()
10
12
  );
@@ -38,7 +40,7 @@ function createRateLimiter(fn, initialOptions) {
38
40
  }
39
41
  setOptions(initialOptions);
40
42
  return {
41
- ...utils.bindInstanceMethods(rateLimiter$1),
43
+ ...rateLimiter$1,
42
44
  executionCount,
43
45
  rejectionCount,
44
46
  remainingInWindow,
@@ -1 +1 @@
1
- {"version":3,"file":"createRateLimiter.cjs","sources":["../../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\n\nexport interface SolidRateLimiter<\n TFn extends AnyFunction,\n TArgs extends Parameters<TFn>,\n> extends Omit<\n RateLimiter<TFn, TArgs>,\n | 'getExecutionCount'\n | 'getMsUntilNextWindow'\n | 'getRejectionCount'\n | 'getRemainingInWindow'\n > {\n executionCount: Accessor<number>\n msUntilNextWindow: Accessor<number>\n rejectionCount: Accessor<number>\n remainingInWindow: Accessor<number>\n}\n\n/**\n * A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Rate limiting is a simple \"hard limit\" approach that allows executions until a maximum count is reached within\n * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,\n * it does not attempt to space out or collapse executions intelligently.\n *\n * For smoother execution patterns:\n * - Use throttling when you want consistent spacing between executions (e.g. UI updates)\n * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)\n * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)\n *\n * @example\n * ```tsx\n * // Basic rate limiting - max 5 calls per minute\n * const rateLimiter = createRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * });\n *\n * // Monitor rate limit status\n * const handleClick = () => {\n * if (rateLimiter.remainingInWindow() > 0) {\n * rateLimiter.maybeExecute(data);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n *\n * // Access rate limiter state via signals\n * console.log('Executions:', rateLimiter.executionCount());\n * console.log('Rejections:', rateLimiter.rejectionCount());\n * console.log('Remaining:', rateLimiter.remainingInWindow());\n * console.log('Next window in:', rateLimiter.msUntilNextWindow());\n * ```\n */\nexport function createRateLimiter<\n TFn extends AnyFunction,\n TArgs extends Parameters<TFn>,\n>(\n fn: TFn,\n initialOptions: RateLimiterOptions<TFn, TArgs>,\n): SolidRateLimiter<TFn, TArgs> {\n const rateLimiter = new RateLimiter<TFn, TArgs>(fn, initialOptions)\n\n const [executionCount, setExecutionCount] = createSignal(\n rateLimiter.getExecutionCount(),\n )\n const [rejectionCount, setRejectionCount] = createSignal(\n rateLimiter.getRejectionCount(),\n )\n const [remainingInWindow, setRemainingInWindow] = createSignal(\n rateLimiter.getRemainingInWindow(),\n )\n const [msUntilNextWindow, setMsUntilNextWindow] = createSignal(\n rateLimiter.getMsUntilNextWindow(),\n )\n\n function setOptions(newOptions: Partial<RateLimiterOptions<TFn, TArgs>>) {\n rateLimiter.setOptions({\n ...newOptions,\n onExecute: (rateLimiter) => {\n setExecutionCount(rateLimiter.getExecutionCount())\n setRemainingInWindow(rateLimiter.getRemainingInWindow())\n setMsUntilNextWindow(rateLimiter.getMsUntilNextWindow())\n const onExecute = newOptions.onExecute ?? initialOptions.onExecute\n onExecute?.(rateLimiter)\n },\n onReject: (rateLimiter) => {\n setRejectionCount(rateLimiter.getRejectionCount())\n setRemainingInWindow(rateLimiter.getRemainingInWindow())\n setMsUntilNextWindow(rateLimiter.getMsUntilNextWindow())\n const onReject = newOptions.onReject ?? initialOptions.onReject\n onReject?.(rateLimiter)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...bindInstanceMethods(rateLimiter),\n executionCount,\n rejectionCount,\n remainingInWindow,\n msUntilNextWindow,\n setOptions,\n }\n}\n"],"names":["rateLimiter","RateLimiter","createSignal","bindInstanceMethods"],"mappings":";;;;;AA8DgB,SAAA,kBAId,IACA,gBAC8B;AAC9B,QAAMA,gBAAc,IAAIC,wBAAwB,IAAI,cAAc;AAE5D,QAAA,CAAC,gBAAgB,iBAAiB,IAAIC,QAAA;AAAA,IAC1CF,cAAY,kBAAkB;AAAA,EAChC;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAIE,QAAA;AAAA,IAC1CF,cAAY,kBAAkB;AAAA,EAChC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIE,QAAA;AAAA,IAChDF,cAAY,qBAAqB;AAAA,EACnC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIE,QAAA;AAAA,IAChDF,cAAY,qBAAqB;AAAA,EACnC;AAEA,WAAS,WAAW,YAAqD;AACvEA,kBAAY,WAAW;AAAA,MACrB,GAAG;AAAA,MACH,WAAW,CAACA,iBAAgB;AACRA,0BAAAA,aAAY,mBAAmB;AAC5BA,6BAAAA,aAAY,sBAAsB;AAClCA,6BAAAA,aAAY,sBAAsB;AACjD,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MACd;AAAA,MACA,UAAU,CAACA,iBAAgB;AACPA,0BAAAA,aAAY,mBAAmB;AAC5BA,6BAAAA,aAAY,sBAAsB;AAClCA,6BAAAA,aAAY,sBAAsB;AACjD,cAAA,WAAW,WAAW,YAAY,eAAe;AACvD,6CAAWA;AAAAA,MAAW;AAAA,IACxB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAGG,MAAAA,oBAAoBH,aAAW;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
1
+ {"version":3,"file":"createRateLimiter.cjs","sources":["../../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\n\nexport interface SolidRateLimiter<TFn extends AnyFunction>\n extends Omit<\n RateLimiter<TFn>,\n | 'getExecutionCount'\n | 'getMsUntilNextWindow'\n | 'getRejectionCount'\n | 'getRemainingInWindow'\n > {\n executionCount: Accessor<number>\n msUntilNextWindow: Accessor<number>\n rejectionCount: Accessor<number>\n remainingInWindow: Accessor<number>\n}\n\n/**\n * A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Rate limiting is a simple \"hard limit\" approach that allows executions until a maximum count is reached within\n * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,\n * it does not attempt to space out or collapse executions intelligently.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n * consistent rate of execution over time.\n *\n * For smoother execution patterns:\n * - Use throttling when you want consistent spacing between executions (e.g. UI updates)\n * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)\n * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)\n *\n * @example\n * ```tsx\n * // Basic rate limiting - max 5 calls per minute with a sliding window\n * const rateLimiter = createRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Monitor rate limit status\n * const handleClick = () => {\n * if (rateLimiter.remainingInWindow() > 0) {\n * rateLimiter.maybeExecute(data);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n *\n * // Access rate limiter state via signals\n * console.log('Executions:', rateLimiter.executionCount());\n * console.log('Rejections:', rateLimiter.rejectionCount());\n * console.log('Remaining:', rateLimiter.remainingInWindow());\n * console.log('Next window in:', rateLimiter.msUntilNextWindow());\n * ```\n */\nexport function createRateLimiter<TFn extends AnyFunction>(\n fn: TFn,\n initialOptions: RateLimiterOptions<TFn>,\n): SolidRateLimiter<TFn> {\n const rateLimiter = bindInstanceMethods(\n new RateLimiter<TFn>(fn, initialOptions),\n )\n\n const [executionCount, setExecutionCount] = createSignal(\n rateLimiter.getExecutionCount(),\n )\n const [rejectionCount, setRejectionCount] = createSignal(\n rateLimiter.getRejectionCount(),\n )\n const [remainingInWindow, setRemainingInWindow] = createSignal(\n rateLimiter.getRemainingInWindow(),\n )\n const [msUntilNextWindow, setMsUntilNextWindow] = createSignal(\n rateLimiter.getMsUntilNextWindow(),\n )\n\n function setOptions(newOptions: Partial<RateLimiterOptions<TFn>>) {\n rateLimiter.setOptions({\n ...newOptions,\n onExecute: (rateLimiter) => {\n setExecutionCount(rateLimiter.getExecutionCount())\n setRemainingInWindow(rateLimiter.getRemainingInWindow())\n setMsUntilNextWindow(rateLimiter.getMsUntilNextWindow())\n\n const onExecute = newOptions.onExecute ?? initialOptions.onExecute\n onExecute?.(rateLimiter)\n },\n onReject: (rateLimiter) => {\n setRejectionCount(rateLimiter.getRejectionCount())\n setRemainingInWindow(rateLimiter.getRemainingInWindow())\n setMsUntilNextWindow(rateLimiter.getMsUntilNextWindow())\n\n const onReject = newOptions.onReject ?? initialOptions.onReject\n onReject?.(rateLimiter)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...rateLimiter,\n executionCount,\n rejectionCount,\n remainingInWindow,\n msUntilNextWindow,\n setOptions,\n } as SolidRateLimiter<TFn>\n}\n"],"names":["rateLimiter","bindInstanceMethods","RateLimiter","createSignal"],"mappings":";;;;;AAmEgB,SAAA,kBACd,IACA,gBACuB;AACvB,QAAMA,gBAAcC,MAAA;AAAA,IAClB,IAAIC,YAAAA,YAAiB,IAAI,cAAc;AAAA,EACzC;AAEM,QAAA,CAAC,gBAAgB,iBAAiB,IAAIC,QAAA;AAAA,IAC1CH,cAAY,kBAAkB;AAAA,EAChC;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAIG,QAAA;AAAA,IAC1CH,cAAY,kBAAkB;AAAA,EAChC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIG,QAAA;AAAA,IAChDH,cAAY,qBAAqB;AAAA,EACnC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIG,QAAA;AAAA,IAChDH,cAAY,qBAAqB;AAAA,EACnC;AAEA,WAAS,WAAW,YAA8C;AAChEA,kBAAY,WAAW;AAAA,MACrB,GAAG;AAAA,MACH,WAAW,CAACA,iBAAgB;AACRA,0BAAAA,aAAY,mBAAmB;AAC5BA,6BAAAA,aAAY,sBAAsB;AAClCA,6BAAAA,aAAY,sBAAsB;AAEjD,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MACd;AAAA,MACA,UAAU,CAACA,iBAAgB;AACPA,0BAAAA,aAAY,mBAAmB;AAC5BA,6BAAAA,aAAY,sBAAsB;AAClCA,6BAAAA,aAAY,sBAAsB;AAEjD,cAAA,WAAW,WAAW,YAAY,eAAe;AACvD,6CAAWA;AAAAA,MAAW;AAAA,IACxB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAGA;AAAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
@@ -1,7 +1,7 @@
1
1
  import { RateLimiter, RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
2
2
  import { Accessor } from 'solid-js';
3
3
  import { AnyFunction } from '@tanstack/pacer/types';
4
- export interface SolidRateLimiter<TFn extends AnyFunction, TArgs extends Parameters<TFn>> extends Omit<RateLimiter<TFn, TArgs>, 'getExecutionCount' | 'getMsUntilNextWindow' | 'getRejectionCount' | 'getRemainingInWindow'> {
4
+ export interface SolidRateLimiter<TFn extends AnyFunction> extends Omit<RateLimiter<TFn>, 'getExecutionCount' | 'getMsUntilNextWindow' | 'getRejectionCount' | 'getRemainingInWindow'> {
5
5
  executionCount: Accessor<number>;
6
6
  msUntilNextWindow: Accessor<number>;
7
7
  rejectionCount: Accessor<number>;
@@ -17,6 +17,12 @@ export interface SolidRateLimiter<TFn extends AnyFunction, TArgs extends Paramet
17
17
  * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,
18
18
  * it does not attempt to space out or collapse executions intelligently.
19
19
  *
20
+ * The rate limiter supports two types of windows:
21
+ * - 'fixed': A strict window that resets after the window period. All executions within the window count
22
+ * towards the limit, and the window resets completely after the period.
23
+ * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more
24
+ * consistent rate of execution over time.
25
+ *
20
26
  * For smoother execution patterns:
21
27
  * - Use throttling when you want consistent spacing between executions (e.g. UI updates)
22
28
  * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)
@@ -24,10 +30,11 @@ export interface SolidRateLimiter<TFn extends AnyFunction, TArgs extends Paramet
24
30
  *
25
31
  * @example
26
32
  * ```tsx
27
- * // Basic rate limiting - max 5 calls per minute
33
+ * // Basic rate limiting - max 5 calls per minute with a sliding window
28
34
  * const rateLimiter = createRateLimiter(apiCall, {
29
35
  * limit: 5,
30
36
  * window: 60000,
37
+ * windowType: 'sliding'
31
38
  * });
32
39
  *
33
40
  * // Monitor rate limit status
@@ -46,4 +53,4 @@ export interface SolidRateLimiter<TFn extends AnyFunction, TArgs extends Paramet
46
53
  * console.log('Next window in:', rateLimiter.msUntilNextWindow());
47
54
  * ```
48
55
  */
49
- export declare function createRateLimiter<TFn extends AnyFunction, TArgs extends Parameters<TFn>>(fn: TFn, initialOptions: RateLimiterOptions<TFn, TArgs>): SolidRateLimiter<TFn, TArgs>;
56
+ export declare function createRateLimiter<TFn extends AnyFunction>(fn: TFn, initialOptions: RateLimiterOptions<TFn>): SolidRateLimiter<TFn>;
@@ -1 +1 @@
1
- {"version":3,"file":"createThrottledSignal.cjs","sources":["../../../src/throttler/createThrottledSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createThrottler } from './createThrottler'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\n\n/**\n * A Solid hook that creates a throttled state value that updates at most once within a specified time window.\n * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.\n *\n * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.\n * This is useful for rate-limiting expensive re-renders or operations that depend on rapidly changing state.\n *\n * The hook returns a tuple containing:\n * - The throttled state value accessor\n * - A throttled setter function that respects the configured wait time\n * - The throttler instance for additional control\n *\n * For more direct control over throttling without state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * @example\n * ```tsx\n * // Basic throttling - update state at most once per second\n * const [value, setValue, throttler] = createThrottledSignal(0, { wait: 1000 });\n *\n * // With custom leading/trailing behavior\n * const [value, setValue] = createThrottledSignal(0, {\n * wait: 1000,\n * leading: true, // Update immediately on first change\n * trailing: false // Skip trailing edge updates\n * });\n *\n * // Access throttler state via signals\n * console.log('Executions:', throttler.executionCount());\n * console.log('Is pending:', throttler.isPending());\n * console.log('Last execution:', throttler.lastExecutionTime());\n * console.log('Next execution:', throttler.nextExecutionTime());\n * ```\n */\nexport function createThrottledSignal<TValue>(\n value: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>, [Accessor<TValue>]>,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidThrottler<Setter<TValue>, [Accessor<TValue>]>,\n] {\n const [throttledValue, setThrottledValue] = createSignal<TValue>(value)\n const throttler = createThrottler(setThrottledValue, initialOptions)\n return [throttledValue, throttler.maybeExecute as Setter<TValue>, throttler]\n}\n"],"names":["createSignal","createThrottler"],"mappings":";;;;AAwCgB,SAAA,sBACd,OACA,gBAKA;AACA,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,QAAAA,aAAqB,KAAK;AAChE,QAAA,YAAYC,gBAAAA,gBAAgB,mBAAmB,cAAc;AACnE,SAAO,CAAC,gBAAgB,UAAU,cAAgC,SAAS;AAC7E;;"}
1
+ {"version":3,"file":"createThrottledSignal.cjs","sources":["../../../src/throttler/createThrottledSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createThrottler } from './createThrottler'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\n\n/**\n * A Solid hook that creates a throttled state value that updates at most once within a specified time window.\n * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.\n *\n * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.\n * This is useful for rate-limiting expensive re-renders or operations that depend on rapidly changing state.\n *\n * The hook returns a tuple containing:\n * - The throttled state value accessor\n * - A throttled setter function that respects the configured wait time\n * - The throttler instance for additional control\n *\n * For more direct control over throttling without state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * @example\n * ```tsx\n * // Basic throttling - update state at most once per second\n * const [value, setValue, throttler] = createThrottledSignal(0, { wait: 1000 });\n *\n * // With custom leading/trailing behavior\n * const [value, setValue] = createThrottledSignal(0, {\n * wait: 1000,\n * leading: true, // Update immediately on first change\n * trailing: false // Skip trailing edge updates\n * });\n *\n * // Access throttler state via signals\n * console.log('Executions:', throttler.executionCount());\n * console.log('Is pending:', throttler.isPending());\n * console.log('Last execution:', throttler.lastExecutionTime());\n * console.log('Next execution:', throttler.nextExecutionTime());\n * ```\n */\nexport function createThrottledSignal<TValue>(\n value: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n): [Accessor<TValue>, Setter<TValue>, SolidThrottler<Setter<TValue>>] {\n const [throttledValue, setThrottledValue] = createSignal<TValue>(value)\n const throttler = createThrottler(setThrottledValue, initialOptions)\n return [throttledValue, throttler.maybeExecute as Setter<TValue>, throttler]\n}\n"],"names":["createSignal","createThrottler"],"mappings":";;;;AAwCgB,SAAA,sBACd,OACA,gBACoE;AACpE,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,QAAAA,aAAqB,KAAK;AAChE,QAAA,YAAYC,gBAAAA,gBAAgB,mBAAmB,cAAc;AACnE,SAAO,CAAC,gBAAgB,UAAU,cAAgC,SAAS;AAC7E;;"}
@@ -35,8 +35,4 @@ import { ThrottlerOptions } from '@tanstack/pacer/throttler';
35
35
  * console.log('Next execution:', throttler.nextExecutionTime());
36
36
  * ```
37
37
  */
38
- export declare function createThrottledSignal<TValue>(value: TValue, initialOptions: ThrottlerOptions<Setter<TValue>, [Accessor<TValue>]>): [
39
- Accessor<TValue>,
40
- Setter<TValue>,
41
- SolidThrottler<Setter<TValue>, [Accessor<TValue>]>
42
- ];
38
+ export declare function createThrottledSignal<TValue>(value: TValue, initialOptions: ThrottlerOptions<Setter<TValue>>): [Accessor<TValue>, Setter<TValue>, SolidThrottler<Setter<TValue>>];
@@ -9,9 +9,6 @@ function createThrottledValue(value, initialOptions) {
9
9
  );
10
10
  solidJs.createEffect(() => {
11
11
  setThrottledValue(value());
12
- solidJs.onCleanup(() => {
13
- throttler.cancel();
14
- });
15
12
  });
16
13
  return [throttledValue, throttler];
17
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"createThrottledValue.cjs","sources":["../../../src/throttler/createThrottledValue.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { createThrottledSignal } from './createThrottledSignal'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\n\n/**\n * A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window.\n * This hook uses Solid's createSignal internally to manage the throttled state.\n *\n * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.\n * This is useful for rate-limiting expensive re-renders or API calls that depend on rapidly changing values.\n *\n * The hook returns both the throttled value and the underlying throttler instance for additional control.\n * The throttled value will update according to the leading/trailing edge behavior specified in the options.\n *\n * For more direct control over throttling behavior without Solid state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * @example\n * ```tsx\n * // Basic throttling - update at most once per second\n * const [throttledValue] = createThrottledValue(rawValue, { wait: 1000 });\n *\n * // With custom leading/trailing behavior\n * const [throttledValue, throttler] = createThrottledValue(rawValue, {\n * wait: 1000,\n * leading: true, // Update immediately on first change\n * trailing: false // Skip trailing edge updates\n * });\n *\n * // Access throttler state via signals\n * console.log('Executions:', throttler.executionCount());\n * console.log('Is pending:', throttler.isPending());\n * console.log('Last execution:', throttler.lastExecutionTime());\n * console.log('Next execution:', throttler.nextExecutionTime());\n * ```\n */\nexport function createThrottledValue<TValue>(\n value: Accessor<TValue>,\n initialOptions: ThrottlerOptions<Setter<TValue>, [Accessor<TValue>]>,\n): [Accessor<TValue>, SolidThrottler<Setter<TValue>, [Accessor<TValue>]>] {\n const [throttledValue, setThrottledValue, throttler] = createThrottledSignal(\n value(),\n initialOptions,\n )\n\n createEffect(() => {\n setThrottledValue(value() as any)\n onCleanup(() => {\n throttler.cancel()\n })\n })\n\n return [throttledValue, throttler]\n}\n"],"names":["createThrottledSignal","createEffect","onCleanup"],"mappings":";;;;AAsCgB,SAAA,qBACd,OACA,gBACwE;AACxE,QAAM,CAAC,gBAAgB,mBAAmB,SAAS,IAAIA,sBAAA;AAAA,IACrD,MAAM;AAAA,IACN;AAAA,EACF;AAEAC,UAAAA,aAAa,MAAM;AACjB,sBAAkB,OAAc;AAChCC,YAAAA,UAAU,MAAM;AACd,gBAAU,OAAO;AAAA,IAAA,CAClB;AAAA,EAAA,CACF;AAEM,SAAA,CAAC,gBAAgB,SAAS;AACnC;;"}
1
+ {"version":3,"file":"createThrottledValue.cjs","sources":["../../../src/throttler/createThrottledValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createThrottledSignal } from './createThrottledSignal'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\n\n/**\n * A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window.\n * This hook uses Solid's createSignal internally to manage the throttled state.\n *\n * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.\n * This is useful for rate-limiting expensive re-renders or API calls that depend on rapidly changing values.\n *\n * The hook returns a tuple containing:\n * - An accessor function that provides the throttled value\n * - The throttler instance with control methods\n *\n * The throttled value will update according to the leading/trailing edge behavior specified in the options.\n *\n * For more direct control over throttling behavior without Solid state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * @example\n * ```tsx\n * // Basic throttling - update at most once per second\n * const [throttledValue, throttler] = createThrottledValue(rawValue, { wait: 1000 });\n *\n * // Use the throttled value\n * console.log(throttledValue()); // Access the current throttled value\n *\n * // Control the throttler\n * throttler.cancel(); // Cancel any pending updates\n * ```\n */\nexport function createThrottledValue<TValue>(\n value: Accessor<TValue>,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n): [Accessor<TValue>, SolidThrottler<Setter<TValue>>] {\n const [throttledValue, setThrottledValue, throttler] = createThrottledSignal(\n value(),\n initialOptions,\n )\n\n createEffect(() => {\n setThrottledValue(value() as any)\n })\n\n return [throttledValue, throttler]\n}\n"],"names":["createThrottledSignal","createEffect"],"mappings":";;;;AAkCgB,SAAA,qBACd,OACA,gBACoD;AACpD,QAAM,CAAC,gBAAgB,mBAAmB,SAAS,IAAIA,sBAAA;AAAA,IACrD,MAAM;AAAA,IACN;AAAA,EACF;AAEAC,UAAAA,aAAa,MAAM;AACjB,sBAAkB,OAAc;AAAA,EAAA,CACjC;AAEM,SAAA,CAAC,gBAAgB,SAAS;AACnC;;"}
@@ -8,7 +8,10 @@ import { ThrottlerOptions } from '@tanstack/pacer/throttler';
8
8
  * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.
9
9
  * This is useful for rate-limiting expensive re-renders or API calls that depend on rapidly changing values.
10
10
  *
11
- * The hook returns both the throttled value and the underlying throttler instance for additional control.
11
+ * The hook returns a tuple containing:
12
+ * - An accessor function that provides the throttled value
13
+ * - The throttler instance with control methods
14
+ *
12
15
  * The throttled value will update according to the leading/trailing edge behavior specified in the options.
13
16
  *
14
17
  * For more direct control over throttling behavior without Solid state management,
@@ -17,20 +20,13 @@ import { ThrottlerOptions } from '@tanstack/pacer/throttler';
17
20
  * @example
18
21
  * ```tsx
19
22
  * // Basic throttling - update at most once per second
20
- * const [throttledValue] = createThrottledValue(rawValue, { wait: 1000 });
23
+ * const [throttledValue, throttler] = createThrottledValue(rawValue, { wait: 1000 });
21
24
  *
22
- * // With custom leading/trailing behavior
23
- * const [throttledValue, throttler] = createThrottledValue(rawValue, {
24
- * wait: 1000,
25
- * leading: true, // Update immediately on first change
26
- * trailing: false // Skip trailing edge updates
27
- * });
25
+ * // Use the throttled value
26
+ * console.log(throttledValue()); // Access the current throttled value
28
27
  *
29
- * // Access throttler state via signals
30
- * console.log('Executions:', throttler.executionCount());
31
- * console.log('Is pending:', throttler.isPending());
32
- * console.log('Last execution:', throttler.lastExecutionTime());
33
- * console.log('Next execution:', throttler.nextExecutionTime());
28
+ * // Control the throttler
29
+ * throttler.cancel(); // Cancel any pending updates
34
30
  * ```
35
31
  */
36
- export declare function createThrottledValue<TValue>(value: Accessor<TValue>, initialOptions: ThrottlerOptions<Setter<TValue>, [Accessor<TValue>]>): [Accessor<TValue>, SolidThrottler<Setter<TValue>, [Accessor<TValue>]>];
32
+ export declare function createThrottledValue<TValue>(value: Accessor<TValue>, initialOptions: ThrottlerOptions<Setter<TValue>>): [Accessor<TValue>, SolidThrottler<Setter<TValue>>];
@@ -4,7 +4,7 @@ const throttler = require("@tanstack/pacer/throttler");
4
4
  const solidJs = require("solid-js");
5
5
  const utils = require("@tanstack/pacer/utils");
6
6
  function createThrottler(fn, initialOptions) {
7
- const throttler$1 = new throttler.Throttler(fn, initialOptions);
7
+ const throttler$1 = utils.bindInstanceMethods(new throttler.Throttler(fn, initialOptions));
8
8
  const [executionCount, setExecutionCount] = solidJs.createSignal(
9
9
  throttler$1.getExecutionCount()
10
10
  );
@@ -29,8 +29,13 @@ function createThrottler(fn, initialOptions) {
29
29
  });
30
30
  }
31
31
  setOptions(initialOptions);
32
+ solidJs.createEffect(() => {
33
+ solidJs.onCleanup(() => {
34
+ throttler$1.cancel();
35
+ });
36
+ });
32
37
  return {
33
- ...utils.bindInstanceMethods(throttler$1),
38
+ ...throttler$1,
34
39
  executionCount,
35
40
  isPending,
36
41
  lastExecutionTime,
@@ -1 +1 @@
1
- {"version":3,"file":"createThrottler.cjs","sources":["../../../src/throttler/createThrottler.ts"],"sourcesContent":["import { Throttler } from '@tanstack/pacer/throttler'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\n\n/**\n * An extension of the Throttler class that adds Solid signals to access the internal state of the throttler\n */\nexport interface SolidThrottler<\n TFn extends AnyFunction,\n TArgs extends Parameters<TFn>,\n> extends Omit<\n Throttler<TFn, TArgs>,\n | 'getExecutionCount'\n | 'getIsPending'\n | 'getLastExecutionTime'\n | 'getNextExecutionTime'\n > {\n executionCount: Accessor<number>\n isPending: Accessor<boolean>\n lastExecutionTime: Accessor<number>\n nextExecutionTime: Accessor<number>\n}\n\n/**\n * A low-level Solid hook that creates a `Throttler` instance that limits how often the provided function can execute.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that\n * you can integrate with any state management solution (createSignal, Redux, Zustand, Jotai, etc). For a simpler and higher-level hook that\n * integrates directly with Solid's createSignal, see createThrottledSignal.\n *\n * Throttling ensures a function executes at most once within a specified time window,\n * regardless of how many times it is called. This is useful for rate-limiting\n * expensive operations or UI updates.\n *\n * @example\n * ```tsx\n * // Basic throttling with custom state\n * const [value, setValue] = createSignal(0);\n * const throttler = createThrottler(setValue, { wait: 1000 });\n *\n * // With any state manager\n * const throttler = createThrottler(\n * (value) => stateManager.setState(value),\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false // Skip trailing edge updates\n * }\n * );\n *\n * // Access throttler state via signals\n * console.log(throttler.executionCount()); // number of times executed\n * console.log(throttler.isPending()); // whether throttled function is pending\n * console.log(throttler.lastExecutionTime()); // timestamp of last execution\n * console.log(throttler.nextExecutionTime()); // timestamp of next allowed execution\n * ```\n */\nexport function createThrottler<\n TFn extends AnyFunction,\n TArgs extends Parameters<TFn>,\n>(\n fn: TFn,\n initialOptions: ThrottlerOptions<TFn, TArgs>,\n): SolidThrottler<TFn, TArgs> {\n const throttler = new Throttler<TFn, TArgs>(fn, initialOptions)\n\n const [executionCount, setExecutionCount] = createSignal(\n throttler.getExecutionCount(),\n )\n const [isPending, setIsPending] = createSignal(throttler.getIsPending())\n const [lastExecutionTime, setLastExecutionTime] = createSignal(\n throttler.getLastExecutionTime(),\n )\n const [nextExecutionTime, setNextExecutionTime] = createSignal(\n throttler.getNextExecutionTime(),\n )\n\n function setOptions(newOptions: Partial<ThrottlerOptions<TFn, TArgs>>) {\n throttler.setOptions({\n ...newOptions,\n onExecute: (throttler) => {\n setExecutionCount(throttler.getExecutionCount())\n setIsPending(throttler.getIsPending())\n setLastExecutionTime(throttler.getLastExecutionTime())\n setNextExecutionTime(throttler.getNextExecutionTime())\n\n const onExecute = newOptions.onExecute ?? initialOptions.onExecute\n onExecute?.(throttler)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...bindInstanceMethods(throttler),\n executionCount,\n isPending,\n lastExecutionTime,\n nextExecutionTime,\n setOptions,\n }\n}\n"],"names":["throttler","Throttler","createSignal","bindInstanceMethods"],"mappings":";;;;;AA4DgB,SAAA,gBAId,IACA,gBAC4B;AAC5B,QAAMA,cAAY,IAAIC,oBAAsB,IAAI,cAAc;AAExD,QAAA,CAAC,gBAAgB,iBAAiB,IAAIC,QAAA;AAAA,IAC1CF,YAAU,kBAAkB;AAAA,EAC9B;AACA,QAAM,CAAC,WAAW,YAAY,IAAIE,QAAAA,aAAaF,YAAU,cAAc;AACjE,QAAA,CAAC,mBAAmB,oBAAoB,IAAIE,QAAA;AAAA,IAChDF,YAAU,qBAAqB;AAAA,EACjC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIE,QAAA;AAAA,IAChDF,YAAU,qBAAqB;AAAA,EACjC;AAEA,WAAS,WAAW,YAAmD;AACrEA,gBAAU,WAAW;AAAA,MACnB,GAAG;AAAA,MACH,WAAW,CAACA,eAAc;AACNA,0BAAAA,WAAU,mBAAmB;AAClCA,qBAAAA,WAAU,cAAc;AAChBA,6BAAAA,WAAU,sBAAsB;AAChCA,6BAAAA,WAAU,sBAAsB;AAE/C,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MAAS;AAAA,IACvB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAGG,MAAAA,oBAAoBH,WAAS;AAAA,IAChC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
1
+ {"version":3,"file":"createThrottler.cjs","sources":["../../../src/throttler/createThrottler.ts"],"sourcesContent":["import { Throttler } from '@tanstack/pacer/throttler'\nimport { createEffect, createSignal, onCleanup } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\n\n/**\n * An extension of the Throttler class that adds Solid signals to access the internal state of the throttler\n */\nexport interface SolidThrottler<TFn extends AnyFunction>\n extends Omit<\n Throttler<TFn>,\n | 'getExecutionCount'\n | 'getIsPending'\n | 'getLastExecutionTime'\n | 'getNextExecutionTime'\n > {\n executionCount: Accessor<number>\n isPending: Accessor<boolean>\n lastExecutionTime: Accessor<number>\n nextExecutionTime: Accessor<number>\n}\n\n/**\n * A low-level Solid hook that creates a `Throttler` instance that limits how often the provided function can execute.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that\n * you can integrate with any state management solution (createSignal, Redux, Zustand, Jotai, etc). For a simpler and higher-level hook that\n * integrates directly with Solid's createSignal, see createThrottledSignal.\n *\n * Throttling ensures a function executes at most once within a specified time window,\n * regardless of how many times it is called. This is useful for rate-limiting\n * expensive operations or UI updates.\n *\n * @example\n * ```tsx\n * // Basic throttling with custom state\n * const [value, setValue] = createSignal(0);\n * const throttler = createThrottler(setValue, { wait: 1000 });\n *\n * // With any state manager\n * const throttler = createThrottler(\n * (value) => stateManager.setState(value),\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false // Skip trailing edge updates\n * }\n * );\n *\n * // Access throttler state via signals\n * console.log(throttler.executionCount()); // number of times executed\n * console.log(throttler.isPending()); // whether throttled function is pending\n * console.log(throttler.lastExecutionTime()); // timestamp of last execution\n * console.log(throttler.nextExecutionTime()); // timestamp of next allowed execution\n * ```\n */\nexport function createThrottler<TFn extends AnyFunction>(\n fn: TFn,\n initialOptions: ThrottlerOptions<TFn>,\n): SolidThrottler<TFn> {\n const throttler = bindInstanceMethods(new Throttler<TFn>(fn, initialOptions))\n\n const [executionCount, setExecutionCount] = createSignal(\n throttler.getExecutionCount(),\n )\n const [isPending, setIsPending] = createSignal(throttler.getIsPending())\n const [lastExecutionTime, setLastExecutionTime] = createSignal(\n throttler.getLastExecutionTime(),\n )\n const [nextExecutionTime, setNextExecutionTime] = createSignal(\n throttler.getNextExecutionTime(),\n )\n\n function setOptions(newOptions: Partial<ThrottlerOptions<TFn>>) {\n throttler.setOptions({\n ...newOptions,\n onExecute: (throttler) => {\n setExecutionCount(throttler.getExecutionCount())\n setIsPending(throttler.getIsPending())\n setLastExecutionTime(throttler.getLastExecutionTime())\n setNextExecutionTime(throttler.getNextExecutionTime())\n\n const onExecute = newOptions.onExecute ?? initialOptions.onExecute\n onExecute?.(throttler)\n },\n })\n }\n\n setOptions(initialOptions)\n\n createEffect(() => {\n onCleanup(() => {\n throttler.cancel()\n })\n })\n\n return {\n ...throttler,\n executionCount,\n isPending,\n lastExecutionTime,\n nextExecutionTime,\n setOptions,\n } as SolidThrottler<TFn>\n}\n"],"names":["throttler","bindInstanceMethods","Throttler","createSignal","createEffect","onCleanup"],"mappings":";;;;;AA0DgB,SAAA,gBACd,IACA,gBACqB;AACrB,QAAMA,cAAYC,MAAAA,oBAAoB,IAAIC,UAAe,UAAA,IAAI,cAAc,CAAC;AAEtE,QAAA,CAAC,gBAAgB,iBAAiB,IAAIC,QAAA;AAAA,IAC1CH,YAAU,kBAAkB;AAAA,EAC9B;AACA,QAAM,CAAC,WAAW,YAAY,IAAIG,QAAAA,aAAaH,YAAU,cAAc;AACjE,QAAA,CAAC,mBAAmB,oBAAoB,IAAIG,QAAA;AAAA,IAChDH,YAAU,qBAAqB;AAAA,EACjC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIG,QAAA;AAAA,IAChDH,YAAU,qBAAqB;AAAA,EACjC;AAEA,WAAS,WAAW,YAA4C;AAC9DA,gBAAU,WAAW;AAAA,MACnB,GAAG;AAAA,MACH,WAAW,CAACA,eAAc;AACNA,0BAAAA,WAAU,mBAAmB;AAClCA,qBAAAA,WAAU,cAAc;AAChBA,6BAAAA,WAAU,sBAAsB;AAChCA,6BAAAA,WAAU,sBAAsB;AAE/C,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MAAS;AAAA,IACvB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAEzBI,UAAAA,aAAa,MAAM;AACjBC,YAAAA,UAAU,MAAM;AACdL,kBAAU,OAAO;AAAA,IAAA,CAClB;AAAA,EAAA,CACF;AAEM,SAAA;AAAA,IACL,GAAGA;AAAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
@@ -4,7 +4,7 @@ import { AnyFunction } from '@tanstack/pacer/types';
4
4
  /**
5
5
  * An extension of the Throttler class that adds Solid signals to access the internal state of the throttler
6
6
  */
7
- export interface SolidThrottler<TFn extends AnyFunction, TArgs extends Parameters<TFn>> extends Omit<Throttler<TFn, TArgs>, 'getExecutionCount' | 'getIsPending' | 'getLastExecutionTime' | 'getNextExecutionTime'> {
7
+ export interface SolidThrottler<TFn extends AnyFunction> extends Omit<Throttler<TFn>, 'getExecutionCount' | 'getIsPending' | 'getLastExecutionTime' | 'getNextExecutionTime'> {
8
8
  executionCount: Accessor<number>;
9
9
  isPending: Accessor<boolean>;
10
10
  lastExecutionTime: Accessor<number>;
@@ -44,4 +44,4 @@ export interface SolidThrottler<TFn extends AnyFunction, TArgs extends Parameter
44
44
  * console.log(throttler.nextExecutionTime()); // timestamp of next allowed execution
45
45
  * ```
46
46
  */
47
- export declare function createThrottler<TFn extends AnyFunction, TArgs extends Parameters<TFn>>(fn: TFn, initialOptions: ThrottlerOptions<TFn, TArgs>): SolidThrottler<TFn, TArgs>;
47
+ export declare function createThrottler<TFn extends AnyFunction>(fn: TFn, initialOptions: ThrottlerOptions<TFn>): SolidThrottler<TFn>;
@@ -1,9 +1,12 @@
1
1
  import { AsyncDebouncer, AsyncDebouncerOptions } from '@tanstack/pacer/async-debouncer';
2
2
  import { AnyAsyncFunction } from '@tanstack/pacer/types';
3
3
  import { Accessor } from 'solid-js';
4
- export interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction, TArgs extends Parameters<TFn>> extends Omit<AsyncDebouncer<TFn, TArgs>, 'getExecutionCount' | 'getIsPending'> {
5
- executionCount: Accessor<number>;
4
+ export interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction> extends Omit<AsyncDebouncer<TFn>, 'getErrorCount' | 'getIsPending' | 'getLastResult' | 'getSettleCount' | 'getSuccessCount'> {
5
+ errorCount: Accessor<number>;
6
6
  isPending: Accessor<boolean>;
7
+ lastResult: Accessor<ReturnType<TFn> | undefined>;
8
+ settleCount: Accessor<number>;
9
+ successCount: Accessor<number>;
7
10
  }
8
11
  /**
9
12
  * A low-level Solid hook that creates an `AsyncDebouncer` instance to delay execution of an async function.
@@ -39,4 +42,4 @@ export interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction, TArgs extends
39
42
  * );
40
43
  * ```
41
44
  */
42
- export declare function createAsyncDebouncer<TFn extends AnyAsyncFunction, TArgs extends Parameters<TFn>>(fn: TFn, initialOptions: AsyncDebouncerOptions<TFn, TArgs>): SolidAsyncDebouncer<TFn, TArgs>;
45
+ export declare function createAsyncDebouncer<TFn extends AnyAsyncFunction>(fn: TFn, initialOptions: AsyncDebouncerOptions<TFn>): SolidAsyncDebouncer<TFn>;
@@ -3,26 +3,41 @@ import { createSignal } from "solid-js";
3
3
  import { bindInstanceMethods } from "@tanstack/pacer/utils";
4
4
  function createAsyncDebouncer(fn, initialOptions) {
5
5
  const asyncDebouncer = new AsyncDebouncer(fn, initialOptions);
6
- const [executionCount, setExecutionCount] = createSignal(
7
- asyncDebouncer.getExecutionCount()
6
+ const [errorCount, setErrorCount] = createSignal(
7
+ asyncDebouncer.getErrorCount()
8
+ );
9
+ const [settleCount, setSettleCount] = createSignal(
10
+ asyncDebouncer.getSettleCount()
11
+ );
12
+ const [successCount, setSuccessCount] = createSignal(
13
+ asyncDebouncer.getSuccessCount()
8
14
  );
9
15
  const [isPending, setIsPending] = createSignal(asyncDebouncer.getIsPending());
16
+ const [lastResult, setLastResult] = createSignal(
17
+ asyncDebouncer.getLastResult()
18
+ );
10
19
  function setOptions(newOptions) {
11
20
  asyncDebouncer.setOptions({
12
21
  ...newOptions,
13
- onExecute: (asyncDebouncer2) => {
14
- setExecutionCount(asyncDebouncer2.getExecutionCount());
22
+ onSettled: (asyncDebouncer2) => {
23
+ setSuccessCount(asyncDebouncer2.getSuccessCount());
24
+ setErrorCount(asyncDebouncer2.getErrorCount());
25
+ setSettleCount(asyncDebouncer2.getSettleCount());
15
26
  setIsPending(asyncDebouncer2.getIsPending());
16
- const onExecute = newOptions.onExecute ?? initialOptions.onExecute;
17
- onExecute == null ? void 0 : onExecute(asyncDebouncer2);
27
+ setLastResult(asyncDebouncer2.getLastResult());
28
+ const onSettled = newOptions.onSettled ?? initialOptions.onSettled;
29
+ onSettled == null ? void 0 : onSettled(asyncDebouncer2);
18
30
  }
19
31
  });
20
32
  }
21
33
  setOptions(initialOptions);
22
34
  return {
23
35
  ...bindInstanceMethods(asyncDebouncer),
24
- executionCount,
36
+ errorCount,
25
37
  isPending,
38
+ lastResult,
39
+ settleCount,
40
+ successCount,
26
41
  setOptions
27
42
  };
28
43
  }
@@ -1 +1 @@
1
- {"version":3,"file":"createAsyncDebouncer.js","sources":["../../../src/async-debouncer/createAsyncDebouncer.ts"],"sourcesContent":["import { AsyncDebouncer } from '@tanstack/pacer/async-debouncer'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { AsyncDebouncerOptions } from '@tanstack/pacer/async-debouncer'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type { Accessor } from 'solid-js'\n\nexport interface SolidAsyncDebouncer<\n TFn extends AnyAsyncFunction,\n TArgs extends Parameters<TFn>,\n> extends Omit<\n AsyncDebouncer<TFn, TArgs>,\n 'getExecutionCount' | 'getIsPending'\n > {\n executionCount: Accessor<number>\n isPending: Accessor<boolean>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncDebouncer` instance to delay execution of an async function.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a debouncer instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Async debouncing ensures that an async function only executes after a specified delay has passed since its last invocation.\n * This is useful for handling fast-changing inputs like search fields, form validation, or any scenario where you want to\n * wait for user input to settle before making expensive async calls.\n *\n * @example\n * ```tsx\n * // Basic API call debouncing\n * const { maybeExecute } = createAsyncDebouncer(\n * async (query: string) => {\n * const results = await api.search(query);\n * return results;\n * },\n * { wait: 500 }\n * );\n *\n * // With state management\n * const [results, setResults] = createSignal([]);\n * const { maybeExecute } = createAsyncDebouncer(\n * async (searchTerm) => {\n * const data = await searchAPI(searchTerm);\n * setResults(data);\n * },\n * {\n * wait: 300,\n * }\n * );\n * ```\n */\n\nexport function createAsyncDebouncer<\n TFn extends AnyAsyncFunction,\n TArgs extends Parameters<TFn>,\n>(\n fn: TFn,\n initialOptions: AsyncDebouncerOptions<TFn, TArgs>,\n): SolidAsyncDebouncer<TFn, TArgs> {\n const asyncDebouncer = new AsyncDebouncer<TFn, TArgs>(fn, initialOptions)\n\n const [executionCount, setExecutionCount] = createSignal(\n asyncDebouncer.getExecutionCount(),\n )\n const [isPending, setIsPending] = createSignal(asyncDebouncer.getIsPending())\n\n function setOptions(newOptions: Partial<AsyncDebouncerOptions<TFn, TArgs>>) {\n asyncDebouncer.setOptions({\n ...newOptions,\n onExecute: (asyncDebouncer) => {\n setExecutionCount(asyncDebouncer.getExecutionCount())\n setIsPending(asyncDebouncer.getIsPending())\n\n const onExecute = newOptions.onExecute ?? initialOptions.onExecute\n onExecute?.(asyncDebouncer)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...bindInstanceMethods(asyncDebouncer),\n executionCount,\n isPending,\n setOptions,\n }\n}\n"],"names":["asyncDebouncer"],"mappings":";;;AAqDgB,SAAA,qBAId,IACA,gBACiC;AACjC,QAAM,iBAAiB,IAAI,eAA2B,IAAI,cAAc;AAElE,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,eAAe,kBAAkB;AAAA,EACnC;AACA,QAAM,CAAC,WAAW,YAAY,IAAI,aAAa,eAAe,cAAc;AAE5E,WAAS,WAAW,YAAwD;AAC1E,mBAAe,WAAW;AAAA,MACxB,GAAG;AAAA,MACH,WAAW,CAACA,oBAAmB;AACXA,0BAAAA,gBAAe,mBAAmB;AACvCA,qBAAAA,gBAAe,cAAc;AAEpC,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MAAc;AAAA,IAC5B,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAG,oBAAoB,cAAc;AAAA,IACrC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"createAsyncDebouncer.js","sources":["../../../src/async-debouncer/createAsyncDebouncer.ts"],"sourcesContent":["import { AsyncDebouncer } from '@tanstack/pacer/async-debouncer'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { AsyncDebouncerOptions } from '@tanstack/pacer/async-debouncer'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type { Accessor } from 'solid-js'\n\nexport interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction>\n extends Omit<\n AsyncDebouncer<TFn>,\n | 'getErrorCount'\n | 'getIsPending'\n | 'getLastResult'\n | 'getSettleCount'\n | 'getSuccessCount'\n > {\n errorCount: Accessor<number>\n isPending: Accessor<boolean>\n lastResult: Accessor<ReturnType<TFn> | undefined>\n settleCount: Accessor<number>\n successCount: Accessor<number>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncDebouncer` instance to delay execution of an async function.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a debouncer instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Async debouncing ensures that an async function only executes after a specified delay has passed since its last invocation.\n * This is useful for handling fast-changing inputs like search fields, form validation, or any scenario where you want to\n * wait for user input to settle before making expensive async calls.\n *\n * @example\n * ```tsx\n * // Basic API call debouncing\n * const { maybeExecute } = createAsyncDebouncer(\n * async (query: string) => {\n * const results = await api.search(query);\n * return results;\n * },\n * { wait: 500 }\n * );\n *\n * // With state management\n * const [results, setResults] = createSignal([]);\n * const { maybeExecute } = createAsyncDebouncer(\n * async (searchTerm) => {\n * const data = await searchAPI(searchTerm);\n * setResults(data);\n * },\n * {\n * wait: 300,\n * }\n * );\n * ```\n */\n\nexport function createAsyncDebouncer<TFn extends AnyAsyncFunction>(\n fn: TFn,\n initialOptions: AsyncDebouncerOptions<TFn>,\n): SolidAsyncDebouncer<TFn> {\n const asyncDebouncer = new AsyncDebouncer<TFn>(fn, initialOptions)\n\n const [errorCount, setErrorCount] = createSignal(\n asyncDebouncer.getErrorCount(),\n )\n const [settleCount, setSettleCount] = createSignal(\n asyncDebouncer.getSettleCount(),\n )\n const [successCount, setSuccessCount] = createSignal(\n asyncDebouncer.getSuccessCount(),\n )\n const [isPending, setIsPending] = createSignal(asyncDebouncer.getIsPending())\n const [lastResult, setLastResult] = createSignal(\n asyncDebouncer.getLastResult(),\n )\n\n function setOptions(newOptions: Partial<AsyncDebouncerOptions<TFn>>) {\n asyncDebouncer.setOptions({\n ...newOptions,\n onSettled: (asyncDebouncer) => {\n setSuccessCount(asyncDebouncer.getSuccessCount())\n setErrorCount(asyncDebouncer.getErrorCount())\n setSettleCount(asyncDebouncer.getSettleCount())\n setIsPending(asyncDebouncer.getIsPending())\n setLastResult(asyncDebouncer.getLastResult())\n const onSettled = newOptions.onSettled ?? initialOptions.onSettled\n onSettled?.(asyncDebouncer)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...bindInstanceMethods(asyncDebouncer),\n errorCount,\n isPending,\n lastResult,\n settleCount,\n successCount,\n setOptions,\n } as SolidAsyncDebouncer<TFn>\n}\n"],"names":["asyncDebouncer"],"mappings":";;;AA0DgB,SAAA,qBACd,IACA,gBAC0B;AAC1B,QAAM,iBAAiB,IAAI,eAAoB,IAAI,cAAc;AAE3D,QAAA,CAAC,YAAY,aAAa,IAAI;AAAA,IAClC,eAAe,cAAc;AAAA,EAC/B;AACM,QAAA,CAAC,aAAa,cAAc,IAAI;AAAA,IACpC,eAAe,eAAe;AAAA,EAChC;AACM,QAAA,CAAC,cAAc,eAAe,IAAI;AAAA,IACtC,eAAe,gBAAgB;AAAA,EACjC;AACA,QAAM,CAAC,WAAW,YAAY,IAAI,aAAa,eAAe,cAAc;AACtE,QAAA,CAAC,YAAY,aAAa,IAAI;AAAA,IAClC,eAAe,cAAc;AAAA,EAC/B;AAEA,WAAS,WAAW,YAAiD;AACnE,mBAAe,WAAW;AAAA,MACxB,GAAG;AAAA,MACH,WAAW,CAACA,oBAAmB;AACbA,wBAAAA,gBAAe,iBAAiB;AAClCA,sBAAAA,gBAAe,eAAe;AAC7BA,uBAAAA,gBAAe,gBAAgB;AACjCA,qBAAAA,gBAAe,cAAc;AAC5BA,sBAAAA,gBAAe,eAAe;AACtC,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MAAc;AAAA,IAC5B,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAG,oBAAoB,cAAc;AAAA,IACrC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
@@ -32,11 +32,15 @@ export interface SolidAsyncQueuer<TValue> extends Omit<AsyncQueuer<TValue>, 'get
32
32
  /**
33
33
  * Signal version of `getPeek`
34
34
  */
35
- peek: Accessor<TValue | undefined>;
35
+ peek: Accessor<(() => Promise<TValue>) | undefined>;
36
36
  /**
37
37
  * Signal version of `getPendingItems`
38
38
  */
39
39
  pendingItems: Accessor<Array<() => Promise<TValue>>>;
40
+ /**
41
+ * Signal version of `getRejectionCount`
42
+ */
43
+ rejectionCount: Accessor<number>;
40
44
  /**
41
45
  * Signal version of `getSize`
42
46
  */