@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,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_throttler = require("@tanstack/pacer/async-throttler");
4
5
 
@@ -24,6 +25,20 @@ let _tanstack_pacer_async_throttler = require("@tanstack/pacer/async-throttler")
24
25
  * tracking by providing a selector function. This prevents unnecessary updates and gives you
25
26
  * full control over when your component tracks state changes.
26
27
  *
28
+ * ## Cleanup on Destroy
29
+ *
30
+ * By default, the function cancels any pending execution and aborts in-flight work when the component is destroyed.
31
+ * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
32
+ *
33
+ * ```ts
34
+ * const throttler = injectAsyncThrottler(fn, {
35
+ * wait: 1000,
36
+ * onUnmount: (t) => t.flush()
37
+ * });
38
+ * ```
39
+ *
40
+ * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
41
+ *
27
42
  * @example
28
43
  * ```ts
29
44
  * // Default behavior - no reactive state subscriptions
@@ -46,15 +61,24 @@ let _tanstack_pacer_async_throttler = require("@tanstack/pacer/async-throttler")
46
61
  * ```
47
62
  */
48
63
  function injectAsyncThrottler(fn, options, selector = () => ({})) {
49
- const throttler = new _tanstack_pacer_async_throttler.AsyncThrottler(fn, {
64
+ const mergedOptions = {
50
65
  ...require_pacer_context.injectPacerOptions().asyncThrottler,
51
66
  ...options
52
- });
67
+ };
68
+ const throttler = new _tanstack_pacer_async_throttler.AsyncThrottler(fn, mergedOptions);
53
69
  const state = (0, _tanstack_angular_store.injectStore)(throttler.store, selector);
54
- return {
70
+ const result = {
55
71
  ...throttler,
56
72
  state
57
73
  };
74
+ (0, _angular_core.inject)(_angular_core.DestroyRef, { optional: true })?.onDestroy(() => {
75
+ if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
76
+ else {
77
+ throttler.cancel();
78
+ throttler.abort();
79
+ }
80
+ });
81
+ return result;
58
82
  }
59
83
 
60
84
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"injectAsyncThrottler.cjs","names":["AsyncThrottler","injectPacerOptions"],"sources":["../../src/async-throttler/injectAsyncThrottler.ts"],"sourcesContent":["import { injectStore } from '@tanstack/angular-store'\nimport { AsyncThrottler } from '@tanstack/pacer/async-throttler'\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 AsyncThrottlerOptions,\n AsyncThrottlerState,\n} from '@tanstack/pacer/async-throttler'\n\nexport interface AngularAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncThrottler<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the async throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<AsyncThrottlerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncThrottler instance.\n *\n * This is a lower-level function that provides direct access to the AsyncThrottler's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides async throttling functionality with promise support, error handling,\n * retry capabilities, and abort support.\n *\n * The throttler will execute the function at most once within the specified wait time.\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 throttler = injectAsyncThrottler(\n * async (data: Data) => {\n * const response = await fetch('/api/update', {\n * method: 'POST',\n * body: JSON.stringify(data)\n * });\n * return response.json();\n * },\n * { wait: 1000 }\n * );\n *\n * // In an event handler\n * const handleUpdate = async (data: Data) => {\n * const result = await throttler.maybeExecute(data);\n * console.log('Update result:', result);\n * };\n * ```\n */\nexport function injectAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AsyncThrottlerOptions<TFn>,\n selector: (state: AsyncThrottlerState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncThrottler,\n ...options,\n } as AsyncThrottlerOptions<TFn>\n\n const throttler = new AsyncThrottler<TFn>(fn, mergedOptions)\n const state = injectStore(throttler.store, selector)\n\n return {\n ...throttler,\n state,\n } as AngularAsyncThrottler<TFn, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEA,SAAgB,qBAId,IACA,SACA,kBACG,EAAE,GACkC;CAMvC,MAAM,YAAY,IAAIA,+CAAoB,IALpB;EACpB,GAAGC,0CAAoB,CAAC;EACxB,GAAG;EACJ,CAE2D;CAC5D,MAAM,iDAAoB,UAAU,OAAO,SAAS;AAEpD,QAAO;EACL,GAAG;EACH;EACD"}
1
+ {"version":3,"file":"injectAsyncThrottler.cjs","names":["injectPacerOptions","AsyncThrottler","DestroyRef"],"sources":["../../src/async-throttler/injectAsyncThrottler.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { AsyncThrottler } from '@tanstack/pacer/async-throttler'\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 AsyncThrottlerOptions,\n AsyncThrottlerState,\n} from '@tanstack/pacer/async-throttler'\n\nexport interface AngularAsyncThrottlerOptions<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends AsyncThrottlerOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the throttler instance.\n * When provided, replaces the default cleanup (cancel + abort); use it to call flush(), cancel(), add logging, etc.\n * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.\n */\n onUnmount?: (throttler: AngularAsyncThrottler<TFn, TSelected>) => void\n}\n\nexport interface AngularAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncThrottler<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the async throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<AsyncThrottlerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncThrottler instance.\n *\n * This is a lower-level function that provides direct access to the AsyncThrottler's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides async throttling functionality with promise support, error handling,\n * retry capabilities, and abort support.\n *\n * The throttler will execute the function at most once within the specified wait time.\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 cancels any pending execution and aborts in-flight work when the component is destroyed.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```ts\n * const throttler = injectAsyncThrottler(fn, {\n * wait: 1000,\n * onUnmount: (t) => t.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 throttler = injectAsyncThrottler(\n * async (data: Data) => {\n * const response = await fetch('/api/update', {\n * method: 'POST',\n * body: JSON.stringify(data)\n * });\n * return response.json();\n * },\n * { wait: 1000 }\n * );\n *\n * // In an event handler\n * const handleUpdate = async (data: Data) => {\n * const result = await throttler.maybeExecute(data);\n * console.log('Update result:', result);\n * };\n * ```\n */\nexport function injectAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AngularAsyncThrottlerOptions<TFn, TSelected>,\n selector: (state: AsyncThrottlerState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncThrottler,\n ...options,\n } as AngularAsyncThrottlerOptions<TFn, TSelected>\n\n const throttler = new AsyncThrottler<TFn>(fn, mergedOptions)\n const state = injectStore(throttler.store, selector)\n\n const result = {\n ...throttler,\n state,\n } as AngularAsyncThrottler<TFn, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n throttler.cancel()\n throttler.abort()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiGA,SAAgB,qBAId,IACA,SACA,kBACG,EAAE,GACkC;CACvC,MAAM,gBAAgB;EACpB,GAAGA,0CAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,YAAY,IAAIC,+CAAoB,IAAI,cAAc;CAC5D,MAAM,iDAAoB,UAAU,OAAO,SAAS;CAEpD,MAAM,SAAS;EACb,GAAG;EACH;EACD;AAGD,2BAD0BC,0BAAY,EAAE,UAAU,MAAM,CAAC,EAC7C,gBAAgB;AAC1B,MAAI,cAAc,UAChB,eAAc,UAAU,OAAO;OAC1B;AACL,aAAU,QAAQ;AAClB,aAAU,OAAO;;GAEnB;AAEF,QAAO"}
@@ -1,9 +1,17 @@
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 { AsyncThrottler, AsyncThrottlerOptions, AsyncThrottlerState } from "@tanstack/pacer/async-throttler";
5
5
 
6
6
  //#region src/async-throttler/injectAsyncThrottler.d.ts
7
+ interface AngularAsyncThrottlerOptions<TFn extends AnyAsyncFunction, TSelected = {}> extends AsyncThrottlerOptions<TFn> {
8
+ /**
9
+ * Optional callback invoked when the component is destroyed. Receives the throttler instance.
10
+ * When provided, replaces the default cleanup (cancel + abort); use it to call flush(), cancel(), add logging, etc.
11
+ * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
12
+ */
13
+ onUnmount?: (throttler: AngularAsyncThrottler<TFn, TSelected>) => void;
14
+ }
7
15
  interface AngularAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncThrottler<TFn>, 'store'> {
8
16
  /**
9
17
  * Reactive state signal that will be updated when the async throttler state changes
@@ -38,6 +46,20 @@ interface AngularAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}> ex
38
46
  * tracking by providing a selector function. This prevents unnecessary updates and gives you
39
47
  * full control over when your component tracks state changes.
40
48
  *
49
+ * ## Cleanup on Destroy
50
+ *
51
+ * By default, the function cancels any pending execution and aborts in-flight work when the component is destroyed.
52
+ * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
53
+ *
54
+ * ```ts
55
+ * const throttler = injectAsyncThrottler(fn, {
56
+ * wait: 1000,
57
+ * onUnmount: (t) => t.flush()
58
+ * });
59
+ * ```
60
+ *
61
+ * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
62
+ *
41
63
  * @example
42
64
  * ```ts
43
65
  * // Default behavior - no reactive state subscriptions
@@ -59,7 +81,7 @@ interface AngularAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}> ex
59
81
  * };
60
82
  * ```
61
83
  */
62
- declare function injectAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: AsyncThrottlerOptions<TFn>, selector?: (state: AsyncThrottlerState<TFn>) => TSelected): AngularAsyncThrottler<TFn, TSelected>;
84
+ declare function injectAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: AngularAsyncThrottlerOptions<TFn, TSelected>, selector?: (state: AsyncThrottlerState<TFn>) => TSelected): AngularAsyncThrottler<TFn, TSelected>;
63
85
  //#endregion
64
- export { AngularAsyncThrottler, injectAsyncThrottler };
86
+ export { AngularAsyncThrottler, AngularAsyncThrottlerOptions, injectAsyncThrottler };
65
87
  //# sourceMappingURL=injectAsyncThrottler.d.cts.map
@@ -1,9 +1,17 @@
1
1
  import { Signal } from "@angular/core";
2
+ import { Store } from "@tanstack/angular-store";
2
3
  import { AsyncThrottler, AsyncThrottlerOptions, AsyncThrottlerState } from "@tanstack/pacer/async-throttler";
3
4
  import { AnyAsyncFunction } from "@tanstack/pacer/types";
4
- import { Store } from "@tanstack/store";
5
5
 
6
6
  //#region src/async-throttler/injectAsyncThrottler.d.ts
7
+ interface AngularAsyncThrottlerOptions<TFn extends AnyAsyncFunction, TSelected = {}> extends AsyncThrottlerOptions<TFn> {
8
+ /**
9
+ * Optional callback invoked when the component is destroyed. Receives the throttler instance.
10
+ * When provided, replaces the default cleanup (cancel + abort); use it to call flush(), cancel(), add logging, etc.
11
+ * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
12
+ */
13
+ onUnmount?: (throttler: AngularAsyncThrottler<TFn, TSelected>) => void;
14
+ }
7
15
  interface AngularAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncThrottler<TFn>, 'store'> {
8
16
  /**
9
17
  * Reactive state signal that will be updated when the async throttler state changes
@@ -38,6 +46,20 @@ interface AngularAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}> ex
38
46
  * tracking by providing a selector function. This prevents unnecessary updates and gives you
39
47
  * full control over when your component tracks state changes.
40
48
  *
49
+ * ## Cleanup on Destroy
50
+ *
51
+ * By default, the function cancels any pending execution and aborts in-flight work when the component is destroyed.
52
+ * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
53
+ *
54
+ * ```ts
55
+ * const throttler = injectAsyncThrottler(fn, {
56
+ * wait: 1000,
57
+ * onUnmount: (t) => t.flush()
58
+ * });
59
+ * ```
60
+ *
61
+ * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
62
+ *
41
63
  * @example
42
64
  * ```ts
43
65
  * // Default behavior - no reactive state subscriptions
@@ -59,7 +81,7 @@ interface AngularAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}> ex
59
81
  * };
60
82
  * ```
61
83
  */
62
- declare function injectAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: AsyncThrottlerOptions<TFn>, selector?: (state: AsyncThrottlerState<TFn>) => TSelected): AngularAsyncThrottler<TFn, TSelected>;
84
+ declare function injectAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: AngularAsyncThrottlerOptions<TFn, TSelected>, selector?: (state: AsyncThrottlerState<TFn>) => TSelected): AngularAsyncThrottler<TFn, TSelected>;
63
85
  //#endregion
