@tanstack/angular-pacer 0.23.0 → 0.24.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 (125) hide show
  1. package/README.md +17 -2
  2. package/dist/async-batcher/injectAsyncBatchedCallback.cjs.map +1 -1
  3. package/dist/async-batcher/injectAsyncBatchedCallback.d.cts +0 -1
  4. package/dist/async-batcher/injectAsyncBatchedCallback.d.ts +0 -1
  5. package/dist/async-batcher/injectAsyncBatchedCallback.js.map +1 -1
  6. package/dist/async-batcher/injectAsyncBatcher.cjs.map +1 -1
  7. package/dist/async-batcher/injectAsyncBatcher.d.cts +0 -1
  8. package/dist/async-batcher/injectAsyncBatcher.d.ts +0 -1
  9. package/dist/async-batcher/injectAsyncBatcher.js.map +1 -1
  10. package/dist/async-debouncer/injectAsyncDebouncedCallback.cjs.map +1 -1
  11. package/dist/async-debouncer/injectAsyncDebouncedCallback.d.cts +0 -1
  12. package/dist/async-debouncer/injectAsyncDebouncedCallback.d.ts +0 -1
  13. package/dist/async-debouncer/injectAsyncDebouncedCallback.js.map +1 -1
  14. package/dist/async-debouncer/injectAsyncDebouncer.cjs.map +1 -1
  15. package/dist/async-debouncer/injectAsyncDebouncer.d.cts +0 -1
  16. package/dist/async-debouncer/injectAsyncDebouncer.d.ts +0 -1
  17. package/dist/async-debouncer/injectAsyncDebouncer.js.map +1 -1
  18. package/dist/async-queuer/injectAsyncQueuedSignal.cjs.map +1 -1
  19. package/dist/async-queuer/injectAsyncQueuedSignal.d.cts +0 -1
  20. package/dist/async-queuer/injectAsyncQueuedSignal.d.ts +0 -1
  21. package/dist/async-queuer/injectAsyncQueuedSignal.js.map +1 -1
  22. package/dist/async-queuer/injectAsyncQueuer.cjs.map +1 -1
  23. package/dist/async-queuer/injectAsyncQueuer.d.cts +0 -1
  24. package/dist/async-queuer/injectAsyncQueuer.d.ts +0 -1
  25. package/dist/async-queuer/injectAsyncQueuer.js.map +1 -1
  26. package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.cjs.map +1 -1
  27. package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.d.cts +0 -1
  28. package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.d.ts +0 -1
  29. package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.js.map +1 -1
  30. package/dist/async-rate-limiter/injectAsyncRateLimiter.cjs.map +1 -1
  31. package/dist/async-rate-limiter/injectAsyncRateLimiter.d.cts +0 -1
  32. package/dist/async-rate-limiter/injectAsyncRateLimiter.d.ts +0 -1
  33. package/dist/async-rate-limiter/injectAsyncRateLimiter.js.map +1 -1
  34. package/dist/async-retryer/index.cjs +0 -1
  35. package/dist/async-throttler/injectAsyncThrottledCallback.cjs.map +1 -1
  36. package/dist/async-throttler/injectAsyncThrottledCallback.d.cts +0 -1
  37. package/dist/async-throttler/injectAsyncThrottledCallback.d.ts +0 -1
  38. package/dist/async-throttler/injectAsyncThrottledCallback.js.map +1 -1
  39. package/dist/async-throttler/injectAsyncThrottler.cjs.map +1 -1
  40. package/dist/async-throttler/injectAsyncThrottler.d.cts +0 -1
  41. package/dist/async-throttler/injectAsyncThrottler.d.ts +0 -1
  42. package/dist/async-throttler/injectAsyncThrottler.js.map +1 -1
  43. package/dist/batcher/injectBatchedCallback.cjs.map +1 -1
  44. package/dist/batcher/injectBatchedCallback.d.cts +0 -1
  45. package/dist/batcher/injectBatchedCallback.d.ts +0 -1
  46. package/dist/batcher/injectBatchedCallback.js.map +1 -1
  47. package/dist/batcher/injectBatcher.cjs.map +1 -1
  48. package/dist/batcher/injectBatcher.d.cts +0 -1
  49. package/dist/batcher/injectBatcher.d.ts +0 -1
  50. package/dist/batcher/injectBatcher.js.map +1 -1
  51. package/dist/debouncer/injectDebouncedCallback.cjs.map +1 -1
  52. package/dist/debouncer/injectDebouncedCallback.d.cts +0 -1
  53. package/dist/debouncer/injectDebouncedCallback.d.ts +0 -1
  54. package/dist/debouncer/injectDebouncedCallback.js.map +1 -1
  55. package/dist/debouncer/injectDebouncedSignal.cjs.map +1 -1
  56. package/dist/debouncer/injectDebouncedSignal.d.cts +0 -1
  57. package/dist/debouncer/injectDebouncedSignal.d.ts +0 -1
  58. package/dist/debouncer/injectDebouncedSignal.js.map +1 -1
  59. package/dist/debouncer/injectDebouncedValue.cjs.map +1 -1
  60. package/dist/debouncer/injectDebouncedValue.d.cts +0 -1
  61. package/dist/debouncer/injectDebouncedValue.d.ts +0 -1
  62. package/dist/debouncer/injectDebouncedValue.js.map +1 -1
  63. package/dist/debouncer/injectDebouncer.cjs.map +1 -1
  64. package/dist/debouncer/injectDebouncer.d.cts +0 -1
  65. package/dist/debouncer/injectDebouncer.d.ts +0 -1
  66. package/dist/debouncer/injectDebouncer.js.map +1 -1
  67. package/dist/provider/pacer-context.cjs.map +1 -1
  68. package/dist/provider/pacer-context.d.cts +0 -1
  69. package/dist/provider/pacer-context.d.ts +0 -1
  70. package/dist/provider/pacer-context.js.map +1 -1
  71. package/dist/provider/pacer-provider.cjs.map +1 -1
  72. package/dist/provider/pacer-provider.d.cts +0 -1
  73. package/dist/provider/pacer-provider.d.ts +0 -1
  74. package/dist/provider/pacer-provider.js.map +1 -1
  75. package/dist/queuer/injectQueuedSignal.cjs.map +1 -1
  76. package/dist/queuer/injectQueuedSignal.d.cts +0 -1
  77. package/dist/queuer/injectQueuedSignal.d.ts +0 -1
  78. package/dist/queuer/injectQueuedSignal.js.map +1 -1
  79. package/dist/queuer/injectQueuedValue.cjs.map +1 -1
  80. package/dist/queuer/injectQueuedValue.d.cts +0 -1
  81. package/dist/queuer/injectQueuedValue.d.ts +0 -1
  82. package/dist/queuer/injectQueuedValue.js.map +1 -1
  83. package/dist/queuer/injectQueuer.cjs.map +1 -1
  84. package/dist/queuer/injectQueuer.d.cts +0 -1
  85. package/dist/queuer/injectQueuer.d.ts +0 -1
  86. package/dist/queuer/injectQueuer.js.map +1 -1
  87. package/dist/rate-limiter/injectRateLimitedCallback.cjs.map +1 -1
  88. package/dist/rate-limiter/injectRateLimitedCallback.d.cts +0 -1
  89. package/dist/rate-limiter/injectRateLimitedCallback.d.ts +0 -1
  90. package/dist/rate-limiter/injectRateLimitedCallback.js.map +1 -1
  91. package/dist/rate-limiter/injectRateLimitedSignal.cjs.map +1 -1
  92. package/dist/rate-limiter/injectRateLimitedSignal.d.cts +0 -1
  93. package/dist/rate-limiter/injectRateLimitedSignal.d.ts +0 -1
  94. package/dist/rate-limiter/injectRateLimitedSignal.js.map +1 -1
  95. package/dist/rate-limiter/injectRateLimitedValue.cjs.map +1 -1
  96. package/dist/rate-limiter/injectRateLimitedValue.d.cts +0 -1
  97. package/dist/rate-limiter/injectRateLimitedValue.d.ts +0 -1
  98. package/dist/rate-limiter/injectRateLimitedValue.js.map +1 -1
  99. package/dist/rate-limiter/injectRateLimiter.cjs.map +1 -1
  100. package/dist/rate-limiter/injectRateLimiter.d.cts +0 -1
  101. package/dist/rate-limiter/injectRateLimiter.d.ts +0 -1
  102. package/dist/rate-limiter/injectRateLimiter.js.map +1 -1
  103. package/dist/throttler/injectThrottledCallback.cjs.map +1 -1
  104. package/dist/throttler/injectThrottledCallback.d.cts +0 -1
  105. package/dist/throttler/injectThrottledCallback.d.ts +0 -1
  106. package/dist/throttler/injectThrottledCallback.js.map +1 -1
  107. package/dist/throttler/injectThrottledSignal.cjs.map +1 -1
  108. package/dist/throttler/injectThrottledSignal.d.cts +0 -1
  109. package/dist/throttler/injectThrottledSignal.d.ts +0 -1
  110. package/dist/throttler/injectThrottledSignal.js.map +1 -1
  111. package/dist/throttler/injectThrottledValue.cjs.map +1 -1
  112. package/dist/throttler/injectThrottledValue.d.cts +0 -1
  113. package/dist/throttler/injectThrottledValue.d.ts +0 -1
  114. package/dist/throttler/injectThrottledValue.js.map +1 -1
  115. package/dist/throttler/injectThrottler.cjs.map +1 -1
  116. package/dist/throttler/injectThrottler.d.cts +0 -1
  117. package/dist/throttler/injectThrottler.d.ts +0 -1
  118. package/dist/throttler/injectThrottler.js.map +1 -1
  119. package/dist/types/index.cjs +0 -1
  120. package/dist/utils/index.cjs +0 -1
  121. package/package.json +5 -5
  122. package/src/debouncer/injectDebouncedValue.ts +1 -2
  123. package/src/queuer/injectQueuedValue.ts +2 -4
  124. package/src/rate-limiter/injectRateLimitedValue.ts +1 -2
  125. package/src/throttler/injectThrottledValue.ts +1 -2
