@tanstack/angular-pacer 0.20.0 → 0.22.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 (120) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -7
  3. package/dist/async-batcher/index.d.cts +2 -2
  4. package/dist/async-batcher/index.d.ts +2 -2
  5. package/dist/async-batcher/injectAsyncBatcher.cjs +27 -3
  6. package/dist/async-batcher/injectAsyncBatcher.cjs.map +1 -1
  7. package/dist/async-batcher/injectAsyncBatcher.d.cts +25 -3
  8. package/dist/async-batcher/injectAsyncBatcher.d.ts +25 -3
  9. package/dist/async-batcher/injectAsyncBatcher.js +27 -3
  10. package/dist/async-batcher/injectAsyncBatcher.js.map +1 -1
  11. package/dist/async-debouncer/index.d.cts +2 -2
  12. package/dist/async-debouncer/index.d.ts +2 -2
  13. package/dist/async-debouncer/injectAsyncDebouncer.cjs +27 -3
  14. package/dist/async-debouncer/injectAsyncDebouncer.cjs.map +1 -1
  15. package/dist/async-debouncer/injectAsyncDebouncer.d.cts +25 -3
  16. package/dist/async-debouncer/injectAsyncDebouncer.d.ts +25 -3
  17. package/dist/async-debouncer/injectAsyncDebouncer.js +27 -3
  18. package/dist/async-debouncer/injectAsyncDebouncer.js.map +1 -1
  19. package/dist/async-queuer/index.d.cts +2 -2
  20. package/dist/async-queuer/index.d.ts +2 -2
  21. package/dist/async-queuer/injectAsyncQueuedSignal.cjs.map +1 -1
  22. package/dist/async-queuer/injectAsyncQueuedSignal.d.cts +5 -10
  23. package/dist/async-queuer/injectAsyncQueuedSignal.d.ts +5 -10
  24. package/dist/async-queuer/injectAsyncQueuedSignal.js.map +1 -1
  25. package/dist/async-queuer/injectAsyncQueuer.cjs +27 -3
  26. package/dist/async-queuer/injectAsyncQueuer.cjs.map +1 -1
  27. package/dist/async-queuer/injectAsyncQueuer.d.cts +25 -3
  28. package/dist/async-queuer/injectAsyncQueuer.d.ts +25 -3
  29. package/dist/async-queuer/injectAsyncQueuer.js +27 -3
  30. package/dist/async-queuer/injectAsyncQueuer.js.map +1 -1
  31. package/dist/async-rate-limiter/index.d.cts +2 -2
  32. package/dist/async-rate-limiter/index.d.ts +2 -2
  33. package/dist/async-rate-limiter/injectAsyncRateLimiter.cjs +15 -3
  34. package/dist/async-rate-limiter/injectAsyncRateLimiter.cjs.map +1 -1
  35. package/dist/async-rate-limiter/injectAsyncRateLimiter.d.cts +15 -3
  36. package/dist/async-rate-limiter/injectAsyncRateLimiter.d.ts +15 -3
  37. package/dist/async-rate-limiter/injectAsyncRateLimiter.js +15 -3
  38. package/dist/async-rate-limiter/injectAsyncRateLimiter.js.map +1 -1
  39. package/dist/async-throttler/index.d.cts +2 -2
  40. package/dist/async-throttler/index.d.ts +2 -2
  41. package/dist/async-throttler/injectAsyncThrottler.cjs +27 -3
  42. package/dist/async-throttler/injectAsyncThrottler.cjs.map +1 -1
  43. package/dist/async-throttler/injectAsyncThrottler.d.cts +25 -3
  44. package/dist/async-throttler/injectAsyncThrottler.d.ts +25 -3
  45. package/dist/async-throttler/injectAsyncThrottler.js +27 -3
  46. package/dist/async-throttler/injectAsyncThrottler.js.map +1 -1
  47. package/dist/batcher/index.d.cts +2 -2
  48. package/dist/batcher/index.d.ts +2 -2
  49. package/dist/batcher/injectBatcher.cjs +22 -3
  50. package/dist/batcher/injectBatcher.cjs.map +1 -1
  51. package/dist/batcher/injectBatcher.d.cts +22 -3
  52. package/dist/batcher/injectBatcher.d.ts +22 -3
  53. package/dist/batcher/injectBatcher.js +22 -3
  54. package/dist/batcher/injectBatcher.js.map +1 -1
  55. package/dist/debouncer/index.d.cts +2 -2
  56. package/dist/debouncer/index.d.ts +2 -2
  57. package/dist/debouncer/injectDebouncedSignal.cjs.map +1 -1
  58. package/dist/debouncer/injectDebouncedSignal.d.cts +5 -10
  59. package/dist/debouncer/injectDebouncedSignal.d.ts +5 -10
  60. package/dist/debouncer/injectDebouncedSignal.js.map +1 -1
  61. package/dist/debouncer/injectDebouncer.cjs +22 -3
  62. package/dist/debouncer/injectDebouncer.cjs.map +1 -1
  63. package/dist/debouncer/injectDebouncer.d.cts +22 -3
  64. package/dist/debouncer/injectDebouncer.d.ts +22 -3
  65. package/dist/debouncer/injectDebouncer.js +22 -3
  66. package/dist/debouncer/injectDebouncer.js.map +1 -1
  67. package/dist/index.d.cts +11 -11
  68. package/dist/index.d.ts +11 -11
  69. package/dist/queuer/index.d.cts +2 -2
  70. package/dist/queuer/index.d.ts +2 -2
  71. package/dist/queuer/injectQueuedSignal.cjs.map +1 -1
  72. package/dist/queuer/injectQueuedSignal.d.cts +5 -10
  73. package/dist/queuer/injectQueuedSignal.d.ts +5 -10
  74. package/dist/queuer/injectQueuedSignal.js.map +1 -1
  75. package/dist/queuer/injectQueuer.cjs +22 -3
  76. package/dist/queuer/injectQueuer.cjs.map +1 -1
  77. package/dist/queuer/injectQueuer.d.cts +22 -3
  78. package/dist/queuer/injectQueuer.d.ts +22 -3
  79. package/dist/queuer/injectQueuer.js +22 -3
  80. package/dist/queuer/injectQueuer.js.map +1 -1
  81. package/dist/rate-limiter/index.d.cts +2 -2
  82. package/dist/rate-limiter/index.d.ts +2 -2
  83. package/dist/rate-limiter/injectRateLimitedSignal.cjs.map +1 -1
  84. package/dist/rate-limiter/injectRateLimitedSignal.d.cts +5 -10
  85. package/dist/rate-limiter/injectRateLimitedSignal.d.ts +5 -10
  86. package/dist/rate-limiter/injectRateLimitedSignal.js.map +1 -1
  87. package/dist/rate-limiter/injectRateLimiter.cjs +13 -3
  88. package/dist/rate-limiter/injectRateLimiter.cjs.map +1 -1
  89. package/dist/rate-limiter/injectRateLimiter.d.cts +13 -3
  90. package/dist/rate-limiter/injectRateLimiter.d.ts +13 -3
  91. package/dist/rate-limiter/injectRateLimiter.js +13 -3
  92. package/dist/rate-limiter/injectRateLimiter.js.map +1 -1
  93. package/dist/throttler/index.d.cts +2 -2
  94. package/dist/throttler/index.d.ts +2 -2
  95. package/dist/throttler/injectThrottledSignal.cjs.map +1 -1
  96. package/dist/throttler/injectThrottledSignal.d.cts +5 -10
  97. package/dist/throttler/injectThrottledSignal.d.ts +5 -10
  98. package/dist/throttler/injectThrottledSignal.js.map +1 -1
  99. package/dist/throttler/injectThrottler.cjs +22 -3
  100. package/dist/throttler/injectThrottler.cjs.map +1 -1
  101. package/dist/throttler/injectThrottler.d.cts +22 -3
  102. package/dist/throttler/injectThrottler.d.ts +22 -3
  103. package/dist/throttler/injectThrottler.js +22 -3
  104. package/dist/throttler/injectThrottler.js.map +1 -1
  105. package/package.json +15 -15
  106. package/src/async-batcher/injectAsyncBatcher.ts +43 -4
  107. package/src/async-debouncer/injectAsyncDebouncer.ts +43 -4
  108. package/src/async-queuer/injectAsyncQueuedSignal.ts +4 -12
  109. package/src/async-queuer/injectAsyncQueuer.ts +43 -4
  110. package/src/async-rate-limiter/injectAsyncRateLimiter.ts +32 -4
  111. package/src/async-throttler/injectAsyncThrottler.ts +43 -4
  112. package/src/batcher/injectBatcher.ts +39 -4
  113. package/src/debouncer/injectDebouncedSignal.ts +4 -11
  114. package/src/debouncer/injectDebouncer.ts +39 -4
  115. package/src/queuer/injectQueuedSignal.ts +4 -9
  116. package/src/queuer/injectQueuer.ts +39 -4
  117. package/src/rate-limiter/injectRateLimitedSignal.ts +4 -11
  118. package/src/rate-limiter/injectRateLimiter.ts +28 -4
  119. package/src/throttler/injectThrottledSignal.ts +4 -11
  120. package/src/throttler/injectThrottler.ts +39 -4