64
- export { AngularAsyncThrottler, injectAsyncThrottler };
86
+ export { AngularAsyncThrottler, AngularAsyncThrottlerOptions, injectAsyncThrottler };
65
87
  //# sourceMappingURL=injectAsyncThrottler.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 { AsyncThrottler } from "@tanstack/pacer/async-throttler";
4
5
 
@@ -24,6 +25,20 @@ import { AsyncThrottler } from "@tanstack/pacer/async-throttler";
24
25
  * tracking by providing a selector function. This prevents unnecessary updates and gives you
25
26
  * full control over when your component tracks state changes.
26
27
  *
28
+ * ## Cleanup on Destroy
29
+ *
30
+ * By default, the function cancels any pending execution and aborts in-flight work when the component is destroyed.
31
+ * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
32
+ *
33
+ * ```ts
34
+ * const throttler = injectAsyncThrottler(fn, {
35
+ * wait: 1000,
36
+ * onUnmount: (t) => t.flush()
37
+ * });
38
+ * ```
39
+ *
40
+ * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
41
+ *
27
42
  * @example
28
43
  * ```ts
29
44
  * // Default behavior - no reactive state subscriptions
@@ -46,15 +61,24 @@ import { AsyncThrottler } from "@tanstack/pacer/async-throttler";
46
61
  * ```