@@ -1 +1 @@
1
- {"version":3,"file":"injectThrottledValue.cjs","names":["injectThrottledSignal"],"sources":["../../src/throttler/injectThrottledValue.ts"],"sourcesContent":["import { effect } from '@angular/core'\nimport { injectThrottledSignal } from './injectThrottledSignal'\nimport type { ThrottledSignal } from './injectThrottledSignal'\nimport type { Signal } from '@angular/core'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\n/**\n * An Angular function that creates a throttled value that updates at most once within a specified time window.\n * Unlike injectThrottledSignal, this function automatically tracks changes to the input signal\n * and updates the throttled value accordingly.\n *\n * The throttled value will update at most once within the specified wait time, regardless of\n * how frequently the input value changes.\n *\n * This is useful for deriving throttled values from signals that change frequently,\n * like scroll positions or mouse coordinates, where you want to limit how often downstream effects\n * or calculations occur.\n *\n * The function returns a throttled signal object containing:\n * - A Signal that provides the current throttled value\n * - The throttler instance with control methods\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler 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.\n *\n * Available throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const scrollY = signal(0)\n * const throttledScrollY = injectThrottledValue(scrollY, {\n * wait: 100, // Update at most once per 100ms\n * })\n *\n * // Opt-in to reactive updates when pending state changes\n * const throttledScrollYWithState = injectThrottledValue(\n * scrollY,\n * { wait: 100 },\n * (state) => ({ isPending: state.isPending }),\n * )\n *\n * // Read the throttled signal value\n * effect(() => {\n * updateUI(throttledScrollY())\n * })\n *\n * // Access throttler state via the returned object's state() signal\n * console.log('Is pending:', throttledScrollYWithState.state().isPending)\n *\n * // Control the throttler\n * throttledScrollY.cancel() // Cancel any pending updates\n * ```\n */\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected>\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValue: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected>\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValueOrOptions: TValue | ThrottlerOptions<Setter<TValue>>,\n initialOptionsOrSelector?:\n | ThrottlerOptions<Setter<TValue>>\n | ((state: ThrottlerState<Setter<TValue>>) => TSelected),\n maybeSelector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected> {\n const hasSelector = typeof initialOptionsOrSelector === 'function'\n\n const hasInitialValue =\n (initialOptionsOrSelector !== undefined && !hasSelector) ||\n maybeSelector !== undefined\n\n const initialValue = hasInitialValue\n ? (initialValueOrOptions as TValue)\n : (undefined as unknown as TValue)\n const initialOptions = hasInitialValue\n ? (initialOptionsOrSelector as ThrottlerOptions<Setter<TValue>>)\n : (initialValueOrOptions as ThrottlerOptions<Setter<TValue>>)\n const selector = hasInitialValue\n ? maybeSelector\n : (initialOptionsOrSelector as\n | ((state: ThrottlerState<Setter<TValue>>) => TSelected)\n | undefined)\n\n const throttledValue = injectThrottledSignal(\n initialValue,\n initialOptions,\n selector,\n )\n\n effect(() => {\n const latest = value()\n throttledValue.set(latest)\n })\n\n return throttledValue\n}\n"],"mappings":";;;;AAqFA,SAAgB,qBACd,OACA,uBACA,0BAGA,eACoC;CAGpC,MAAM,kBACH,6BAA6B,UAAa,EAHzB,OAAO,6BAA6B,eAItD,kBAAkB;CAcpB,MAAM,iBAAiBA,oDAZF,kBAChB,wBACA,QACkB,kBAClB,2BACA,uBACY,kBACb,gBACC,yBAQJ;AAED,iCAAa;EACX,MAAM,SAAS,OAAO;AACtB,iBAAe,IAAI,OAAO;GAC1B;AAEF,QAAO"}
1
+ {"version":3,"file":"injectThrottledValue.cjs","names":["injectThrottledSignal"],"sources":["../../src/throttler/injectThrottledValue.ts"],"sourcesContent":["import { effect } from '@angular/core'\nimport { injectThrottledSignal } from './injectThrottledSignal'\nimport type { ThrottledSignal } from './injectThrottledSignal'\nimport type { Signal } from '@angular/core'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\n/**\n * An Angular function that creates a throttled value that updates at most once within a specified time window.\n * Unlike injectThrottledSignal, this function automatically tracks changes to the input signal\n * and updates the throttled value accordingly.\n *\n * The throttled value will update at most once within the specified wait time, regardless of\n * how frequently the input value changes.\n *\n * This is useful for deriving throttled values from signals that change frequently,\n * like scroll positions or mouse coordinates, where you want to limit how often downstream effects\n * or calculations occur.\n *\n * The function returns a throttled signal object containing:\n * - A Signal that provides the current throttled value\n * - The throttler instance with control methods\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler 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.\n *\n * Available throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const scrollY = signal(0)\n * const throttledScrollY = injectThrottledValue(scrollY, {\n * wait: 100, // Update at most once per 100ms\n * })\n *\n * // Opt-in to reactive updates when pending state changes\n * const throttledScrollYWithState = injectThrottledValue(\n * scrollY,\n * { wait: 100 },\n * (state) => ({ isPending: state.isPending }),\n * )\n *\n * // Read the throttled signal value\n * effect(() => {\n * updateUI(throttledScrollY())\n * })\n *\n * // Access throttler state via the returned object's state() signal\n * console.log('Is pending:', throttledScrollYWithState.state().isPending)\n *\n * // Control the throttler\n * throttledScrollY.cancel() // Cancel any pending updates\n * ```\n */\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected>\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValue: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected>\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValueOrOptions: TValue | ThrottlerOptions<Setter<TValue>>,\n initialOptionsOrSelector?:\n | ThrottlerOptions<Setter<TValue>>\n | ((state: ThrottlerState<Setter<TValue>>) => TSelected),\n maybeSelector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected> {\n const hasSelector = typeof initialOptionsOrSelector === 'function'\n\n const hasInitialValue =\n (initialOptionsOrSelector !== undefined && !hasSelector) ||\n maybeSelector !== undefined\n\n const initialValue = hasInitialValue\n ? (initialValueOrOptions as TValue)\n : (undefined as unknown as TValue)\n const initialOptions = hasInitialValue\n ? (initialOptionsOrSelector as ThrottlerOptions<Setter<TValue>>)\n : (initialValueOrOptions as ThrottlerOptions<Setter<TValue>>)\n const selector = hasInitialValue\n ? maybeSelector\n : (initialOptionsOrSelector as\n ((state: ThrottlerState<Setter<TValue>>) => TSelected) | undefined)\n\n const throttledValue = injectThrottledSignal(\n initialValue,\n initialOptions,\n selector,\n )\n\n effect(() => {\n const latest = value()\n throttledValue.set(latest)\n })\n\n return throttledValue\n}\n"],"mappings":";;;;AAqFA,SAAgB,qBACd,OACA,uBACA,0BAGA,eACoC;CAGpC,MAAM,kBACH,6BAA6B,UAAa,EAHzB,OAAO,6BAA6B,eAItD,kBAAkB;CAapB,MAAM,iBAAiBA,oDAXF,kBAChB,wBACA,QACkB,kBAClB,2BACA,uBACY,kBACb,gBACC,wBAOL;CAEA,gCAAa;EACX,MAAM,SAAS,MAAM;EACrB,eAAe,IAAI,MAAM;CAC3B,CAAC;CAED,OAAO;AACT"}
@@ -1,7 +1,6 @@
1
1
  import { ThrottledSignal } from "./injectThrottledSignal.cjs";