@@ -1,4 +1,4 @@
1
- import { AngularAsyncQueuer, injectAsyncQueuer } from "./injectAsyncQueuer.js";
1
+ import { AngularAsyncQueuer, AngularAsyncQueuerOptions, injectAsyncQueuer } from "./injectAsyncQueuer.js";
2
2
  import { AsyncQueuedSignal, injectAsyncQueuedSignal } from "./injectAsyncQueuedSignal.js";
3
3
  export * from "@tanstack/pacer/async-queuer";
4
- export { AngularAsyncQueuer, AsyncQueuedSignal, injectAsyncQueuedSignal, injectAsyncQueuer };
4
+ export { AngularAsyncQueuer, AngularAsyncQueuerOptions, AsyncQueuedSignal, injectAsyncQueuedSignal, injectAsyncQueuer };
@@ -1 +1 @@
1
- {"version":3,"file":"injectAsyncQueuedSignal.cjs","names":["injectAsyncQueuer"],"sources":["../../src/async-queuer/injectAsyncQueuedSignal.ts"],"sourcesContent":["import { computed } from '@angular/core'\nimport { injectAsyncQueuer } from './injectAsyncQueuer'\nimport type { AngularAsyncQueuer } from './injectAsyncQueuer'\nimport type {\n AsyncQueuerOptions,\n AsyncQueuerState,\n} from '@tanstack/pacer/async-queuer'\n\nexport type AsyncQueuedSignal<\n TValue,\n TSelected = {},\n> = (() => Array<TValue>) & {\n /**\n * Add an item to the queue.\n */\n readonly addItem: AngularAsyncQueuer<TValue, TSelected>['addItem']\n /**\n * The queuer instance with additional control methods and state signals.\n */\n readonly queuer: AngularAsyncQueuer<TValue, TSelected>\n}\n\n/**\n * An Angular function that creates an async queuer with managed state, combining Angular's signals with async queuing functionality.\n * This function provides both the current queue state and queue control methods.\n *\n * The queue state is automatically updated whenever items are added, removed, or processed in the queue.\n * All queue operations are reflected in the state array returned by the function.\n *\n * The function returns a callable object:\n * - `queued()`: Get the current queue items as an array\n * - `queued.addItem(...)`: Add an item to the queue\n * - `queued.queue`: The queuer instance with additional control methods\n *\n * @example\n * ```ts\n * // Default behavior - track items\n * const queued = injectAsyncQueuedSignal(\n * async (item) => {\n * const response = await fetch('/api/process', {\n * method: 'POST',\n * body: JSON.stringify(item)\n * });\n * return response.json();\n * },\n * { concurrency: 2, wait: 1000 }\n * );\n *\n * // Add items\n * queued.addItem(data1);\n *\n * // Access items\n * console.log(queued()); // [data1, ...]\n *\n * // Control the queue\n * queued.queuer.start();\n * queued.queuer.stop();\n * ```\n */\nexport function injectAsyncQueuedSignal<\n TValue,\n TSelected extends Pick<AsyncQueuerState<TValue>, 'items'> = Pick<\n AsyncQueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (value: TValue) => Promise<any>,\n options: AsyncQueuerOptions<TValue> = {},\n selector: (state: AsyncQueuerState<TValue>) => TSelected = (state) =>\n ({ items: state.items }) as TSelected,\n): AsyncQueuedSignal<TValue, TSelected> {\n const queuer = injectAsyncQueuer(fn, options, selector)\n\n const items = computed(() => queuer.state().items as Array<TValue>)\n\n const queued = Object.assign(items, {\n addItem: queuer.addItem.bind(queuer),\n queuer,\n }) as AsyncQueuedSignal<TValue, TSelected>\n\n return queued\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,SAAgB,wBAOd,IACA,UAAsC,EAAE,EACxC,YAA4D,WACzD,EAAE,OAAO,MAAM,OAAO,GACa;CACtC,MAAM,SAASA,4CAAkB,IAAI,SAAS,SAAS;CAEvD,MAAM,0CAAuB,OAAO,OAAO,CAAC,MAAuB;AAOnE,QALe,OAAO,OAAO,OAAO;EAClC,SAAS,OAAO,QAAQ,KAAK,OAAO;EACpC;EACD,CAAC"}
1
+ {"version":3,"file":"injectAsyncQueuedSignal.cjs","names":["injectAsyncQueuer"],"sources":["../../src/async-queuer/injectAsyncQueuedSignal.ts"],"sourcesContent":["import { computed } from '@angular/core'\nimport { injectAsyncQueuer } from './injectAsyncQueuer'\nimport type { AngularAsyncQueuer } from './injectAsyncQueuer'\nimport type {\n AsyncQueuerOptions,\n AsyncQueuerState,\n} from '@tanstack/pacer/async-queuer'\n\nexport interface AsyncQueuedSignal<TValue, TSelected = {}> {\n (): Array<TValue>\n addItem: AngularAsyncQueuer<TValue, TSelected>['addItem']\n queuer: AngularAsyncQueuer<TValue, TSelected>\n}\n\n/**\n * An Angular function that creates an async queuer with managed state, combining Angular's signals with async queuing functionality.\n * This function provides both the current queue state and queue control methods.\n *\n * The queue state is automatically updated whenever items are added, removed, or processed in the queue.\n * All queue operations are reflected in the state array returned by the function.\n *\n * The function returns a callable object:\n * - `queued()`: Get the current queue items as an array\n * - `queued.addItem(...)`: Add an item to the queue\n * - `queued.queue`: The queuer instance with additional control methods\n *\n * @example\n * ```ts\n * // Default behavior - track items\n * const queued = injectAsyncQueuedSignal(\n * async (item) => {\n * const response = await fetch('/api/process', {\n * method: 'POST',\n * body: JSON.stringify(item)\n * });\n * return response.json();\n * },\n * { concurrency: 2, wait: 1000 }\n * );\n *\n * // Add items\n * queued.addItem(data1);\n *\n * // Access items\n * console.log(queued()); // [data1, ...]\n *\n * // Control the queue\n * queued.queuer.start();\n * queued.queuer.stop();\n * ```\n */\nexport function injectAsyncQueuedSignal<\n TValue,\n TSelected extends Pick<AsyncQueuerState<TValue>, 'items'> = Pick<\n AsyncQueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (value: TValue) => Promise<any>,\n options: AsyncQueuerOptions<TValue> = {},\n selector: (state: AsyncQueuerState<TValue>) => TSelected = (state) =>\n ({ items: state.items }) as TSelected,\n): AsyncQueuedSignal<TValue, TSelected> {\n const queuer = injectAsyncQueuer(fn, options, selector)\n\n const items = computed(() => queuer.state().items as Array<TValue>)\n\n const queued = Object.assign(items, {\n addItem: queuer.addItem.bind(queuer),\n queuer,\n }) as AsyncQueuedSignal<TValue, TSelected>\n\n return queued\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,SAAgB,wBAOd,IACA,UAAsC,EAAE,EACxC,YAA4D,WACzD,EAAE,OAAO,MAAM,OAAO,GACa;CACtC,MAAM,SAASA,4CAAkB,IAAI,SAAS,SAAS;CAEvD,MAAM,0CAAuB,OAAO,OAAO,CAAC,MAAuB;AAOnE,QALe,OAAO,OAAO,OAAO;EAClC,SAAS,OAAO,QAAQ,KAAK,OAAO;EACpC;EACD,CAAC"}
@@ -2,16 +2,11 @@ import { AngularAsyncQueuer } from "./injectAsyncQueuer.cjs";
2
2
  import { AsyncQueuerOptions, AsyncQueuerState } from "@tanstack/pacer/async-queuer";
3
3
 
4
4
  //#region src/async-queuer/injectAsyncQueuedSignal.d.ts
5
- type AsyncQueuedSignal<TValue, TSelected = {}> = (() => Array<TValue>) & {
6
- /**
7
- * Add an item to the queue.
8
- */
9
- readonly addItem: AngularAsyncQueuer<TValue, TSelected>['addItem'];
10
- /**
11
- * The queuer instance with additional control methods and state signals.
12
- */
13
- readonly queuer: AngularAsyncQueuer<TValue, TSelected>;
14
- };
5
+ interface AsyncQueuedSignal<TValue, TSelected = {}> {
6
+ (): Array<TValue>;
7
+ addItem: AngularAsyncQueuer<TValue, TSelected>['addItem'];
8
+ queuer: AngularAsyncQueuer<TValue, TSelected>;
9
+ }
15
10
  /**
16
11
  * An Angular function that creates an async queuer with managed state, combining Angular's signals with async queuing functionality.
17
12
  * This function provides both the current queue state and queue control methods.
@@ -2,16 +2,11 @@ import { AngularAsyncQueuer } from "./injectAsyncQueuer.js";
2
2
  import { AsyncQueuerOptions, AsyncQueuerState } from "@tanstack/pacer/async-queuer";
3
3
 
4
4
  //#region src/async-queuer/injectAsyncQueuedSignal.d.ts
5
- type AsyncQueuedSignal<TValue, TSelected = {}> = (() => Array<TValue>) & {
6
- /**
7
- * Add an item to the queue.
8
- */
9
- readonly addItem: AngularAsyncQueuer<TValue, TSelected>['addItem'];
10
- /**
11
- * The queuer instance with additional control methods and state signals.
12
- */
13
- readonly queuer: AngularAsyncQueuer<TValue, TSelected>;
14
- };
5
+ interface AsyncQueuedSignal<TValue, TSelected = {}> {
6
+ (): Array<TValue>;
7
+ addItem: AngularAsyncQueuer<TValue, TSelected>['addItem'];
8
+ queuer: AngularAsyncQueuer<TValue, TSelected>;
9
+ }
15
10
  /**
16
11
  * An Angular function that creates an async queuer with managed state, combining Angular's signals with async queuing functionality.
17
12
  * This function provides both the current queue state and queue control methods.
@@ -1 +1 @@
1
- {"version":3,"file":"injectAsyncQueuedSignal.js","names":[],"sources":["../../src/async-queuer/injectAsyncQueuedSignal.ts"],"sourcesContent":["import { computed } from '@angular/core'\nimport { injectAsyncQueuer } from './injectAsyncQueuer'\nimport type { AngularAsyncQueuer } from './injectAsyncQueuer'\nimport type {\n AsyncQueuerOptions,\n AsyncQueuerState,\n} from '@tanstack/pacer/async-queuer'\n\nexport type AsyncQueuedSignal<\n TValue,\n TSelected = {},\n> = (() => Array<TValue>) & {\n /**\n * Add an item to the queue.\n */\n readonly addItem: AngularAsyncQueuer<TValue, TSelected>['addItem']\n /**\n * The queuer instance with additional control methods and state signals.\n */\n readonly queuer: AngularAsyncQueuer<TValue, TSelected>\n}\n\n/**\n * An Angular function that creates an async queuer with managed state, combining Angular's signals with async queuing functionality.\n * This function provides both the current queue state and queue control methods.\n *\n * The queue state is automatically updated whenever items are added, removed, or processed in the queue.\n * All queue operations are reflected in the state array returned by the function.\n *\n * The function returns a callable object:\n * - `queued()`: Get the current queue items as an array\n * - `queued.addItem(...)`: Add an item to the queue\n * - `queued.queue`: The queuer instance with additional control methods\n *\n * @example\n * ```ts\n * // Default behavior - track items\n * const queued = injectAsyncQueuedSignal(\n * async (item) => {\n * const response = await fetch('/api/process', {\n * method: 'POST',\n * body: JSON.stringify(item)\n * });\n * return response.json();\n * },\n * { concurrency: 2, wait: 1000 }\n * );\n *\n * // Add items\n * queued.addItem(data1);\n *\n * // Access items\n * console.log(queued()); // [data1, ...]\n *\n * // Control the queue\n * queued.queuer.start();\n * queued.queuer.stop();\n * ```\n */\nexport function injectAsyncQueuedSignal<\n TValue,\n TSelected extends Pick<AsyncQueuerState<TValue>, 'items'> = Pick<\n AsyncQueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (value: TValue) => Promise<any>,\n options: AsyncQueuerOptions<TValue> = {},\n selector: (state: AsyncQueuerState<TValue>) => TSelected = (state) =>\n ({ items: state.items }) as TSelected,\n): AsyncQueuedSignal<TValue, TSelected> {\n const queuer = injectAsyncQueuer(fn, options, selector)\n\n const items = computed(() => queuer.state().items as Array<TValue>)\n\n const queued = Object.assign(items, {\n addItem: queuer.addItem.bind(queuer),\n queuer,\n }) as AsyncQueuedSignal<TValue, TSelected>\n\n return queued\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,SAAgB,wBAOd,IACA,UAAsC,EAAE,EACxC,YAA4D,WACzD,EAAE,OAAO,MAAM,OAAO,GACa;CACtC,MAAM,SAAS,kBAAkB,IAAI,SAAS,SAAS;CAEvD,MAAM,QAAQ,eAAe,OAAO,OAAO,CAAC,MAAuB;AAOnE,QALe,OAAO,OAAO,OAAO;EAClC,SAAS,OAAO,QAAQ,KAAK,OAAO;EACpC;EACD,CAAC"}
1
+ {"version":3,"file":"injectAsyncQueuedSignal.js","names":[],"sources":["../../src/async-queuer/injectAsyncQueuedSignal.ts"],"sourcesContent":["import { computed } from '@angular/core'\nimport { injectAsyncQueuer } from './injectAsyncQueuer'\nimport type { AngularAsyncQueuer } from './injectAsyncQueuer'\nimport type {\n AsyncQueuerOptions,\n AsyncQueuerState,\n} from '@tanstack/pacer/async-queuer'\n\nexport interface AsyncQueuedSignal<TValue, TSelected = {}> {\n (): Array<TValue>\n addItem: AngularAsyncQueuer<TValue, TSelected>['addItem']\n queuer: AngularAsyncQueuer<TValue, TSelected>\n}\n\n/**\n * An Angular function that creates an async queuer with managed state, combining Angular's signals with async queuing functionality.\n * This function provides both the current queue state and queue control methods.\n *\n * The queue state is automatically updated whenever items are added, removed, or processed in the queue.\n * All queue operations are reflected in the state array returned by the function.\n *\n * The function returns a callable object:\n * - `queued()`: Get the current queue items as an array\n * - `queued.addItem(...)`: Add an item to the queue\n * - `queued.queue`: The queuer instance with additional control methods\n *\n * @example\n * ```ts\n * // Default behavior - track items\n * const queued = injectAsyncQueuedSignal(\n * async (item) => {\n * const response = await fetch('/api/process', {\n * method: 'POST',\n * body: JSON.stringify(item)\n * });\n * return response.json();\n * },\n * { concurrency: 2, wait: 1000 }\n * );\n *\n * // Add items\n * queued.addItem(data1);\n *\n * // Access items\n * console.log(queued()); // [data1, ...]\n *\n * // Control the queue\n * queued.queuer.start();\n * queued.queuer.stop();\n * ```\n */\nexport function injectAsyncQueuedSignal<\n TValue,\n TSelected extends Pick<AsyncQueuerState<TValue>, 'items'> = Pick<\n AsyncQueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (value: TValue) => Promise<any>,\n options: AsyncQueuerOptions<TValue> = {},\n selector: (state: AsyncQueuerState<TValue>) => TSelected = (state) =>\n ({ items: state.items }) as TSelected,\n): AsyncQueuedSignal<TValue, TSelected> {\n const queuer = injectAsyncQueuer(fn, options, selector)\n\n const items = computed(() => queuer.state().items as Array<TValue>)\n\n const queued = Object.assign(items, {\n addItem: queuer.addItem.bind(queuer),\n queuer,\n }) as AsyncQueuedSignal<TValue, TSelected>\n\n return queued\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,SAAgB,wBAOd,IACA,UAAsC,EAAE,EACxC,YAA4D,WACzD,EAAE,OAAO,MAAM,OAAO,GACa;CACtC,MAAM,SAAS,kBAAkB,IAAI,SAAS,SAAS;CAEvD,MAAM,QAAQ,eAAe,OAAO,OAAO,CAAC,MAAuB;AAOnE,QALe,OAAO,OAAO,OAAO;EAClC,SAAS,OAAO,QAAQ,KAAK,OAAO;EACpC;EACD,CAAC"}
@@ -1,4 +1,5 @@
1
1
  const require_pacer_context = require('../provider/pacer-context.cjs');
2
+ let _angular_core = require("@angular/core");
2
3
  let _tanstack_angular_store = require("@tanstack/angular-store");
3
4
  let _tanstack_pacer_async_queuer = require("@tanstack/pacer/async-queuer");
4
5
 
@@ -22,6 +23,20 @@ let _tanstack_pacer_async_queuer = require("@tanstack/pacer/async-queuer");
22
23
  * tracking by providing a selector function. This prevents unnecessary updates and gives you
23
24
  * full control over when your component tracks state changes.
24
25
  *
26
+ * ## Cleanup on Destroy
27
+ *
28
+ * By default, the function stops the queuer and aborts in-flight work when the component is destroyed.
29
+ * Use the `onUnmount` option to customize this. For example, to flush pending items instead:
30
+ *
31
+ * ```ts
32
+ * const queuer = injectAsyncQueuer(fn, {
33
+ * concurrency: 2,
34
+ * onUnmount: (q) => q.flush()
35
+ * });
36
+ * ```
37
+ *
38
+ * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
39
+ *
25
40
  * @example
26
41
  * ```ts
27
42
  * // Default behavior - no reactive state subscriptions
@@ -45,15 +60,24 @@ let _tanstack_pacer_async_queuer = require("@tanstack/pacer/async-queuer");
45
60
  * ```
46
61
  */
47
62
  function injectAsyncQueuer(fn, options = {}, selector = () => ({})) {
48
- const queuer = new _tanstack_pacer_async_queuer.AsyncQueuer(fn, {
63
+ const mergedOptions = {
49
64
  ...require_pacer_context.injectPacerOptions().asyncQueuer,
50
65
  ...options
51
- });
66
+ };
67
+ const queuer = new _tanstack_pacer_async_queuer.AsyncQueuer(fn, mergedOptions);
52
68
  const state = (0, _tanstack_angular_store.injectStore)(queuer.store, selector);
53
- return {
69
+ const result = {
54
70
  ...queuer,
55
71
  state
56
72
  };
73
+ (0, _angular_core.inject)(_angular_core.DestroyRef, { optional: true })?.onDestroy(() => {
74
+ if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
75
+ else {
76
+ queuer.stop();
77
+ queuer.abort();
78
+ }
79
+ });
80
+ return result;
57
81
  }
58
82
 
59
83
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"injectAsyncQueuer.cjs","names":["AsyncQueuer","injectPacerOptions"],"sources":["../../src/async-queuer/injectAsyncQueuer.ts"],"sourcesContent":["import { injectStore } from '@tanstack/angular-store'\nimport { AsyncQueuer } from '@tanstack/pacer/async-queuer'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/store'\nimport type {\n AsyncQueuerOptions,\n AsyncQueuerState,\n} from '@tanstack/pacer/async-queuer'\n\nexport interface AngularAsyncQueuer<TValue, TSelected = {}> extends Omit<\n AsyncQueuer<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the async queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<AsyncQueuerState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncQueuer instance.\n *\n * This is a lower-level function that provides direct access to the AsyncQueuer's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The AsyncQueuer processes items asynchronously with support for concurrent execution,\n * promise-based processing, error handling, retry capabilities, and abort support.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const queuer = injectAsyncQueuer(\n * async (item: Data) => {\n * const response = await fetch('/api/process', {\n * method: 'POST',\n * body: JSON.stringify(item)\n * });\n * return response.json();\n * },\n * { concurrency: 2, wait: 1000 }\n * );\n *\n * // Add items\n * queuer.addItem(data1);\n * queuer.addItem(data2);\n *\n * // Access the selected state\n * const { items, isExecuting } = queuer.state();\n * ```\n */\nexport function injectAsyncQueuer<TValue, TSelected = {}>(\n fn: (value: TValue) => Promise<any>,\n options: AsyncQueuerOptions<TValue> = {},\n selector: (state: AsyncQueuerState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncQueuer,\n ...options,\n } as AsyncQueuerOptions<TValue>\n\n const queuer = new AsyncQueuer<TValue>(fn, mergedOptions)\n const state = injectStore(queuer.store, selector)\n\n return {\n ...queuer,\n state,\n } as AngularAsyncQueuer<TValue, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,kBACd,IACA,UAAsC,EAAE,EACxC,kBACG,EAAE,GACkC;CAMvC,MAAM,SAAS,IAAIA,yCAAoB,IALjB;EACpB,GAAGC,0CAAoB,CAAC;EACxB,GAAG;EACJ,CAEwD;CACzD,MAAM,iDAAoB,OAAO,OAAO,SAAS;AAEjD,QAAO;EACL,GAAG;EACH;EACD"}
1
+ {"version":3,"file":"injectAsyncQueuer.cjs","names":["injectPacerOptions","AsyncQueuer","DestroyRef"],"sources":["../../src/async-queuer/injectAsyncQueuer.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { AsyncQueuer } from '@tanstack/pacer/async-queuer'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type {\n AsyncQueuerOptions,\n AsyncQueuerState,\n} from '@tanstack/pacer/async-queuer'\n\nexport interface AngularAsyncQueuerOptions<\n TValue,\n TSelected = {},\n> extends AsyncQueuerOptions<TValue> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop + abort); use it to call flush(), stop(), add logging, etc.\n * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.\n */\n onUnmount?: (queuer: AngularAsyncQueuer<TValue, TSelected>) => void\n}\n\nexport interface AngularAsyncQueuer<TValue, TSelected = {}> extends Omit<\n AsyncQueuer<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the async queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<AsyncQueuerState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncQueuer instance.\n *\n * This is a lower-level function that provides direct access to the AsyncQueuer's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The AsyncQueuer processes items asynchronously with support for concurrent execution,\n * promise-based processing, error handling, retry capabilities, and abort support.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * ## Cleanup on Destroy\n *\n * By default, the function stops the queuer and aborts in-flight work when the component is destroyed.\n * Use the `onUnmount` option to customize this. For example, to flush pending items instead:\n *\n * ```ts\n * const queuer = injectAsyncQueuer(fn, {\n * concurrency: 2,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n *\n * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const queuer = injectAsyncQueuer(\n * async (item: Data) => {\n * const response = await fetch('/api/process', {\n * method: 'POST',\n * body: JSON.stringify(item)\n * });\n * return response.json();\n * },\n * { concurrency: 2, wait: 1000 }\n * );\n *\n * // Add items\n * queuer.addItem(data1);\n * queuer.addItem(data2);\n *\n * // Access the selected state\n * const { items, isExecuting } = queuer.state();\n * ```\n */\nexport function injectAsyncQueuer<TValue, TSelected = {}>(\n fn: (value: TValue) => Promise<any>,\n options: AngularAsyncQueuerOptions<TValue, TSelected> = {},\n selector: (state: AsyncQueuerState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncQueuer,\n ...options,\n } as AngularAsyncQueuerOptions<TValue, TSelected>\n\n const queuer = new AsyncQueuer<TValue>(fn, mergedOptions)\n const state = injectStore(queuer.store, selector)\n\n const result = {\n ...queuer,\n state,\n } as AngularAsyncQueuer<TValue, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n queuer.stop()\n queuer.abort()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FA,SAAgB,kBACd,IACA,UAAwD,EAAE,EAC1D,kBACG,EAAE,GACkC;CACvC,MAAM,gBAAgB;EACpB,GAAGA,0CAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,SAAS,IAAIC,yCAAoB,IAAI,cAAc;CACzD,MAAM,iDAAoB,OAAO,OAAO,SAAS;CAEjD,MAAM,SAAS;EACb,GAAG;EACH;EACD;AAGD,2BAD0BC,0BAAY,EAAE,UAAU,MAAM,CAAC,EAC7C,gBAAgB;AAC1B,MAAI,cAAc,UAChB,eAAc,UAAU,OAAO;OAC1B;AACL,UAAO,MAAM;AACb,UAAO,OAAO;;GAEhB;AAEF,QAAO"}
@@ -1,8 +1,16 @@
1
1
  import { Signal } from "@angular/core";
2
- import { Store } from "@tanstack/store";
2
+ import { Store } from "@tanstack/angular-store";
3
3
  import { AsyncQueuer, AsyncQueuerOptions, AsyncQueuerState } from "@tanstack/pacer/async-queuer";
4
4
 
5
5
  //#region src/async-queuer/injectAsyncQueuer.d.ts
6
+ interface AngularAsyncQueuerOptions<TValue, TSelected = {}> extends AsyncQueuerOptions<TValue> {
7
+ /**
8
+ * Optional callback invoked when the component is destroyed. Receives the queuer instance.
9
+ * When provided, replaces the default cleanup (stop + abort); use it to call flush(), stop(), add logging, etc.
10
+ * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
11
+ */
12
+ onUnmount?: (queuer: AngularAsyncQueuer<TValue, TSelected>) => void;
13
+ }
6
14
  interface AngularAsyncQueuer<TValue, TSelected = {}> extends Omit<AsyncQueuer<TValue>, 'store'> {
7
15
  /**
8
16
  * Reactive state signal that will be updated when the async queuer state changes
@@ -35,6 +43,20 @@ interface AngularAsyncQueuer<TValue, TSelected = {}> extends Omit<AsyncQueuer<TV
35
43
  * tracking by providing a selector function. This prevents unnecessary updates and gives you
36
44
  * full control over when your component tracks state changes.
37
45
  *
46
+ * ## Cleanup on Destroy
47
+ *
48
+ * By default, the function stops the queuer and aborts in-flight work when the component is destroyed.
49
+ * Use the `onUnmount` option to customize this. For example, to flush pending items instead:
50
+ *
51
+ * ```ts
52
+ * const queuer = injectAsyncQueuer(fn, {
53
+ * concurrency: 2,
54
+ * onUnmount: (q) => q.flush()
55
+ * });
56
+ * ```
57
+ *
58
+ * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
59
+ *
38
60
  * @example
39
61
  * ```ts
40
62
  * // Default behavior - no reactive state subscriptions
@@ -57,7 +79,7 @@ interface AngularAsyncQueuer<TValue, TSelected = {}> extends Omit<AsyncQueuer<TV
57
79
  * const { items, isExecuting } = queuer.state();
58
80
  * ```
59
81
  */
60
- declare function injectAsyncQueuer<TValue, TSelected = {}>(fn: (value: TValue) => Promise<any>, options?: AsyncQueuerOptions<TValue>, selector?: (state: AsyncQueuerState<TValue>) => TSelected): AngularAsyncQueuer<TValue, TSelected>;
82
+ declare function injectAsyncQueuer<TValue, TSelected = {}>(fn: (value: TValue) => Promise<any>, options?: AngularAsyncQueuerOptions<TValue, TSelected>, selector?: (state: AsyncQueuerState<TValue>) => TSelected): AngularAsyncQueuer<TValue, TSelected>;
61
83
  //#endregion
62
- export { AngularAsyncQueuer, injectAsyncQueuer };
84
+ export { AngularAsyncQueuer, AngularAsyncQueuerOptions, injectAsyncQueuer };
63
85
  //# sourceMappingURL=injectAsyncQueuer.d.cts.map
@@ -1,8 +1,16 @@
1
1
  import { Signal } from "@angular/core";
2
+ import { Store } from "@tanstack/angular-store";
2
3
  import { AsyncQueuer, AsyncQueuerOptions, AsyncQueuerState } from "@tanstack/pacer/async-queuer";
3
- import { Store } from "@tanstack/store";
4
4
 
5
5
  //#region src/async-queuer/injectAsyncQueuer.d.ts
6
+ interface AngularAsyncQueuerOptions<TValue, TSelected = {}> extends AsyncQueuerOptions<TValue> {
7
+ /**
8
+ * Optional callback invoked when the component is destroyed. Receives the queuer instance.
9
+ * When provided, replaces the default cleanup (stop + abort); use it to call flush(), stop(), add logging, etc.
10
+ * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
11
+ */
12
+ onUnmount?: (queuer: AngularAsyncQueuer<TValue, TSelected>) => void;
13
+ }
6
14
  interface AngularAsyncQueuer<TValue, TSelected = {}> extends Omit<AsyncQueuer<TValue>, 'store'> {
7
15
  /**
8
16
  * Reactive state signal that will be updated when the async queuer state changes
@@ -35,6 +43,20 @@ interface AngularAsyncQueuer<TValue, TSelected = {}> extends Omit<AsyncQueuer<TV
35
43
  * tracking by providing a selector function. This prevents unnecessary updates and gives you
36
44
  * full control over when your component tracks state changes.
37
45
  *
46
+ * ## Cleanup on Destroy
47
+ *
48
+ * By default, the function stops the queuer and aborts in-flight work when the component is destroyed.
49
+ * Use the `onUnmount` option to customize this. For example, to flush pending items instead:
50
+ *
51
+ * ```ts
52
+ * const queuer = injectAsyncQueuer(fn, {
53
+ * concurrency: 2,
54
+ * onUnmount: (q) => q.flush()
55
+ * });
56
+ * ```
57
+ *
58
+ * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
59
+ *
38
60
  * @example
39
61
  * ```ts
40
62
  * // Default behavior - no reactive state subscriptions
@@ -57,7 +79,7 @@ interface AngularAsyncQueuer<TValue, TSelected = {}> extends Omit<AsyncQueuer<TV
57
79
  * const { items, isExecuting } = queuer.state();
58
80
  * ```
59
81
  */
60
- declare function injectAsyncQueuer<TValue, TSelected = {}>(fn: (value: TValue) => Promise<any>, options?: AsyncQueuerOptions<TValue>, selector?: (state: AsyncQueuerState<TValue>) => TSelected): AngularAsyncQueuer<TValue, TSelected>;
82
+ declare function injectAsyncQueuer<TValue, TSelected = {}>(fn: (value: TValue) => Promise<any>, options?: AngularAsyncQueuerOptions<TValue, TSelected>, selector?: (state: AsyncQueuerState<TValue>) => TSelected): AngularAsyncQueuer<TValue, TSelected>;
61
83
  //#endregion
62
- export { AngularAsyncQueuer, injectAsyncQueuer };
84
+ export { AngularAsyncQueuer, AngularAsyncQueuerOptions, injectAsyncQueuer };
63
85
  //# sourceMappingURL=injectAsyncQueuer.d.ts.map
@@ -1,4 +1,5 @@
1
1
  import { injectPacerOptions } from "../provider/pacer-context.js";
2
+ import { DestroyRef, inject } from "@angular/core";
2
3
  import { injectStore } from "@tanstack/angular-store";
3
4
  import { AsyncQueuer } from "@tanstack/pacer/async-queuer";
4
5
 
@@ -22,6 +23,20 @@ import { AsyncQueuer } from "@tanstack/pacer/async-queuer";
22
23
  * tracking by providing a selector function. This prevents unnecessary updates and gives you
23
24
  * full control over when your component tracks state changes.
24
25
  *
26
+ * ## Cleanup on Destroy
27
+ *
28
+ * By default, the function stops the queuer and aborts in-flight work when the component is destroyed.
29
+ * Use the `onUnmount` option to customize this. For example, to flush pending items instead:
30
+ *
31
+ * ```ts
32
+ * const queuer = injectAsyncQueuer(fn, {
33
+ * concurrency: 2,
34
+ * onUnmount: (q) => q.flush()
35
+ * });
36
+ * ```
37
+ *
38
+ * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
39
+ *
25
40
  * @example
26
41
  * ```ts
27
42
  * // Default behavior - no reactive state subscriptions
@@ -45,15 +60,24 @@ import { AsyncQueuer } from "@tanstack/pacer/async-queuer";
45
60
  * ```
46
61
  */
47
62
  function injectAsyncQueuer(fn, options = {}, selector = () => ({})) {
48
- const queuer = new AsyncQueuer(fn, {
63
+ const mergedOptions = {
49
64
  ...injectPacerOptions().asyncQueuer,
50
65
  ...options
51
- });
66
+ };
67
+ const queuer = new AsyncQueuer(fn, mergedOptions);
52
68
  const state = injectStore(queuer.store, selector);
53
- return {
69
+ const result = {
54
70
  ...queuer,
55
71
  state
56
72
  };
73
+ inject(DestroyRef, { optional: true })?.onDestroy(() => {
74
+ if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
75
+ else {
76
+ queuer.stop();
77
+ queuer.abort();
78
+ }
79
+ });
80
+ return result;
57
81
  }
58
82
 
59
83
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"injectAsyncQueuer.js","names":[],"sources":["../../src/async-queuer/injectAsyncQueuer.ts"],"sourcesContent":["import { injectStore } from '@tanstack/angular-store'\nimport { AsyncQueuer } from '@tanstack/pacer/async-queuer'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/store'\nimport type {\n AsyncQueuerOptions,\n AsyncQueuerState,\n} from '@tanstack/pacer/async-queuer'\n\nexport interface AngularAsyncQueuer<TValue, TSelected = {}> extends Omit<\n AsyncQueuer<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the async queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<AsyncQueuerState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncQueuer instance.\n *\n * This is a lower-level function that provides direct access to the AsyncQueuer's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The AsyncQueuer processes items asynchronously with support for concurrent execution,\n * promise-based processing, error handling, retry capabilities, and abort support.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const queuer = injectAsyncQueuer(\n * async (item: Data) => {\n * const response = await fetch('/api/process', {\n * method: 'POST',\n * body: JSON.stringify(item)\n * });\n * return response.json();\n * },\n * { concurrency: 2, wait: 1000 }\n * );\n *\n * // Add items\n * queuer.addItem(data1);\n * queuer.addItem(data2);\n *\n * // Access the selected state\n * const { items, isExecuting } = queuer.state();\n * ```\n */\nexport function injectAsyncQueuer<TValue, TSelected = {}>(\n fn: (value: TValue) => Promise<any>,\n options: AsyncQueuerOptions<TValue> = {},\n selector: (state: AsyncQueuerState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncQueuer,\n ...options,\n } as AsyncQueuerOptions<TValue>\n\n const queuer = new AsyncQueuer<TValue>(fn, mergedOptions)\n const state = injectStore(queuer.store, selector)\n\n return {\n ...queuer,\n state,\n } as AngularAsyncQueuer<TValue, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,kBACd,IACA,UAAsC,EAAE,EACxC,kBACG,EAAE,GACkC;CAMvC,MAAM,SAAS,IAAI,YAAoB,IALjB;EACpB,GAAG,oBAAoB,CAAC;EACxB,GAAG;EACJ,CAEwD;CACzD,MAAM,QAAQ,YAAY,OAAO,OAAO,SAAS;AAEjD,QAAO;EACL,GAAG;EACH;EACD"}
1
+ {"version":3,"file":"injectAsyncQueuer.js","names":[],"sources":["../../src/async-queuer/injectAsyncQueuer.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { AsyncQueuer } from '@tanstack/pacer/async-queuer'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type {\n AsyncQueuerOptions,\n AsyncQueuerState,\n} from '@tanstack/pacer/async-queuer'\n\nexport interface AngularAsyncQueuerOptions<\n TValue,\n TSelected = {},\n> extends AsyncQueuerOptions<TValue> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop + abort); use it to call flush(), stop(), add logging, etc.\n * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.\n */\n onUnmount?: (queuer: AngularAsyncQueuer<TValue, TSelected>) => void\n}\n\nexport interface AngularAsyncQueuer<TValue, TSelected = {}> extends Omit<\n AsyncQueuer<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the async queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<AsyncQueuerState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncQueuer instance.\n *\n * This is a lower-level function that provides direct access to the AsyncQueuer's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The AsyncQueuer processes items asynchronously with support for concurrent execution,\n * promise-based processing, error handling, retry capabilities, and abort support.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * ## Cleanup on Destroy\n *\n * By default, the function stops the queuer and aborts in-flight work when the component is destroyed.\n * Use the `onUnmount` option to customize this. For example, to flush pending items instead:\n *\n * ```ts\n * const queuer = injectAsyncQueuer(fn, {\n * concurrency: 2,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n *\n * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const queuer = injectAsyncQueuer(\n * async (item: Data) => {\n * const response = await fetch('/api/process', {\n * method: 'POST',\n * body: JSON.stringify(item)\n * });\n * return response.json();\n * },\n * { concurrency: 2, wait: 1000 }\n * );\n *\n * // Add items\n * queuer.addItem(data1);\n * queuer.addItem(data2);\n *\n * // Access the selected state\n * const { items, isExecuting } = queuer.state();\n * ```\n */\nexport function injectAsyncQueuer<TValue, TSelected = {}>(\n fn: (value: TValue) => Promise<any>,\n options: AngularAsyncQueuerOptions<TValue, TSelected> = {},\n selector: (state: AsyncQueuerState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncQueuer,\n ...options,\n } as AngularAsyncQueuerOptions<TValue, TSelected>\n\n const queuer = new AsyncQueuer<TValue>(fn, mergedOptions)\n const state = injectStore(queuer.store, selector)\n\n const result = {\n ...queuer,\n state,\n } as AngularAsyncQueuer<TValue, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n queuer.stop()\n queuer.abort()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FA,SAAgB,kBACd,IACA,UAAwD,EAAE,EAC1D,kBACG,EAAE,GACkC;CACvC,MAAM,gBAAgB;EACpB,GAAG,oBAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,SAAS,IAAI,YAAoB,IAAI,cAAc;CACzD,MAAM,QAAQ,YAAY,OAAO,OAAO,SAAS;CAEjD,MAAM,SAAS;EACb,GAAG;EACH;EACD;AAGD,CADmB,OAAO,YAAY,EAAE,UAAU,MAAM,CAAC,EAC7C,gBAAgB;AAC1B,MAAI,cAAc,UAChB,eAAc,UAAU,OAAO;OAC1B;AACL,UAAO,MAAM;AACb,UAAO,OAAO;;GAEhB;AAEF,QAAO"}
@@ -1,4 +1,4 @@
1
1
  import { injectAsyncRateLimitedCallback } from "./injectAsyncRateLimitedCallback.cjs";
2
- import { AngularAsyncRateLimiter, injectAsyncRateLimiter } from "./injectAsyncRateLimiter.cjs";
2
+ import { AngularAsyncRateLimiter, AngularAsyncRateLimiterOptions, injectAsyncRateLimiter } from "./injectAsyncRateLimiter.cjs";
3
3
  export * from "@tanstack/pacer/async-rate-limiter";
4
- export { AngularAsyncRateLimiter, injectAsyncRateLimitedCallback, injectAsyncRateLimiter };
4
+ export { AngularAsyncRateLimiter, AngularAsyncRateLimiterOptions, injectAsyncRateLimitedCallback, injectAsyncRateLimiter };
@@ -1,4 +1,4 @@
1
1
  import { injectAsyncRateLimitedCallback } from "./injectAsyncRateLimitedCallback.js";
2
- import { AngularAsyncRateLimiter, injectAsyncRateLimiter } from "./injectAsyncRateLimiter.js";
2
+ import { AngularAsyncRateLimiter, AngularAsyncRateLimiterOptions, injectAsyncRateLimiter } from "./injectAsyncRateLimiter.js";
3
3
  export * from "@tanstack/pacer/async-rate-limiter";
4
- export { AngularAsyncRateLimiter, injectAsyncRateLimitedCallback, injectAsyncRateLimiter };
4
+ export { AngularAsyncRateLimiter, AngularAsyncRateLimiterOptions, injectAsyncRateLimitedCallback, injectAsyncRateLimiter };
@@ -1,4 +1,5 @@
1
1
  const require_pacer_context = require('../provider/pacer-context.cjs');
2
+ let _angular_core = require("@angular/core");
2
3
  let _tanstack_angular_store = require("@tanstack/angular-store");
3
4
  let _tanstack_pacer_async_rate_limiter = require("@tanstack/pacer/async-rate-limiter");
4
5
 
@@ -22,6 +23,11 @@ let _tanstack_pacer_async_rate_limiter = require("@tanstack/pacer/async-rate-lim
22
23
  * tracking by providing a selector function. This prevents unnecessary updates and gives you
23
24
  * full control over when your component tracks state changes.
24
25
  *
26
+ * ## Cleanup on Destroy
27
+ *
28
+ * By default, the function aborts in-flight work when the component is destroyed.
29
+ * Use the `onUnmount` option to customize this.
30
+ *
25
31
  * @example
26
32
  * ```ts
27
33
  * // Default behavior - no reactive state subscriptions
@@ -41,15 +47,21 @@ let _tanstack_pacer_async_rate_limiter = require("@tanstack/pacer/async-rate-lim
41
47
  * ```
42
48
  */
43
49
  function injectAsyncRateLimiter(fn, options, selector = () => ({})) {
44
- const rateLimiter = new _tanstack_pacer_async_rate_limiter.AsyncRateLimiter(fn, {
50
+ const mergedOptions = {
45
51
  ...require_pacer_context.injectPacerOptions().asyncRateLimiter,
46
52
  ...options
47
- });
53
+ };
54
+ const rateLimiter = new _tanstack_pacer_async_rate_limiter.AsyncRateLimiter(fn, mergedOptions);
48
55
  const state = (0, _tanstack_angular_store.injectStore)(rateLimiter.store, selector);
49
- return {
56
+ const result = {
50
57
  ...rateLimiter,
51
58
  state
52
59
  };
60
+ (0, _angular_core.inject)(_angular_core.DestroyRef, { optional: true })?.onDestroy(() => {
61
+ if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
62
+ else rateLimiter.abort();
63
+ });
64
+ return result;
53
65
  }
54
66
 
55
67
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"injectAsyncRateLimiter.cjs","names":["AsyncRateLimiter","injectPacerOptions"],"sources":["../../src/async-rate-limiter/injectAsyncRateLimiter.ts"],"sourcesContent":["import { injectStore } from '@tanstack/angular-store'\nimport { AsyncRateLimiter } from '@tanstack/pacer/async-rate-limiter'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/store'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncRateLimiterOptions,\n AsyncRateLimiterState,\n} from '@tanstack/pacer/async-rate-limiter'\n\nexport interface AngularAsyncRateLimiter<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncRateLimiter<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the async rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<AsyncRateLimiterState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncRateLimiter instance.\n *\n * This is a lower-level function that provides direct access to the AsyncRateLimiter's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides async rate limiting functionality with promise support, error handling,\n * retry capabilities, and abort support.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = injectAsyncRateLimiter(\n * async (id: string) => {\n * const response = await fetch(`/api/data/${id}`);\n * return response.json();\n * },\n * { limit: 5, window: 60000, windowType: 'sliding' }\n * );\n *\n * // In an event handler\n * const handleRequest = async (id: string) => {\n * const result = await rateLimiter.maybeExecute(id);\n * console.log('Result:', result);\n * };\n * ```\n */\nexport function injectAsyncRateLimiter<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AsyncRateLimiterOptions<TFn>,\n selector: (state: AsyncRateLimiterState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncRateLimiter,\n ...options,\n } as AsyncRateLimiterOptions<TFn>\n\n const rateLimiter = new AsyncRateLimiter<TFn>(fn, mergedOptions)\n const state = injectStore(rateLimiter.store, selector)\n\n return {\n ...rateLimiter,\n state,\n } as AngularAsyncRateLimiter<TFn, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAgB,uBAId,IACA,SACA,kBACG,EAAE,GACoC;CAMzC,MAAM,cAAc,IAAIA,oDAAsB,IALxB;EACpB,GAAGC,0CAAoB,CAAC;EACxB,GAAG;EACJ,CAE+D;CAChE,MAAM,iDAAoB,YAAY,OAAO,SAAS;AAEtD,QAAO;EACL,GAAG;EACH;EACD"}
1
+ {"version":3,"file":"injectAsyncRateLimiter.cjs","names":["injectPacerOptions","AsyncRateLimiter","DestroyRef"],"sources":["../../src/async-rate-limiter/injectAsyncRateLimiter.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { AsyncRateLimiter } from '@tanstack/pacer/async-rate-limiter'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncRateLimiterOptions,\n AsyncRateLimiterState,\n} from '@tanstack/pacer/async-rate-limiter'\n\nexport interface AngularAsyncRateLimiterOptions<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends AsyncRateLimiterOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the rate limiter instance.\n * When provided, replaces the default cleanup (abort).\n */\n onUnmount?: (rateLimiter: AngularAsyncRateLimiter<TFn, TSelected>) => void\n}\n\nexport interface AngularAsyncRateLimiter<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncRateLimiter<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the async rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<AsyncRateLimiterState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncRateLimiter instance.\n *\n * This is a lower-level function that provides direct access to the AsyncRateLimiter's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides async rate limiting functionality with promise support, error handling,\n * retry capabilities, and abort support.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * ## Cleanup on Destroy\n *\n * By default, the function aborts in-flight work when the component is destroyed.\n * Use the `onUnmount` option to customize this.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = injectAsyncRateLimiter(\n * async (id: string) => {\n * const response = await fetch(`/api/data/${id}`);\n * return response.json();\n * },\n * { limit: 5, window: 60000, windowType: 'sliding' }\n * );\n *\n * // In an event handler\n * const handleRequest = async (id: string) => {\n * const result = await rateLimiter.maybeExecute(id);\n * console.log('Result:', result);\n * };\n * ```\n */\nexport function injectAsyncRateLimiter<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AngularAsyncRateLimiterOptions<TFn, TSelected>,\n selector: (state: AsyncRateLimiterState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncRateLimiter,\n ...options,\n } as AngularAsyncRateLimiterOptions<TFn, TSelected>\n\n const rateLimiter = new AsyncRateLimiter<TFn>(fn, mergedOptions)\n const state = injectStore(rateLimiter.store, selector)\n\n const result = {\n ...rateLimiter,\n state,\n } as AngularAsyncRateLimiter<TFn, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n rateLimiter.abort()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,SAAgB,uBAId,IACA,SACA,kBACG,EAAE,GACoC;CACzC,MAAM,gBAAgB;EACpB,GAAGA,0CAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,cAAc,IAAIC,oDAAsB,IAAI,cAAc;CAChE,MAAM,iDAAoB,YAAY,OAAO,SAAS;CAEtD,MAAM,SAAS;EACb,GAAG;EACH;EACD;AAGD,2BAD0BC,0BAAY,EAAE,UAAU,MAAM,CAAC,EAC7C,gBAAgB;AAC1B,MAAI,cAAc,UAChB,eAAc,UAAU,OAAO;MAE/B,aAAY,OAAO;GAErB;AAEF,QAAO"}
@@ -1,9 +1,16 @@
1
1
  import { Signal } from "@angular/core";
2
- import { Store } from "@tanstack/store";
2
+ import { Store } from "@tanstack/angular-store";
3
3
  import { AnyAsyncFunction } from "@tanstack/pacer/types";
4
4
  import { AsyncRateLimiter, AsyncRateLimiterOptions, AsyncRateLimiterState } from "@tanstack/pacer/async-rate-limiter";
5
5
 
6
6
  //#region src/async-rate-limiter/injectAsyncRateLimiter.d.ts
7
+ interface AngularAsyncRateLimiterOptions<TFn extends AnyAsyncFunction, TSelected = {}> extends AsyncRateLimiterOptions<TFn> {
8
+ /**
9
+ * Optional callback invoked when the component is destroyed. Receives the rate limiter instance.
10
+ * When provided, replaces the default cleanup (abort).
11
+ */
12
+ onUnmount?: (rateLimiter: AngularAsyncRateLimiter<TFn, TSelected>) => void;
13
+ }
7
14
  interface AngularAsyncRateLimiter<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncRateLimiter<TFn>, 'store'> {
8
15
  /**
9
16
  * Reactive state signal that will be updated when the async rate limiter state changes
@@ -36,6 +43,11 @@ interface AngularAsyncRateLimiter<TFn extends AnyAsyncFunction, TSelected = {}>
36
43
  * tracking by providing a selector function. This prevents unnecessary updates and gives you
37
44
  * full control over when your component tracks state changes.
38
45
  *
46
+ * ## Cleanup on Destroy
47
+ *
48
+ * By default, the function aborts in-flight work when the component is destroyed.
49
+ * Use the `onUnmount` option to customize this.
50
+ *
39
51
  * @example
40
52
  * ```ts
41
53
  * // Default behavior - no reactive state subscriptions
@@ -54,7 +66,7 @@ interface AngularAsyncRateLimiter<TFn extends AnyAsyncFunction, TSelected = {}>
54
66
  * };
55
67
  * ```
56
68
  */
57
- declare function injectAsyncRateLimiter<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: AsyncRateLimiterOptions<TFn>, selector?: (state: AsyncRateLimiterState<TFn>) => TSelected): AngularAsyncRateLimiter<TFn, TSelected>;
69
+ declare function injectAsyncRateLimiter<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: AngularAsyncRateLimiterOptions<TFn, TSelected>, selector?: (state: AsyncRateLimiterState<TFn>) => TSelected): AngularAsyncRateLimiter<TFn, TSelected>;
58
70
  //#endregion
59
- export { AngularAsyncRateLimiter, injectAsyncRateLimiter };
71
+ export { AngularAsyncRateLimiter, AngularAsyncRateLimiterOptions, injectAsyncRateLimiter };
60
72
  //# sourceMappingURL=injectAsyncRateLimiter.d.cts.map
@@ -1,9 +1,16 @@
1
1
  import { Signal } from "@angular/core";
2
+ import { Store } from "@tanstack/angular-store";
2
3
  import { AsyncRateLimiter, AsyncRateLimiterOptions, AsyncRateLimiterState } from "@tanstack/pacer/async-rate-limiter";
3
4
  import { AnyAsyncFunction } from "@tanstack/pacer/types";
4
- import { Store } from "@tanstack/store";
5
5
 
6
6
  //#region src/async-rate-limiter/injectAsyncRateLimiter.d.ts
7
+ interface AngularAsyncRateLimiterOptions<TFn extends AnyAsyncFunction, TSelected = {}> extends AsyncRateLimiterOptions<TFn> {
8
+ /**
9
+ * Optional callback invoked when the component is destroyed. Receives the rate limiter instance.
10
+ * When provided, replaces the default cleanup (abort).
11
+ */
12
+ onUnmount?: (rateLimiter: AngularAsyncRateLimiter<TFn, TSelected>) => void;
13
+ }
7
14
  interface AngularAsyncRateLimiter<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncRateLimiter<TFn>, 'store'> {
8
15
  /**
9
16
  * Reactive state signal that will be updated when the async rate limiter state changes
@@ -36,6 +43,11 @@ interface AngularAsyncRateLimiter<TFn extends AnyAsyncFunction, TSelected = {}>
36
43
  * tracking by providing a selector function. This prevents unnecessary updates and gives you
37
44
  * full control over when your component tracks state changes.
38
45
  *
46
+ * ## Cleanup on Destroy
47
+ *
48
+ * By default, the function aborts in-flight work when the component is destroyed.
49
+ * Use the `onUnmount` option to customize this.
50
+ *
39
51
  * @example
40
52
  * ```ts
41
53
  * // Default behavior - no reactive state subscriptions
@@ -54,7 +66,7 @@ interface AngularAsyncRateLimiter<TFn extends AnyAsyncFunction, TSelected = {}>
54
66
  * };
55
67
  * ```
56
68
  */
57
- declare function injectAsyncRateLimiter<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: AsyncRateLimiterOptions<TFn>, selector?: (state: AsyncRateLimiterState<TFn>) => TSelected): AngularAsyncRateLimiter<TFn, TSelected>;
69
+ declare function injectAsyncRateLimiter<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: AngularAsyncRateLimiterOptions<TFn, TSelected>, selector?: (state: AsyncRateLimiterState<TFn>) => TSelected): AngularAsyncRateLimiter<TFn, TSelected>;
58
70
  //#endregion
59
- export { AngularAsyncRateLimiter, injectAsyncRateLimiter };
71
+ export { AngularAsyncRateLimiter, AngularAsyncRateLimiterOptions, injectAsyncRateLimiter };
60
72
  //# sourceMappingURL=injectAsyncRateLimiter.d.ts.map
@@ -1,4 +1,5 @@
1
1
  import { injectPacerOptions } from "../provider/pacer-context.js";
2
+ import { DestroyRef, inject } from "@angular/core";
2
3
  import { injectStore } from "@tanstack/angular-store";
3
4
  import { AsyncRateLimiter } from "@tanstack/pacer/async-rate-limiter";
4
5
 
@@ -22,6 +23,11 @@ import { AsyncRateLimiter } from "@tanstack/pacer/async-rate-limiter";
22
23
  * tracking by providing a selector function. This prevents unnecessary updates and gives you
23
24
  * full control over when your component tracks state changes.
24
25
  *
26
+ * ## Cleanup on Destroy
27
+ *
28
+ * By default, the function aborts in-flight work when the component is destroyed.
29
+ * Use the `onUnmount` option to customize this.
30
+ *
25
31
  * @example
26
32
  * ```ts
27
33
  * // Default behavior - no reactive state subscriptions
@@ -41,15 +47,21 @@ import { AsyncRateLimiter } from "@tanstack/pacer/async-rate-limiter";
41
47
  * ```
42
48
  */
43
49
  function injectAsyncRateLimiter(fn, options, selector = () => ({})) {
44
- const rateLimiter = new AsyncRateLimiter(fn, {
50
+ const mergedOptions = {
45
51
  ...injectPacerOptions().asyncRateLimiter,
46
52
  ...options
47
- });
53
+ };
54
+ const rateLimiter = new AsyncRateLimiter(fn, mergedOptions);
48
55
  const state = injectStore(rateLimiter.store, selector);
49
- return {
56
+ const result = {
50
57
  ...rateLimiter,
51
58
  state
52
59
  };
60
+ inject(DestroyRef, { optional: true })?.onDestroy(() => {
61
+ if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
62
+ else rateLimiter.abort();
63
+ });
64
+ return result;
53
65
  }
54
66
 
55
67
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"injectAsyncRateLimiter.js","names":[],"sources":["../../src/async-rate-limiter/injectAsyncRateLimiter.ts"],"sourcesContent":["import { injectStore } from '@tanstack/angular-store'\nimport { AsyncRateLimiter } from '@tanstack/pacer/async-rate-limiter'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/store'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncRateLimiterOptions,\n AsyncRateLimiterState,\n} from '@tanstack/pacer/async-rate-limiter'\n\nexport interface AngularAsyncRateLimiter<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncRateLimiter<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the async rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<AsyncRateLimiterState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncRateLimiter instance.\n *\n * This is a lower-level function that provides direct access to the AsyncRateLimiter's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides async rate limiting functionality with promise support, error handling,\n * retry capabilities, and abort support.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = injectAsyncRateLimiter(\n * async (id: string) => {\n * const response = await fetch(`/api/data/${id}`);\n * return response.json();\n * },\n * { limit: 5, window: 60000, windowType: 'sliding' }\n * );\n *\n * // In an event handler\n * const handleRequest = async (id: string) => {\n * const result = await rateLimiter.maybeExecute(id);\n * console.log('Result:', result);\n * };\n * ```\n */\nexport function injectAsyncRateLimiter<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AsyncRateLimiterOptions<TFn>,\n selector: (state: AsyncRateLimiterState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncRateLimiter,\n ...options,\n } as AsyncRateLimiterOptions<TFn>\n\n const rateLimiter = new AsyncRateLimiter<TFn>(fn, mergedOptions)\n const state = injectStore(rateLimiter.store, selector)\n\n return {\n ...rateLimiter,\n state,\n } as AngularAsyncRateLimiter<TFn, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAgB,uBAId,IACA,SACA,kBACG,EAAE,GACoC;CAMzC,MAAM,cAAc,IAAI,iBAAsB,IALxB;EACpB,GAAG,oBAAoB,CAAC;EACxB,GAAG;EACJ,CAE+D;CAChE,MAAM,QAAQ,YAAY,YAAY,OAAO,SAAS;AAEtD,QAAO;EACL,GAAG;EACH;EACD"}
1
+ {"version":3,"file":"injectAsyncRateLimiter.js","names":[],"sources":["../../src/async-rate-limiter/injectAsyncRateLimiter.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { AsyncRateLimiter } from '@tanstack/pacer/async-rate-limiter'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncRateLimiterOptions,\n AsyncRateLimiterState,\n} from '@tanstack/pacer/async-rate-limiter'\n\nexport interface AngularAsyncRateLimiterOptions<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends AsyncRateLimiterOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the rate limiter instance.\n * When provided, replaces the default cleanup (abort).\n */\n onUnmount?: (rateLimiter: AngularAsyncRateLimiter<TFn, TSelected>) => void\n}\n\nexport interface AngularAsyncRateLimiter<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncRateLimiter<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the async rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<AsyncRateLimiterState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncRateLimiter instance.\n *\n * This is a lower-level function that provides direct access to the AsyncRateLimiter's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides async rate limiting functionality with promise support, error handling,\n * retry capabilities, and abort support.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * ## Cleanup on Destroy\n *\n * By default, the function aborts in-flight work when the component is destroyed.\n * Use the `onUnmount` option to customize this.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = injectAsyncRateLimiter(\n * async (id: string) => {\n * const response = await fetch(`/api/data/${id}`);\n * return response.json();\n * },\n * { limit: 5, window: 60000, windowType: 'sliding' }\n * );\n *\n * // In an event handler\n * const handleRequest = async (id: string) => {\n * const result = await rateLimiter.maybeExecute(id);\n * console.log('Result:', result);\n * };\n * ```\n */\nexport function injectAsyncRateLimiter<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AngularAsyncRateLimiterOptions<TFn, TSelected>,\n selector: (state: AsyncRateLimiterState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncRateLimiter,\n ...options,\n } as AngularAsyncRateLimiterOptions<TFn, TSelected>\n\n const rateLimiter = new AsyncRateLimiter<TFn>(fn, mergedOptions)\n const state = injectStore(rateLimiter.store, selector)\n\n const result = {\n ...rateLimiter,\n state,\n } as AngularAsyncRateLimiter<TFn, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n rateLimiter.abort()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,SAAgB,uBAId,IACA,SACA,kBACG,EAAE,GACoC;CACzC,MAAM,gBAAgB;EACpB,GAAG,oBAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,cAAc,IAAI,iBAAsB,IAAI,cAAc;CAChE,MAAM,QAAQ,YAAY,YAAY,OAAO,SAAS;CAEtD,MAAM,SAAS;EACb,GAAG;EACH;EACD;AAGD,CADmB,OAAO,YAAY,EAAE,UAAU,MAAM,CAAC,EAC7C,gBAAgB;AAC1B,MAAI,cAAc,UAChB,eAAc,UAAU,OAAO;MAE/B,aAAY,OAAO;GAErB;AAEF,QAAO"}
@@ -1,4 +1,4 @@
1
1
  import { injectAsyncThrottledCallback } from "./injectAsyncThrottledCallback.cjs";
2
- import { AngularAsyncThrottler, injectAsyncThrottler } from "./injectAsyncThrottler.cjs";
2
+ import { AngularAsyncThrottler, AngularAsyncThrottlerOptions, injectAsyncThrottler } from "./injectAsyncThrottler.cjs";
3
3
  export * from "@tanstack/pacer/async-throttler";
4
- export { AngularAsyncThrottler, injectAsyncThrottledCallback, injectAsyncThrottler };
4
+ export { AngularAsyncThrottler, AngularAsyncThrottlerOptions, injectAsyncThrottledCallback, injectAsyncThrottler };
@@ -1,4 +1,4 @@
1
1
  import { injectAsyncThrottledCallback } from "./injectAsyncThrottledCallback.js";
2
- import { AngularAsyncThrottler, injectAsyncThrottler } from "./injectAsyncThrottler.js";
2
+ import { AngularAsyncThrottler, AngularAsyncThrottlerOptions, injectAsyncThrottler } from "./injectAsyncThrottler.js";
3
3
  export * from "@tanstack/pacer/async-throttler";
4
- export { AngularAsyncThrottler, injectAsyncThrottledCallback, injectAsyncThrottler };
4
+ export { AngularAsyncThrottler, AngularAsyncThrottlerOptions, injectAsyncThrottledCallback, injectAsyncThrottler };