47
62
  */
48
63
  function injectAsyncThrottler(fn, options, selector = () => ({})) {
49
- const throttler = new AsyncThrottler(fn, {
64
+ const mergedOptions = {
50
65
  ...injectPacerOptions().asyncThrottler,
51
66
  ...options
52
- });
67
+ };
68
+ const throttler = new AsyncThrottler(fn, mergedOptions);
53
69
  const state = injectStore(throttler.store, selector);
54
- return {
70
+ const result = {
55
71
  ...throttler,
56
72
  state
57
73
  };
74
+ inject(DestroyRef, { optional: true })?.onDestroy(() => {
75
+ if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
76
+ else {
77
+ throttler.cancel();
78
+ throttler.abort();
79
+ }
80
+ });
81
+ return result;
58
82
  }
59
83
 
60
84
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"injectAsyncThrottler.js","names":[],"sources":["../../src/async-throttler/injectAsyncThrottler.ts"],"sourcesContent":["import { injectStore } from '@tanstack/angular-store'\nimport { AsyncThrottler } from '@tanstack/pacer/async-throttler'\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 AsyncThrottlerOptions,\n AsyncThrottlerState,\n} from '@tanstack/pacer/async-throttler'\n\nexport interface AngularAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncThrottler<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the async throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<AsyncThrottlerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncThrottler instance.\n *\n * This is a lower-level function that provides direct access to the AsyncThrottler's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides async throttling functionality with promise support, error handling,\n * retry capabilities, and abort support.\n *\n * The throttler will execute the function at most once within the specified wait time.\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 throttler = injectAsyncThrottler(\n * async (data: Data) => {\n * const response = await fetch('/api/update', {\n * method: 'POST',\n * body: JSON.stringify(data)\n * });\n * return response.json();\n * },\n * { wait: 1000 }\n * );\n *\n * // In an event handler\n * const handleUpdate = async (data: Data) => {\n * const result = await throttler.maybeExecute(data);\n * console.log('Update result:', result);\n * };\n * ```\n */\nexport function injectAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AsyncThrottlerOptions<TFn>,\n selector: (state: AsyncThrottlerState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncThrottler,\n ...options,\n } as AsyncThrottlerOptions<TFn>\n\n const throttler = new AsyncThrottler<TFn>(fn, mergedOptions)\n const state = injectStore(throttler.store, selector)\n\n return {\n ...throttler,\n state,\n } as AngularAsyncThrottler<TFn, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEA,SAAgB,qBAId,IACA,SACA,kBACG,EAAE,GACkC;CAMvC,MAAM,YAAY,IAAI,eAAoB,IALpB;EACpB,GAAG,oBAAoB,CAAC;EACxB,GAAG;EACJ,CAE2D;CAC5D,MAAM,QAAQ,YAAY,UAAU,OAAO,SAAS;AAEpD,QAAO;EACL,GAAG;EACH;EACD"}
1
+ {"version":3,"file":"injectAsyncThrottler.js","names":[],"sources":["../../src/async-throttler/injectAsyncThrottler.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { AsyncThrottler } from '@tanstack/pacer/async-throttler'\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 AsyncThrottlerOptions,\n AsyncThrottlerState,\n} from '@tanstack/pacer/async-throttler'\n\nexport interface AngularAsyncThrottlerOptions<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends AsyncThrottlerOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the throttler instance.\n * When provided, replaces the default cleanup (cancel + abort); use it to call flush(), cancel(), add logging, etc.\n * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.\n */\n onUnmount?: (throttler: AngularAsyncThrottler<TFn, TSelected>) => void\n}\n\nexport interface AngularAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncThrottler<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the async throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<AsyncThrottlerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncThrottler instance.\n *\n * This is a lower-level function that provides direct access to the AsyncThrottler's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides async throttling functionality with promise support, error handling,\n * retry capabilities, and abort support.\n *\n * The throttler will execute the function at most once within the specified wait time.\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 cancels any pending execution and aborts in-flight work when the component is destroyed.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```ts\n * const throttler = injectAsyncThrottler(fn, {\n * wait: 1000,\n * onUnmount: (t) => t.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 throttler = injectAsyncThrottler(\n * async (data: Data) => {\n * const response = await fetch('/api/update', {\n * method: 'POST',\n * body: JSON.stringify(data)\n * });\n * return response.json();\n * },\n * { wait: 1000 }\n * );\n *\n * // In an event handler\n * const handleUpdate = async (data: Data) => {\n * const result = await throttler.maybeExecute(data);\n * console.log('Update result:', result);\n * };\n * ```\n */\nexport function injectAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AngularAsyncThrottlerOptions<TFn, TSelected>,\n selector: (state: AsyncThrottlerState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncThrottler,\n ...options,\n } as AngularAsyncThrottlerOptions<TFn, TSelected>\n\n const throttler = new AsyncThrottler<TFn>(fn, mergedOptions)\n const state = injectStore(throttler.store, selector)\n\n const result = {\n ...throttler,\n state,\n } as AngularAsyncThrottler<TFn, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n throttler.cancel()\n throttler.abort()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiGA,SAAgB,qBAId,IACA,SACA,kBACG,EAAE,GACkC;CACvC,MAAM,gBAAgB;EACpB,GAAG,oBAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,YAAY,IAAI,eAAoB,IAAI,cAAc;CAC5D,MAAM,QAAQ,YAAY,UAAU,OAAO,SAAS;CAEpD,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,aAAU,QAAQ;AAClB,aAAU,OAAO;;GAEnB;AAEF,QAAO"}
@@ -1,4 +1,4 @@
1
1
  import { injectBatchedCallback } from "./injectBatchedCallback.cjs";
2
- import { AngularBatcher, injectBatcher } from "./injectBatcher.cjs";
2
+ import { AngularBatcher, AngularBatcherOptions, injectBatcher } from "./injectBatcher.cjs";
3
3
  export * from "@tanstack/pacer/batcher";
4
- export { AngularBatcher, injectBatchedCallback, injectBatcher };
4
+ export { AngularBatcher, AngularBatcherOptions, injectBatchedCallback, injectBatcher };
@@ -1,4 +1,4 @@
1
1
  import { injectBatchedCallback } from "./injectBatchedCallback.js";
2
- import { AngularBatcher, injectBatcher } from "./injectBatcher.js";
2
+ import { AngularBatcher, AngularBatcherOptions, injectBatcher } from "./injectBatcher.js";
3
3
  export * from "@tanstack/pacer/batcher";
4
- export { AngularBatcher, injectBatchedCallback, injectBatcher };
4
+ export { AngularBatcher, AngularBatcherOptions, injectBatchedCallback, injectBatcher };
@@ -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_batcher = require("@tanstack/pacer/batcher");
4
5
 
@@ -24,6 +25,18 @@ let _tanstack_pacer_batcher = require("@tanstack/pacer/batcher");
24
25
  * tracking by providing a selector function. This prevents unnecessary updates and gives you
25
26
  * full control over when your component tracks state changes.
26
27
  *
28
+ * ## Cleanup on Destroy
29
+ *
30
+ * By default, the function cancels any pending batch when the component is destroyed.
31
+ * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
32
+ *
33
+ * ```ts
34
+ * const batcher = injectBatcher(fn, {
35
+ * maxSize: 5,
36
+ * onUnmount: (b) => b.flush()
37
+ * });
38
+ * ```
39
+ *
27
40
  * @example
28
41
  * ```ts
29
42
  * // Default behavior - no reactive state subscriptions
@@ -40,15 +53,21 @@ let _tanstack_pacer_batcher = require("@tanstack/pacer/batcher");
40
53
  * ```
41
54
  */
42
55
  function injectBatcher(fn, options = {}, selector = () => ({})) {
43
- const batcher = new _tanstack_pacer_batcher.Batcher(fn, {
56
+ const mergedOptions = {
44
57
  ...require_pacer_context.injectPacerOptions().batcher,
45
58
  ...options
46
- });
59
+ };
60
+ const batcher = new _tanstack_pacer_batcher.Batcher(fn, mergedOptions);
47
61
  const state = (0, _tanstack_angular_store.injectStore)(batcher.store, selector);
48
- return {
62
+ const result = {
49
63
  ...batcher,
50
64
  state
51
65
  };
66
+ (0, _angular_core.inject)(_angular_core.DestroyRef, { optional: true })?.onDestroy(() => {
67
+ if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
68
+ else batcher.cancel();
69
+ });
70
+ return result;
52
71
  }
53
72
 
54
73
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"injectBatcher.cjs","names":["Batcher","injectPacerOptions"],"sources":["../../src/batcher/injectBatcher.ts"],"sourcesContent":["import { injectStore } from '@tanstack/angular-store'\nimport { Batcher } from '@tanstack/pacer/batcher'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/store'\nimport type { BatcherOptions, BatcherState } from '@tanstack/pacer/batcher'\n\nexport interface AngularBatcher<TValue, TSelected = {}> extends Omit<\n Batcher<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.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<BatcherState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages a Batcher instance.\n *\n * This is a lower-level function that provides direct access to the Batcher's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The Batcher collects items and processes them in batches based on configurable conditions:\n * - Maximum batch size\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\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 batcher = injectBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 }\n * );\n *\n * // Add items\n * batcher.addItem('task1');\n *\n * // Access the selected state\n * const { items, isPending } = batcher.state();\n * ```\n */\nexport function injectBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => void,\n options: BatcherOptions<TValue> = {},\n selector: (state: BatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): AngularBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().batcher,\n ...options,\n } as BatcherOptions<TValue>\n\n const batcher = new Batcher<TValue>(fn, mergedOptions)\n const state = injectStore(batcher.store, selector)\n\n return {\n ...batcher,\n state,\n } as AngularBatcher<TValue, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA,SAAgB,cACd,IACA,UAAkC,EAAE,EACpC,kBACG,EAAE,GAC8B;CAMnC,MAAM,UAAU,IAAIA,gCAAgB,IALd;EACpB,GAAGC,0CAAoB,CAAC;EACxB,GAAG;EACJ,CAEqD;CACtD,MAAM,iDAAoB,QAAQ,OAAO,SAAS;AAElD,QAAO;EACL,GAAG;EACH;EACD"}
1
+ {"version":3,"file":"injectBatcher.cjs","names":["injectPacerOptions","Batcher","DestroyRef"],"sources":["../../src/batcher/injectBatcher.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { Batcher } from '@tanstack/pacer/batcher'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { BatcherOptions, BatcherState } from '@tanstack/pacer/batcher'\n\nexport interface AngularBatcherOptions<\n TValue,\n TSelected = {},\n> extends BatcherOptions<TValue> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the batcher instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), cancel(), add logging, etc.\n */\n onUnmount?: (batcher: AngularBatcher<TValue, TSelected>) => void\n}\n\nexport interface AngularBatcher<TValue, TSelected = {}> extends Omit<\n Batcher<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.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<BatcherState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages a Batcher instance.\n *\n * This is a lower-level function that provides direct access to the Batcher's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The Batcher collects items and processes them in batches based on configurable conditions:\n * - Maximum batch size\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\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 cancels any pending batch when the component is destroyed.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```ts\n * const batcher = injectBatcher(fn, {\n * maxSize: 5,\n * onUnmount: (b) => b.flush()\n * });\n * ```\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const batcher = injectBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 }\n * );\n *\n * // Add items\n * batcher.addItem('task1');\n *\n * // Access the selected state\n * const { items, isPending } = batcher.state();\n * ```\n */\nexport function injectBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => void,\n options: AngularBatcherOptions<TValue, TSelected> = {},\n selector: (state: BatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): AngularBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().batcher,\n ...options,\n } as AngularBatcherOptions<TValue, TSelected>\n\n const batcher = new Batcher<TValue>(fn, mergedOptions)\n const state = injectStore(batcher.store, selector)\n\n const result = {\n ...batcher,\n state,\n } as AngularBatcher<TValue, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n batcher.cancel()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoFA,SAAgB,cACd,IACA,UAAoD,EAAE,EACtD,kBACG,EAAE,GAC8B;CACnC,MAAM,gBAAgB;EACpB,GAAGA,0CAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,UAAU,IAAIC,gCAAgB,IAAI,cAAc;CACtD,MAAM,iDAAoB,QAAQ,OAAO,SAAS;CAElD,MAAM,SAAS;EACb,GAAG;EACH;EACD;AAGD,2BAD0BC,0BAAY,EAAE,UAAU,MAAM,CAAC,EAC7C,gBAAgB;AAC1B,MAAI,cAAc,UAChB,eAAc,UAAU,OAAO;MAE/B,SAAQ,QAAQ;GAElB;AAEF,QAAO"}
@@ -1,8 +1,15 @@
1
1
  import { Signal } from "@angular/core";
2
- import { Store } from "@tanstack/store";
2
+ import { Store } from "@tanstack/angular-store";
3
3
  import { Batcher, BatcherOptions, BatcherState } from "@tanstack/pacer/batcher";
4
4
 
5
5
  //#region src/batcher/injectBatcher.d.ts
6
+ interface AngularBatcherOptions<TValue, TSelected = {}> extends BatcherOptions<TValue> {
7
+ /**
8
+ * Optional callback invoked when the component is destroyed. Receives the batcher instance.
9
+ * When provided, replaces the default cleanup (cancel); use it to call flush(), cancel(), add logging, etc.
10
+ */
11
+ onUnmount?: (batcher: AngularBatcher<TValue, TSelected>) => void;
12
+ }
6
13
  interface AngularBatcher<TValue, TSelected = {}> extends Omit<Batcher<TValue>, 'store'> {
7
14
  /**
8
15
  * Reactive state signal that will be updated when the batcher state changes
@@ -37,6 +44,18 @@ interface AngularBatcher<TValue, TSelected = {}> extends Omit<Batcher<TValue>, '
37
44
  * tracking by providing a selector function. This prevents unnecessary updates and gives you
38
45
  * full control over when your component tracks state changes.
39
46
  *
47
+ * ## Cleanup on Destroy
48
+ *
49
+ * By default, the function cancels any pending batch when the component is destroyed.
50
+ * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
51
+ *
52
+ * ```ts
53
+ * const batcher = injectBatcher(fn, {
54
+ * maxSize: 5,
55
+ * onUnmount: (b) => b.flush()
56
+ * });
57
+ * ```
58
+ *
40
59
  * @example
41
60
  * ```ts
42
61
  * // Default behavior - no reactive state subscriptions
@@ -52,7 +71,7 @@ interface AngularBatcher<TValue, TSelected = {}> extends Omit<Batcher<TValue>, '
52
71
  * const { items, isPending } = batcher.state();
53
72
  * ```
54
73
  */
55
- declare function injectBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => void, options?: BatcherOptions<TValue>, selector?: (state: BatcherState<TValue>) => TSelected): AngularBatcher<TValue, TSelected>;
74
+ declare function injectBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => void, options?: AngularBatcherOptions<TValue, TSelected>, selector?: (state: BatcherState<TValue>) => TSelected): AngularBatcher<TValue, TSelected>;
56
75
  //#endregion
57
- export { AngularBatcher, injectBatcher };
76
+ export { AngularBatcher, AngularBatcherOptions, injectBatcher };
58
77
  //# sourceMappingURL=injectBatcher.d.cts.map
@@ -1,8 +1,15 @@
1
1
  import { Signal } from "@angular/core";
2
+ import { Store } from "@tanstack/angular-store";
2
3
  import { Batcher, BatcherOptions, BatcherState } from "@tanstack/pacer/batcher";
3
- import { Store } from "@tanstack/store";
4
4
 
5
5
  //#region src/batcher/injectBatcher.d.ts
6
+ interface AngularBatcherOptions<TValue, TSelected = {}> extends BatcherOptions<TValue> {
7
+ /**
8
+ * Optional callback invoked when the component is destroyed. Receives the batcher instance.
9
+ * When provided, replaces the default cleanup (cancel); use it to call flush(), cancel(), add logging, etc.
10
+ */
11
+ onUnmount?: (batcher: AngularBatcher<TValue, TSelected>) => void;
12
+ }
6
13
  interface AngularBatcher<TValue, TSelected = {}> extends Omit<Batcher<TValue>, 'store'> {
7
14
  /**
8
15
  * Reactive state signal that will be updated when the batcher state changes
@@ -37,6 +44,18 @@ interface AngularBatcher<TValue, TSelected = {}> extends Omit<Batcher<TValue>, '
37
44
  * tracking by providing a selector function. This prevents unnecessary updates and gives you
38
45
  * full control over when your component tracks state changes.
39
46
  *
47
+ * ## Cleanup on Destroy
48
+ *
49
+ * By default, the function cancels any pending batch when the component is destroyed.
50
+ * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
51
+ *
52
+ * ```ts
53
+ * const batcher = injectBatcher(fn, {
54
+ * maxSize: 5,
55
+ * onUnmount: (b) => b.flush()
56
+ * });
57
+ * ```
58
+ *
40
59
  * @example
41
60
  * ```ts
42
61
  * // Default behavior - no reactive state subscriptions
@@ -52,7 +71,7 @@ interface AngularBatcher<TValue, TSelected = {}> extends Omit<Batcher<TValue>, '
52
71
  * const { items, isPending } = batcher.state();
53
72
  * ```
54
73
  */
55
- declare function injectBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => void, options?: BatcherOptions<TValue>, selector?: (state: BatcherState<TValue>) => TSelected): AngularBatcher<TValue, TSelected>;
74
+ declare function injectBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => void, options?: AngularBatcherOptions<TValue, TSelected>, selector?: (state: BatcherState<TValue>) => TSelected): AngularBatcher<TValue, TSelected>;
56
75
  //#endregion
57
- export { AngularBatcher, injectBatcher };
76
+ export { AngularBatcher, AngularBatcherOptions, injectBatcher };
58
77
  //# sourceMappingURL=injectBatcher.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 { Batcher } from "@tanstack/pacer/batcher";
4
5
 
@@ -24,6 +25,18 @@ import { Batcher } from "@tanstack/pacer/batcher";
24
25
  * tracking by providing a selector function. This prevents unnecessary updates and gives you
25
26
  * full control over when your component tracks state changes.
26
27
  *
28
+ * ## Cleanup on Destroy
29
+ *
30
+ * By default, the function cancels any pending batch when the component is destroyed.
31
+ * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
32
+ *
33
+ * ```ts
34
+ * const batcher = injectBatcher(fn, {
35
+ * maxSize: 5,
36
+ * onUnmount: (b) => b.flush()
37
+ * });
38
+ * ```
39
+ *
27
40
  * @example
28
41
  * ```ts
29
42
  * // Default behavior - no reactive state subscriptions
@@ -40,15 +53,21 @@ import { Batcher } from "@tanstack/pacer/batcher";
40
53
  * ```
41
54
  */
42
55
  function injectBatcher(fn, options = {}, selector = () => ({})) {
43
- const batcher = new Batcher(fn, {
56
+ const mergedOptions = {
44
57
  ...injectPacerOptions().batcher,
45
58
  ...options
46
- });
59
+ };
60
+ const batcher = new Batcher(fn, mergedOptions);
47
61
  const state = injectStore(batcher.store, selector);
48
- return {
62
+ const result = {
49
63
  ...batcher,
50
64
  state
51
65
  };
66
+ inject(DestroyRef, { optional: true })?.onDestroy(() => {
67
+ if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
68
+ else batcher.cancel();
69
+ });
70
+ return result;
52
71
  }
53
72
 
54
73
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"injectBatcher.js","names":[],"sources":["../../src/batcher/injectBatcher.ts"],"sourcesContent":["import { injectStore } from '@tanstack/angular-store'\nimport { Batcher } from '@tanstack/pacer/batcher'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/store'\nimport type { BatcherOptions, BatcherState } from '@tanstack/pacer/batcher'\n\nexport interface AngularBatcher<TValue, TSelected = {}> extends Omit<\n Batcher<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.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<BatcherState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages a Batcher instance.\n *\n * This is a lower-level function that provides direct access to the Batcher's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The Batcher collects items and processes them in batches based on configurable conditions:\n * - Maximum batch size\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\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 batcher = injectBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 }\n * );\n *\n * // Add items\n * batcher.addItem('task1');\n *\n * // Access the selected state\n * const { items, isPending } = batcher.state();\n * ```\n */\nexport function injectBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => void,\n options: BatcherOptions<TValue> = {},\n selector: (state: BatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): AngularBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().batcher,\n ...options,\n } as BatcherOptions<TValue>\n\n const batcher = new Batcher<TValue>(fn, mergedOptions)\n const state = injectStore(batcher.store, selector)\n\n return {\n ...batcher,\n state,\n } as AngularBatcher<TValue, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA,SAAgB,cACd,IACA,UAAkC,EAAE,EACpC,kBACG,EAAE,GAC8B;CAMnC,MAAM,UAAU,IAAI,QAAgB,IALd;EACpB,GAAG,oBAAoB,CAAC;EACxB,GAAG;EACJ,CAEqD;CACtD,MAAM,QAAQ,YAAY,QAAQ,OAAO,SAAS;AAElD,QAAO;EACL,GAAG;EACH;EACD"}
1
+ {"version":3,"file":"injectBatcher.js","names":[],"sources":["../../src/batcher/injectBatcher.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { Batcher } from '@tanstack/pacer/batcher'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { BatcherOptions, BatcherState } from '@tanstack/pacer/batcher'\n\nexport interface AngularBatcherOptions<\n TValue,\n TSelected = {},\n> extends BatcherOptions<TValue> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the batcher instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), cancel(), add logging, etc.\n */\n onUnmount?: (batcher: AngularBatcher<TValue, TSelected>) => void\n}\n\nexport interface AngularBatcher<TValue, TSelected = {}> extends Omit<\n Batcher<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.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<BatcherState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages a Batcher instance.\n *\n * This is a lower-level function that provides direct access to the Batcher's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The Batcher collects items and processes them in batches based on configurable conditions:\n * - Maximum batch size\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\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 cancels any pending batch when the component is destroyed.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```ts\n * const batcher = injectBatcher(fn, {\n * maxSize: 5,\n * onUnmount: (b) => b.flush()\n * });\n * ```\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const batcher = injectBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 }\n * );\n *\n * // Add items\n * batcher.addItem('task1');\n *\n * // Access the selected state\n * const { items, isPending } = batcher.state();\n * ```\n */\nexport function injectBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => void,\n options: AngularBatcherOptions<TValue, TSelected> = {},\n selector: (state: BatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): AngularBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().batcher,\n ...options,\n } as AngularBatcherOptions<TValue, TSelected>\n\n const batcher = new Batcher<TValue>(fn, mergedOptions)\n const state = injectStore(batcher.store, selector)\n\n const result = {\n ...batcher,\n state,\n } as AngularBatcher<TValue, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n batcher.cancel()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoFA,SAAgB,cACd,IACA,UAAoD,EAAE,EACtD,kBACG,EAAE,GAC8B;CACnC,MAAM,gBAAgB;EACpB,GAAG,oBAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,UAAU,IAAI,QAAgB,IAAI,cAAc;CACtD,MAAM,QAAQ,YAAY,QAAQ,OAAO,SAAS;CAElD,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,SAAQ,QAAQ;GAElB;AAEF,QAAO"}
@@ -1,6 +1,6 @@
1
1
  import { injectDebouncedCallback } from "./injectDebouncedCallback.cjs";
2
- import { AngularDebouncer, injectDebouncer } from "./injectDebouncer.cjs";
2
+ import { AngularDebouncer, AngularDebouncerOptions, injectDebouncer } from "./injectDebouncer.cjs";
3
3
  import { DebouncedSignal, injectDebouncedSignal } from "./injectDebouncedSignal.cjs";
4
4
  import { injectDebouncedValue } from "./injectDebouncedValue.cjs";
5
5
  export * from "@tanstack/pacer/debouncer";
6
- export { AngularDebouncer, DebouncedSignal, injectDebouncedCallback, injectDebouncedSignal, injectDebouncedValue, injectDebouncer };
6
+ export { AngularDebouncer, AngularDebouncerOptions, DebouncedSignal, injectDebouncedCallback, injectDebouncedSignal, injectDebouncedValue, injectDebouncer };
@@ -1,6 +1,6 @@
1
1
  import { injectDebouncedCallback } from "./injectDebouncedCallback.js";
2
- import { AngularDebouncer, injectDebouncer } from "./injectDebouncer.js";
2
+ import { AngularDebouncer, AngularDebouncerOptions, injectDebouncer } from "./injectDebouncer.js";
3
3
  import { DebouncedSignal, injectDebouncedSignal } from "./injectDebouncedSignal.js";
4
4
  import { injectDebouncedValue } from "./injectDebouncedValue.js";
5
5
  export * from "@tanstack/pacer/debouncer";
6
- export { AngularDebouncer, DebouncedSignal, injectDebouncedCallback, injectDebouncedSignal, injectDebouncedValue, injectDebouncer };
6
+ export { AngularDebouncer, AngularDebouncerOptions, DebouncedSignal, injectDebouncedCallback, injectDebouncedSignal, injectDebouncedValue, injectDebouncer };
@@ -1 +1 @@
1
- {"version":3,"file":"injectDebouncedSignal.cjs","names":["injectDebouncer"],"sources":["../../src/debouncer/injectDebouncedSignal.ts"],"sourcesContent":["import { signal } from '@angular/core'\nimport { injectDebouncer } from './injectDebouncer'\nimport type { AngularDebouncer } from './injectDebouncer'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\nexport type DebouncedSignal<TValue, TSelected = {}> = ((\n ...args: []\n) => TValue) & {\n /**\n * Set or update the debounced value. This calls `debouncer.maybeExecute(...)`.\n */\n readonly set: Setter<TValue>\n /**\n * The debouncer instance with additional control methods and state signals.\n */\n readonly debouncer: AngularDebouncer<Setter<TValue>, TSelected>\n}\n\n/**\n * An Angular function that creates a debounced state signal, combining Angular's signal with debouncing functionality.\n * This function provides both the current debounced value and methods to update it.\n *\n * The state value is only updated after the specified wait time has elapsed since the last update attempt.\n * If another update is attempted before the wait time expires, the timer resets and starts waiting again.\n * This is useful for handling frequent state updates that should be throttled, like search input values\n * or window resize dimensions.\n *\n * The function returns a callable object:\n * - `debounced()`: Get the current debounced value\n * - `debounced.set(...)`: Set or update the debounced value (debounced via maybeExecute)\n * - `debounced.debouncer`: The debouncer instance with additional control methods and state signals\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * const debouncedQuery = injectDebouncedSignal('', { wait: 500 })\n *\n * // Get value\n * console.log(debouncedQuery())\n *\n * // Set/update value (debounced)\n * debouncedQuery.set('hello')\n *\n * // Access debouncer\n * console.log(debouncedQuery.debouncer.state().isPending)\n * ```\n */\nexport function injectDebouncedSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: DebouncerOptions<Setter<TValue>>,\n selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): DebouncedSignal<TValue, TSelected> {\n const debouncedValue = signal<TValue>(value)\n\n const debouncer = injectDebouncer(\n (newValue: TValue | ((prev: TValue) => TValue)) => {\n if (typeof newValue === 'function') {\n debouncedValue.update(newValue as (prev: TValue) => TValue)\n } else {\n debouncedValue.set(newValue)\n }\n },\n initialOptions,\n selector,\n )\n\n const set: Setter<TValue> = (\n newValue: TValue | ((prev: TValue) => TValue),\n ) => {\n debouncer.maybeExecute(newValue)\n }\n\n const debounced = Object.assign(() => debouncedValue(), {\n set,\n debouncer,\n }) as DebouncedSignal<TValue, TSelected>\n\n return debounced\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqEA,SAAgB,sBACd,OACA,gBACA,UACoC;CACpC,MAAM,2CAAgC,MAAM;CAE5C,MAAM,YAAYA,yCACf,aAAkD;AACjD,MAAI,OAAO,aAAa,WACtB,gBAAe,OAAO,SAAqC;MAE3D,gBAAe,IAAI,SAAS;IAGhC,gBACA,SACD;CAED,MAAM,OACJ,aACG;AACH,YAAU,aAAa,SAAS;;AAQlC,QALkB,OAAO,aAAa,gBAAgB,EAAE;EACtD;EACA;EACD,CAAC"}
1
+ {"version":3,"file":"injectDebouncedSignal.cjs","names":["injectDebouncer"],"sources":["../../src/debouncer/injectDebouncedSignal.ts"],"sourcesContent":["import { signal } from '@angular/core'\nimport { injectDebouncer } from './injectDebouncer'\nimport type { AngularDebouncer } from './injectDebouncer'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\nexport interface DebouncedSignal<TValue, TSelected = {}> {\n (): TValue\n set: Setter<TValue>\n debouncer: AngularDebouncer<Setter<TValue>, TSelected>\n}\n\n/**\n * An Angular function that creates a debounced state signal, combining Angular's signal with debouncing functionality.\n * This function provides both the current debounced value and methods to update it.\n *\n * The state value is only updated after the specified wait time has elapsed since the last update attempt.\n * If another update is attempted before the wait time expires, the timer resets and starts waiting again.\n * This is useful for handling frequent state updates that should be throttled, like search input values\n * or window resize dimensions.\n *\n * The function returns a callable object:\n * - `debounced()`: Get the current debounced value\n * - `debounced.set(...)`: Set or update the debounced value (debounced via maybeExecute)\n * - `debounced.debouncer`: The debouncer instance with additional control methods and state signals\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * const debouncedQuery = injectDebouncedSignal('', { wait: 500 })\n *\n * // Get value\n * console.log(debouncedQuery())\n *\n * // Set/update value (debounced)\n * debouncedQuery.set('hello')\n *\n * // Access debouncer\n * console.log(debouncedQuery.debouncer.state().isPending)\n * ```\n */\nexport function injectDebouncedSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: DebouncerOptions<Setter<TValue>>,\n selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): DebouncedSignal<TValue, TSelected> {\n const debouncedValue = signal<TValue>(value)\n\n const debouncer = injectDebouncer(\n (newValue: TValue | ((prev: TValue) => TValue)) => {\n if (typeof newValue === 'function') {\n debouncedValue.update(newValue as (prev: TValue) => TValue)\n } else {\n debouncedValue.set(newValue)\n }\n },\n initialOptions,\n selector,\n )\n\n const set: Setter<TValue> = (\n newValue: TValue | ((prev: TValue) => TValue),\n ) => {\n debouncer.maybeExecute(newValue)\n }\n\n const debounced = Object.assign(() => debouncedValue(), {\n set,\n debouncer,\n }) as DebouncedSignal<TValue, TSelected>\n\n return debounced\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,SAAgB,sBACd,OACA,gBACA,UACoC;CACpC,MAAM,2CAAgC,MAAM;CAE5C,MAAM,YAAYA,yCACf,aAAkD;AACjD,MAAI,OAAO,aAAa,WACtB,gBAAe,OAAO,SAAqC;MAE3D,gBAAe,IAAI,SAAS;IAGhC,gBACA,SACD;CAED,MAAM,OACJ,aACG;AACH,YAAU,aAAa,SAAS;;AAQlC,QALkB,OAAO,aAAa,gBAAgB,EAAE;EACtD;EACA;EACD,CAAC"}
@@ -3,16 +3,11 @@ import { DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
3
3
 
4
4
  //#region src/debouncer/injectDebouncedSignal.d.ts
5
5
  type Setter<T> = (value: T | ((prev: T) => T)) => void;
6
- type DebouncedSignal<TValue, TSelected = {}> = ((...args: []) => TValue) & {
7
- /**
8
- * Set or update the debounced value. This calls `debouncer.maybeExecute(...)`.
9
- */
10
- readonly set: Setter<TValue>;
11
- /**
12
- * The debouncer instance with additional control methods and state signals.
13
- */
14
- readonly debouncer: AngularDebouncer<Setter<TValue>, TSelected>;
15
- };
6
+ interface DebouncedSignal<TValue, TSelected = {}> {
7
+ (): TValue;
8
+ set: Setter<TValue>;
9
+ debouncer: AngularDebouncer<Setter<TValue>, TSelected>;
10
+ }
16
11
  /**
17
12
  * An Angular function that creates a debounced state signal, combining Angular's signal with debouncing functionality.
18
13
  * This function provides both the current debounced value and methods to update it.
@@ -3,16 +3,11 @@ import { DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
3
3
 
4
4
  //#region src/debouncer/injectDebouncedSignal.d.ts
5
5
  type Setter<T> = (value: T | ((prev: T) => T)) => void;
6
- type DebouncedSignal<TValue, TSelected = {}> = ((...args: []) => TValue) & {
7
- /**
8
- * Set or update the debounced value. This calls `debouncer.maybeExecute(...)`.
9
- */
10
- readonly set: Setter<TValue>;
11
- /**
12
- * The debouncer instance with additional control methods and state signals.
13
- */
14
- readonly debouncer: AngularDebouncer<Setter<TValue>, TSelected>;
15
- };
6
+ interface DebouncedSignal<TValue, TSelected = {}> {
7
+ (): TValue;
8
+ set: Setter<TValue>;
9
+ debouncer: AngularDebouncer<Setter<TValue>, TSelected>;
10
+ }
16
11
  /**
17
12
  * An Angular function that creates a debounced state signal, combining Angular's signal with debouncing functionality.
18
13
  * This function provides both the current debounced value and methods to update it.
@@ -1 +1 @@
1
- {"version":3,"file":"injectDebouncedSignal.js","names":[],"sources":["../../src/debouncer/injectDebouncedSignal.ts"],"sourcesContent":["import { signal } from '@angular/core'\nimport { injectDebouncer } from './injectDebouncer'\nimport type { AngularDebouncer } from './injectDebouncer'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\nexport type DebouncedSignal<TValue, TSelected = {}> = ((\n ...args: []\n) => TValue) & {\n /**\n * Set or update the debounced value. This calls `debouncer.maybeExecute(...)`.\n */\n readonly set: Setter<TValue>\n /**\n * The debouncer instance with additional control methods and state signals.\n */\n readonly debouncer: AngularDebouncer<Setter<TValue>, TSelected>\n}\n\n/**\n * An Angular function that creates a debounced state signal, combining Angular's signal with debouncing functionality.\n * This function provides both the current debounced value and methods to update it.\n *\n * The state value is only updated after the specified wait time has elapsed since the last update attempt.\n * If another update is attempted before the wait time expires, the timer resets and starts waiting again.\n * This is useful for handling frequent state updates that should be throttled, like search input values\n * or window resize dimensions.\n *\n * The function returns a callable object:\n * - `debounced()`: Get the current debounced value\n * - `debounced.set(...)`: Set or update the debounced value (debounced via maybeExecute)\n * - `debounced.debouncer`: The debouncer instance with additional control methods and state signals\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * const debouncedQuery = injectDebouncedSignal('', { wait: 500 })\n *\n * // Get value\n * console.log(debouncedQuery())\n *\n * // Set/update value (debounced)\n * debouncedQuery.set('hello')\n *\n * // Access debouncer\n * console.log(debouncedQuery.debouncer.state().isPending)\n * ```\n */\nexport function injectDebouncedSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: DebouncerOptions<Setter<TValue>>,\n selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): DebouncedSignal<TValue, TSelected> {\n const debouncedValue = signal<TValue>(value)\n\n const debouncer = injectDebouncer(\n (newValue: TValue | ((prev: TValue) => TValue)) => {\n if (typeof newValue === 'function') {\n debouncedValue.update(newValue as (prev: TValue) => TValue)\n } else {\n debouncedValue.set(newValue)\n }\n },\n initialOptions,\n selector,\n )\n\n const set: Setter<TValue> = (\n newValue: TValue | ((prev: TValue) => TValue),\n ) => {\n debouncer.maybeExecute(newValue)\n }\n\n const debounced = Object.assign(() => debouncedValue(), {\n set,\n debouncer,\n }) as DebouncedSignal<TValue, TSelected>\n\n return debounced\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqEA,SAAgB,sBACd,OACA,gBACA,UACoC;CACpC,MAAM,iBAAiB,OAAe,MAAM;CAE5C,MAAM,YAAY,iBACf,aAAkD;AACjD,MAAI,OAAO,aAAa,WACtB,gBAAe,OAAO,SAAqC;MAE3D,gBAAe,IAAI,SAAS;IAGhC,gBACA,SACD;CAED,MAAM,OACJ,aACG;AACH,YAAU,aAAa,SAAS;;AAQlC,QALkB,OAAO,aAAa,gBAAgB,EAAE;EACtD;EACA;EACD,CAAC"}
1
+ {"version":3,"file":"injectDebouncedSignal.js","names":[],"sources":["../../src/debouncer/injectDebouncedSignal.ts"],"sourcesContent":["import { signal } from '@angular/core'\nimport { injectDebouncer } from './injectDebouncer'\nimport type { AngularDebouncer } from './injectDebouncer'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\nexport interface DebouncedSignal<TValue, TSelected = {}> {\n (): TValue\n set: Setter<TValue>\n debouncer: AngularDebouncer<Setter<TValue>, TSelected>\n}\n\n/**\n * An Angular function that creates a debounced state signal, combining Angular's signal with debouncing functionality.\n * This function provides both the current debounced value and methods to update it.\n *\n * The state value is only updated after the specified wait time has elapsed since the last update attempt.\n * If another update is attempted before the wait time expires, the timer resets and starts waiting again.\n * This is useful for handling frequent state updates that should be throttled, like search input values\n * or window resize dimensions.\n *\n * The function returns a callable object:\n * - `debounced()`: Get the current debounced value\n * - `debounced.set(...)`: Set or update the debounced value (debounced via maybeExecute)\n * - `debounced.debouncer`: The debouncer instance with additional control methods and state signals\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * const debouncedQuery = injectDebouncedSignal('', { wait: 500 })\n *\n * // Get value\n * console.log(debouncedQuery())\n *\n * // Set/update value (debounced)\n * debouncedQuery.set('hello')\n *\n * // Access debouncer\n * console.log(debouncedQuery.debouncer.state().isPending)\n * ```\n */\nexport function injectDebouncedSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: DebouncerOptions<Setter<TValue>>,\n selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): DebouncedSignal<TValue, TSelected> {\n const debouncedValue = signal<TValue>(value)\n\n const debouncer = injectDebouncer(\n (newValue: TValue | ((prev: TValue) => TValue)) => {\n if (typeof newValue === 'function') {\n debouncedValue.update(newValue as (prev: TValue) => TValue)\n } else {\n debouncedValue.set(newValue)\n }\n },\n initialOptions,\n selector,\n )\n\n const set: Setter<TValue> = (\n newValue: TValue | ((prev: TValue) => TValue),\n ) => {\n debouncer.maybeExecute(newValue)\n }\n\n const debounced = Object.assign(() => debouncedValue(), {\n set,\n debouncer,\n }) as DebouncedSignal<TValue, TSelected>\n\n return debounced\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,SAAgB,sBACd,OACA,gBACA,UACoC;CACpC,MAAM,iBAAiB,OAAe,MAAM;CAE5C,MAAM,YAAY,iBACf,aAAkD;AACjD,MAAI,OAAO,aAAa,WACtB,gBAAe,OAAO,SAAqC;MAE3D,gBAAe,IAAI,SAAS;IAGhC,gBACA,SACD;CAED,MAAM,OACJ,aACG;AACH,YAAU,aAAa,SAAS;;AAQlC,QALkB,OAAO,aAAa,gBAAgB,EAAE;EACtD;EACA;EACD,CAAC"}