2
2
  import { Signal } from "@angular/core";
3
3
  import { ThrottlerOptions, ThrottlerState } from "@tanstack/pacer/throttler";
4
-
5
4
  //#region src/throttler/injectThrottledValue.d.ts
6
5
  type Setter<T> = (value: T | ((prev: T) => T)) => void;
7
6
  /**
@@ -1,7 +1,6 @@
1
1
  import { ThrottledSignal } from "./injectThrottledSignal.js";
2
2
  import { Signal } from "@angular/core";
3
3
  import { ThrottlerOptions, ThrottlerState } from "@tanstack/pacer/throttler";
4
-
5
4
  //#region src/throttler/injectThrottledValue.d.ts
6
5
  type Setter<T> = (value: T | ((prev: T) => T)) => void;
7
6
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"injectThrottledValue.js","names":[],"sources":["../../src/throttler/injectThrottledValue.ts"],"sourcesContent":["import { effect } from '@angular/core'\nimport { injectThrottledSignal } from './injectThrottledSignal'\nimport type { ThrottledSignal } from './injectThrottledSignal'\nimport type { Signal } from '@angular/core'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\n/**\n * An Angular function that creates a throttled value that updates at most once within a specified time window.\n * Unlike injectThrottledSignal, this function automatically tracks changes to the input signal\n * and updates the throttled value accordingly.\n *\n * The throttled value will update at most once within the specified wait time, regardless of\n * how frequently the input value changes.\n *\n * This is useful for deriving throttled values from signals that change frequently,\n * like scroll positions or mouse coordinates, where you want to limit how often downstream effects\n * or calculations occur.\n *\n * The function returns a throttled signal object containing:\n * - A Signal that provides the current throttled value\n * - The throttler instance with control methods\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler 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.\n *\n * Available throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const scrollY = signal(0)\n * const throttledScrollY = injectThrottledValue(scrollY, {\n * wait: 100, // Update at most once per 100ms\n * })\n *\n * // Opt-in to reactive updates when pending state changes\n * const throttledScrollYWithState = injectThrottledValue(\n * scrollY,\n * { wait: 100 },\n * (state) => ({ isPending: state.isPending }),\n * )\n *\n * // Read the throttled signal value\n * effect(() => {\n * updateUI(throttledScrollY())\n * })\n *\n * // Access throttler state via the returned object's state() signal\n * console.log('Is pending:', throttledScrollYWithState.state().isPending)\n *\n * // Control the throttler\n * throttledScrollY.cancel() // Cancel any pending updates\n * ```\n */\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected>\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValue: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected>\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValueOrOptions: TValue | ThrottlerOptions<Setter<TValue>>,\n initialOptionsOrSelector?:\n | ThrottlerOptions<Setter<TValue>>\n | ((state: ThrottlerState<Setter<TValue>>) => TSelected),\n maybeSelector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected> {\n const hasSelector = typeof initialOptionsOrSelector === 'function'\n\n const hasInitialValue =\n (initialOptionsOrSelector !== undefined && !hasSelector) ||\n maybeSelector !== undefined\n\n const initialValue = hasInitialValue\n ? (initialValueOrOptions as TValue)\n : (undefined as unknown as TValue)\n const initialOptions = hasInitialValue\n ? (initialOptionsOrSelector as ThrottlerOptions<Setter<TValue>>)\n : (initialValueOrOptions as ThrottlerOptions<Setter<TValue>>)\n const selector = hasInitialValue\n ? maybeSelector\n : (initialOptionsOrSelector as\n | ((state: ThrottlerState<Setter<TValue>>) => TSelected)\n | undefined)\n\n const throttledValue = injectThrottledSignal(\n initialValue,\n initialOptions,\n selector,\n )\n\n effect(() => {\n const latest = value()\n throttledValue.set(latest)\n })\n\n return throttledValue\n}\n"],"mappings":";;;;AAqFA,SAAgB,qBACd,OACA,uBACA,0BAGA,eACoC;CAGpC,MAAM,kBACH,6BAA6B,UAAa,EAHzB,OAAO,6BAA6B,eAItD,kBAAkB;CAcpB,MAAM,iBAAiB,sBAZF,kBAChB,wBACA,QACkB,kBAClB,2BACA,uBACY,kBACb,gBACC,yBAQJ;AAED,cAAa;EACX,MAAM,SAAS,OAAO;AACtB,iBAAe,IAAI,OAAO;GAC1B;AAEF,QAAO"}
1
+ {"version":3,"file":"injectThrottledValue.js","names":[],"sources":["../../src/throttler/injectThrottledValue.ts"],"sourcesContent":["import { effect } from '@angular/core'\nimport { injectThrottledSignal } from './injectThrottledSignal'\nimport type { ThrottledSignal } from './injectThrottledSignal'\nimport type { Signal } from '@angular/core'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\n/**\n * An Angular function that creates a throttled value that updates at most once within a specified time window.\n * Unlike injectThrottledSignal, this function automatically tracks changes to the input signal\n * and updates the throttled value accordingly.\n *\n * The throttled value will update at most once within the specified wait time, regardless of\n * how frequently the input value changes.\n *\n * This is useful for deriving throttled values from signals that change frequently,\n * like scroll positions or mouse coordinates, where you want to limit how often downstream effects\n * or calculations occur.\n *\n * The function returns a throttled signal object containing:\n * - A Signal that provides the current throttled value\n * - The throttler instance with control methods\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler 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.\n *\n * Available throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const scrollY = signal(0)\n * const throttledScrollY = injectThrottledValue(scrollY, {\n * wait: 100, // Update at most once per 100ms\n * })\n *\n * // Opt-in to reactive updates when pending state changes\n * const throttledScrollYWithState = injectThrottledValue(\n * scrollY,\n * { wait: 100 },\n * (state) => ({ isPending: state.isPending }),\n * )\n *\n * // Read the throttled signal value\n * effect(() => {\n * updateUI(throttledScrollY())\n * })\n *\n * // Access throttler state via the returned object's state() signal\n * console.log('Is pending:', throttledScrollYWithState.state().isPending)\n *\n * // Control the throttler\n * throttledScrollY.cancel() // Cancel any pending updates\n * ```\n */\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected>\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValue: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected>\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValueOrOptions: TValue | ThrottlerOptions<Setter<TValue>>,\n initialOptionsOrSelector?:\n | ThrottlerOptions<Setter<TValue>>\n | ((state: ThrottlerState<Setter<TValue>>) => TSelected),\n maybeSelector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected> {\n const hasSelector = typeof initialOptionsOrSelector === 'function'\n\n const hasInitialValue =\n (initialOptionsOrSelector !== undefined && !hasSelector) ||\n maybeSelector !== undefined\n\n const initialValue = hasInitialValue\n ? (initialValueOrOptions as TValue)\n : (undefined as unknown as TValue)\n const initialOptions = hasInitialValue\n ? (initialOptionsOrSelector as ThrottlerOptions<Setter<TValue>>)\n : (initialValueOrOptions as ThrottlerOptions<Setter<TValue>>)\n const selector = hasInitialValue\n ? maybeSelector\n : (initialOptionsOrSelector as\n ((state: ThrottlerState<Setter<TValue>>) => TSelected) | undefined)\n\n const throttledValue = injectThrottledSignal(\n initialValue,\n initialOptions,\n selector,\n )\n\n effect(() => {\n const latest = value()\n throttledValue.set(latest)\n })\n\n return throttledValue\n}\n"],"mappings":";;;;AAqFA,SAAgB,qBACd,OACA,uBACA,0BAGA,eACoC;CAGpC,MAAM,kBACH,6BAA6B,UAAa,EAHzB,OAAO,6BAA6B,eAItD,kBAAkB;CAapB,MAAM,iBAAiB,sBAXF,kBAChB,wBACA,QACkB,kBAClB,2BACA,uBACY,kBACb,gBACC,wBAOL;CAEA,aAAa;EACX,MAAM,SAAS,MAAM;EACrB,eAAe,IAAI,MAAM;CAC3B,CAAC;CAED,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"injectThrottler.cjs","names":["injectPacerOptions","Throttler","DestroyRef"],"sources":["../../src/throttler/injectThrottler.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { Throttler } from '@tanstack/pacer/throttler'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\nexport interface AngularThrottlerOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends ThrottlerOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the throttler instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), cancel(), add logging, etc.\n */\n onUnmount?: (throttler: AngularThrottler<TFn, TSelected>) => void\n}\n\nexport interface AngularThrottler<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Throttler<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the 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<ThrottlerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages a Throttler instance.\n *\n * This is a lower-level function that provides direct access to the Throttler's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides throttling functionality to limit how often a function can be called,\n * ensuring it executes at most once within a specified time window.\n *\n * The throttler will execute the function immediately (if leading is enabled) and then\n * prevent further executions until the wait period has elapsed.\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 * Available state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * ## Cleanup on Destroy\n *\n * By default, the function cancels any pending execution 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 = injectThrottler(fn, {\n * wait: 100,\n * onUnmount: (t) => t.flush()\n * });\n * ```\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const throttler = injectThrottler(\n * (scrollY: number) => updateScrollPosition(scrollY),\n * { wait: 100 }\n * );\n *\n * // Opt-in to track isPending changes (optimized for loading states)\n * const throttler = injectThrottler(\n * (scrollY: number) => updateScrollPosition(scrollY),\n * { wait: 100 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // In an event handler\n * window.addEventListener('scroll', () => {\n * throttler.maybeExecute(window.scrollY);\n * });\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = throttler.state();\n * ```\n */\nexport function injectThrottler<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: AngularThrottlerOptions<TFn, TSelected>,\n selector: (state: ThrottlerState<TFn>) => TSelected = () => ({}) as TSelected,\n): AngularThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().throttler,\n ...options,\n } as AngularThrottlerOptions<TFn, TSelected>\n\n const throttler = new Throttler<TFn>(fn, mergedOptions)\n const state = injectSelector(throttler.store, selector)\n\n const result = {\n ...throttler,\n state,\n } as AngularThrottler<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 }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4GA,SAAgB,gBACd,IACA,SACA,kBAA6D,EAAE,GAC7B;CAClC,MAAM,gBAAgB;EACpB,GAAGA,0CAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,YAAY,IAAIC,oCAAe,IAAI,cAAc;CACvD,MAAM,oDAAuB,UAAU,OAAO,SAAS;CAEvD,MAAM,SAAS;EACb,GAAG;EACH;EACD;AAGD,2BAD0BC,0BAAY,EAAE,UAAU,MAAM,CAAC,EAC7C,gBAAgB;AAC1B,MAAI,cAAc,UAChB,eAAc,UAAU,OAAO;MAE/B,WAAU,QAAQ;GAEpB;AAEF,QAAO"}
1
+ {"version":3,"file":"injectThrottler.cjs","names":["injectPacerOptions","Throttler","injectSelector","inject","DestroyRef"],"sources":["../../src/throttler/injectThrottler.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { Throttler } from '@tanstack/pacer/throttler'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\nexport interface AngularThrottlerOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends ThrottlerOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the throttler instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), cancel(), add logging, etc.\n */\n onUnmount?: (throttler: AngularThrottler<TFn, TSelected>) => void\n}\n\nexport interface AngularThrottler<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Throttler<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the 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<ThrottlerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages a Throttler instance.\n *\n * This is a lower-level function that provides direct access to the Throttler's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides throttling functionality to limit how often a function can be called,\n * ensuring it executes at most once within a specified time window.\n *\n * The throttler will execute the function immediately (if leading is enabled) and then\n * prevent further executions until the wait period has elapsed.\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 * Available state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * ## Cleanup on Destroy\n *\n * By default, the function cancels any pending execution 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 = injectThrottler(fn, {\n * wait: 100,\n * onUnmount: (t) => t.flush()\n * });\n * ```\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const throttler = injectThrottler(\n * (scrollY: number) => updateScrollPosition(scrollY),\n * { wait: 100 }\n * );\n *\n * // Opt-in to track isPending changes (optimized for loading states)\n * const throttler = injectThrottler(\n * (scrollY: number) => updateScrollPosition(scrollY),\n * { wait: 100 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // In an event handler\n * window.addEventListener('scroll', () => {\n * throttler.maybeExecute(window.scrollY);\n * });\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = throttler.state();\n * ```\n */\nexport function injectThrottler<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: AngularThrottlerOptions<TFn, TSelected>,\n selector: (state: ThrottlerState<TFn>) => TSelected = () => ({}) as TSelected,\n): AngularThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().throttler,\n ...options,\n } as AngularThrottlerOptions<TFn, TSelected>\n\n const throttler = new Throttler<TFn>(fn, mergedOptions)\n const state = injectSelector(throttler.store, selector)\n\n const result = {\n ...throttler,\n state,\n } as AngularThrottler<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 }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4GA,SAAgB,gBACd,IACA,SACA,kBAA6D,CAAC,IAC5B;CAClC,MAAM,gBAAgB;EACpB,GAAGA,yCAAmB,CAAC,CAAC;EACxB,GAAG;CACL;CAEA,MAAM,YAAY,IAAIC,oCAAe,IAAI,aAAa;CACtD,MAAM,YAAQC,wCAAe,UAAU,OAAO,QAAQ;CAEtD,MAAM,SAAS;EACb,GAAG;EACH;CACF;CAGA,IADmBC,sBAAOC,0BAAY,EAAE,UAAU,KAAK,CAC9C,CAAC,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,MAAM;OAE9B,UAAU,OAAO;CAErB,CAAC;CAED,OAAO;AACT"}
@@ -2,7 +2,6 @@ import { Signal } from "@angular/core";
2
2
  import { Store } from "@tanstack/angular-store";
3
3
  import { AnyFunction } from "@tanstack/pacer/types";
4
4
  import { Throttler, ThrottlerOptions, ThrottlerState } from "@tanstack/pacer/throttler";
5
-
6
5
  //#region src/throttler/injectThrottler.d.ts
7
6
  interface AngularThrottlerOptions<TFn extends AnyFunction, TSelected = {}> extends ThrottlerOptions<TFn> {
8
7
  /**
@@ -2,7 +2,6 @@ import { Signal } from "@angular/core";
2
2
  import { Store } from "@tanstack/angular-store";
3
3
  import { Throttler, ThrottlerOptions, ThrottlerState } from "@tanstack/pacer/throttler";
4
4
  import { AnyFunction } from "@tanstack/pacer/types";
5
-
6
5
  //#region src/throttler/injectThrottler.d.ts
7
6
  interface AngularThrottlerOptions<TFn extends AnyFunction, TSelected = {}> extends ThrottlerOptions<TFn> {
8
7
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"injectThrottler.js","names":[],"sources":["../../src/throttler/injectThrottler.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { Throttler } from '@tanstack/pacer/throttler'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\nexport interface AngularThrottlerOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends ThrottlerOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the throttler instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), cancel(), add logging, etc.\n */\n onUnmount?: (throttler: AngularThrottler<TFn, TSelected>) => void\n}\n\nexport interface AngularThrottler<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Throttler<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the 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<ThrottlerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages a Throttler instance.\n *\n * This is a lower-level function that provides direct access to the Throttler's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides throttling functionality to limit how often a function can be called,\n * ensuring it executes at most once within a specified time window.\n *\n * The throttler will execute the function immediately (if leading is enabled) and then\n * prevent further executions until the wait period has elapsed.\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 * Available state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * ## Cleanup on Destroy\n *\n * By default, the function cancels any pending execution 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 = injectThrottler(fn, {\n * wait: 100,\n * onUnmount: (t) => t.flush()\n * });\n * ```\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const throttler = injectThrottler(\n * (scrollY: number) => updateScrollPosition(scrollY),\n * { wait: 100 }\n * );\n *\n * // Opt-in to track isPending changes (optimized for loading states)\n * const throttler = injectThrottler(\n * (scrollY: number) => updateScrollPosition(scrollY),\n * { wait: 100 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // In an event handler\n * window.addEventListener('scroll', () => {\n * throttler.maybeExecute(window.scrollY);\n * });\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = throttler.state();\n * ```\n */\nexport function injectThrottler<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: AngularThrottlerOptions<TFn, TSelected>,\n selector: (state: ThrottlerState<TFn>) => TSelected = () => ({}) as TSelected,\n): AngularThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().throttler,\n ...options,\n } as AngularThrottlerOptions<TFn, TSelected>\n\n const throttler = new Throttler<TFn>(fn, mergedOptions)\n const state = injectSelector(throttler.store, selector)\n\n const result = {\n ...throttler,\n state,\n } as AngularThrottler<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 }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4GA,SAAgB,gBACd,IACA,SACA,kBAA6D,EAAE,GAC7B;CAClC,MAAM,gBAAgB;EACpB,GAAG,oBAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,YAAY,IAAI,UAAe,IAAI,cAAc;CACvD,MAAM,QAAQ,eAAe,UAAU,OAAO,SAAS;CAEvD,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,WAAU,QAAQ;GAEpB;AAEF,QAAO"}
1
+ {"version":3,"file":"injectThrottler.js","names":[],"sources":["../../src/throttler/injectThrottler.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { Throttler } from '@tanstack/pacer/throttler'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\nexport interface AngularThrottlerOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends ThrottlerOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the throttler instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), cancel(), add logging, etc.\n */\n onUnmount?: (throttler: AngularThrottler<TFn, TSelected>) => void\n}\n\nexport interface AngularThrottler<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Throttler<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the 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<ThrottlerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages a Throttler instance.\n *\n * This is a lower-level function that provides direct access to the Throttler's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides throttling functionality to limit how often a function can be called,\n * ensuring it executes at most once within a specified time window.\n *\n * The throttler will execute the function immediately (if leading is enabled) and then\n * prevent further executions until the wait period has elapsed.\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 * Available state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * ## Cleanup on Destroy\n *\n * By default, the function cancels any pending execution 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 = injectThrottler(fn, {\n * wait: 100,\n * onUnmount: (t) => t.flush()\n * });\n * ```\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const throttler = injectThrottler(\n * (scrollY: number) => updateScrollPosition(scrollY),\n * { wait: 100 }\n * );\n *\n * // Opt-in to track isPending changes (optimized for loading states)\n * const throttler = injectThrottler(\n * (scrollY: number) => updateScrollPosition(scrollY),\n * { wait: 100 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // In an event handler\n * window.addEventListener('scroll', () => {\n * throttler.maybeExecute(window.scrollY);\n * });\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = throttler.state();\n * ```\n */\nexport function injectThrottler<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: AngularThrottlerOptions<TFn, TSelected>,\n selector: (state: ThrottlerState<TFn>) => TSelected = () => ({}) as TSelected,\n): AngularThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().throttler,\n ...options,\n } as AngularThrottlerOptions<TFn, TSelected>\n\n const throttler = new Throttler<TFn>(fn, mergedOptions)\n const state = injectSelector(throttler.store, selector)\n\n const result = {\n ...throttler,\n state,\n } as AngularThrottler<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 }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4GA,SAAgB,gBACd,IACA,SACA,kBAA6D,CAAC,IAC5B;CAClC,MAAM,gBAAgB;EACpB,GAAG,mBAAmB,CAAC,CAAC;EACxB,GAAG;CACL;CAEA,MAAM,YAAY,IAAI,UAAe,IAAI,aAAa;CACtD,MAAM,QAAQ,eAAe,UAAU,OAAO,QAAQ;CAEtD,MAAM,SAAS;EACb,GAAG;EACH;CACF;CAGA,AADmB,OAAO,YAAY,EAAE,UAAU,KAAK,CAC9C,CAAC,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,MAAM;OAE9B,UAAU,OAAO;CAErB,CAAC;CAED,OAAO;AACT"}
@@ -1,5 +1,4 @@
1
1
 
2
-
3
2
  var _tanstack_pacer_types = require("@tanstack/pacer/types");
4
3
  Object.keys(_tanstack_pacer_types).forEach(function (k) {
5
4
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
@@ -1,5 +1,4 @@
1
1
 
2
-
3
2
  var _tanstack_pacer_utils = require("@tanstack/pacer/utils");
4
3
  Object.keys(_tanstack_pacer_utils).forEach(function (k) {
5
4
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/angular-pacer",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "description": "Utilities for debouncing and throttling functions in Angular.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -99,12 +99,12 @@
99
99
  "src"
100
100
  ],
101
101
  "dependencies": {
102
- "@tanstack/angular-store": "^0.11.0",
103
- "@tanstack/pacer": "0.21.0"
102
+ "@tanstack/angular-store": "^0.11.1",
103
+ "@tanstack/pacer": "0.22.0"
104
104
  },
105
105
  "devDependencies": {
106
- "@angular/core": "^21.2.9",
107
- "@types/node": "^25.6.0"
106
+ "@angular/core": "^22.1.0",
107
+ "@types/node": "^26.1.2"
108
108
  },
109
109
  "peerDependencies": {
110
110
  "@angular/core": ">=17.0.0"
@@ -108,8 +108,7 @@ export function injectDebouncedValue<TValue, TSelected = {}>(
108
108
  const selector = hasInitialValue
109
109
  ? maybeSelector
110
110
  : (initialOptionsOrSelector as
111
- | ((state: DebouncerState<Setter<TValue>>) => TSelected)
112
- | undefined)
111
+ ((state: DebouncerState<Setter<TValue>>) => TSelected) | undefined)
113
112
 
114
113
  const debounced = injectDebouncedSignal(
115
114
  initialValue,
@@ -61,8 +61,7 @@ export function injectQueuedValue<
61
61
  value: Signal<TValue>,
62
62
  initialValueOrOptions?: TValue | QueuerOptions<TValue>,
63
63
  initialOptionsOrSelector?:
64
- | QueuerOptions<TValue>
65
- | ((state: QueuerState<TValue>) => TSelected),
64
+ QueuerOptions<TValue> | ((state: QueuerState<TValue>) => TSelected),
66
65
  maybeSelector?: (state: QueuerState<TValue>) => TSelected,
67
66
  ): QueuedSignal<TValue, TSelected> {
68
67
  const hasSelector = typeof initialOptionsOrSelector === 'function'
@@ -79,8 +78,7 @@ export function injectQueuedValue<
79
78
  const selector = hasInitialValue
80
79
  ? maybeSelector
81
80
  : (initialOptionsOrSelector as
82
- | ((state: QueuerState<TValue>) => TSelected)
83
- | undefined)
81
+ ((state: QueuerState<TValue>) => TSelected) | undefined)
84
82
 
85
83
  const linkedValue = linkedSignal(() => value())
86
84
  const queuedValue = signal<TValue>(initialValue)
@@ -81,8 +81,7 @@ export function injectRateLimitedValue<TValue, TSelected = {}>(
81
81
  const selector = hasInitialValue
82
82
  ? maybeSelector
83
83
  : (initialOptionsOrSelector as
84
- | ((state: RateLimiterState) => TSelected)
85
- | undefined)
84
+ ((state: RateLimiterState) => TSelected) | undefined)
86
85
 
87
86
  const rateLimited = injectRateLimitedSignal(
88
87
  initialValue,
@@ -106,8 +106,7 @@ export function injectThrottledValue<TValue, TSelected = {}>(
106
106
  const selector = hasInitialValue
107
107
  ? maybeSelector
108
108
  : (initialOptionsOrSelector as
109
- | ((state: ThrottlerState<Setter<TValue>>) => TSelected)
110
- | undefined)
109
+ ((state: ThrottlerState<Setter<TValue>>) => TSelected) | undefined)
111
110
 
112
111
  const throttledValue = injectThrottledSignal(
113
112
  initialValue,