@tanstack/angular-pacer 0.23.1 → 0.25.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 (250) hide show
  1. package/README.md +21 -6
  2. package/dist/async-batcher/injectAsyncBatchedCallback.d.ts +2 -5
  3. package/dist/async-batcher/injectAsyncBatchedCallback.js +1 -2
  4. package/dist/async-batcher/injectAsyncBatcher.d.ts +4 -7
  5. package/dist/async-batcher/injectAsyncBatcher.js +1 -2
  6. package/dist/async-debouncer/injectAsyncDebouncedCallback.d.ts +2 -5
  7. package/dist/async-debouncer/injectAsyncDebouncedCallback.js +1 -2
  8. package/dist/async-debouncer/injectAsyncDebouncer.d.ts +4 -7
  9. package/dist/async-debouncer/injectAsyncDebouncer.js +1 -2
  10. package/dist/async-queuer/injectAsyncQueuedSignal.d.ts +3 -6
  11. package/dist/async-queuer/injectAsyncQueuedSignal.js +1 -2
  12. package/dist/async-queuer/injectAsyncQueuer.d.ts +4 -7
  13. package/dist/async-queuer/injectAsyncQueuer.js +1 -2
  14. package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.d.ts +2 -5
  15. package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.js +1 -2
  16. package/dist/async-rate-limiter/injectAsyncRateLimiter.d.ts +4 -7
  17. package/dist/async-rate-limiter/injectAsyncRateLimiter.js +1 -2
  18. package/dist/async-throttler/injectAsyncThrottledCallback.d.ts +2 -5
  19. package/dist/async-throttler/injectAsyncThrottledCallback.js +1 -2
  20. package/dist/async-throttler/injectAsyncThrottler.d.ts +4 -7
  21. package/dist/async-throttler/injectAsyncThrottler.js +1 -2
  22. package/dist/batcher/injectBatchedCallback.d.ts +2 -5
  23. package/dist/batcher/injectBatchedCallback.js +1 -2
  24. package/dist/batcher/injectBatcher.d.ts +4 -7
  25. package/dist/batcher/injectBatcher.js +1 -2
  26. package/dist/debouncer/injectDebouncedCallback.d.ts +2 -5
  27. package/dist/debouncer/injectDebouncedCallback.js +1 -2
  28. package/dist/debouncer/injectDebouncedSignal.d.ts +3 -6
  29. package/dist/debouncer/injectDebouncedSignal.js +1 -2
  30. package/dist/debouncer/injectDebouncedValue.d.ts +3 -6
  31. package/dist/debouncer/injectDebouncedValue.js +1 -2
  32. package/dist/debouncer/injectDebouncer.d.ts +4 -7
  33. package/dist/debouncer/injectDebouncer.js +1 -2
  34. package/dist/provider/pacer-context.d.ts +4 -7
  35. package/dist/provider/pacer-context.js +1 -2
  36. package/dist/provider/pacer-provider.d.ts +2 -5
  37. package/dist/provider/pacer-provider.js +1 -2
  38. package/dist/queuer/injectQueuedSignal.d.ts +3 -6
  39. package/dist/queuer/injectQueuedSignal.js +1 -2
  40. package/dist/queuer/injectQueuedValue.d.ts +3 -6
  41. package/dist/queuer/injectQueuedValue.js +1 -2
  42. package/dist/queuer/injectQueuer.d.ts +4 -7
  43. package/dist/queuer/injectQueuer.js +1 -2
  44. package/dist/rate-limiter/injectRateLimitedCallback.d.ts +2 -5
  45. package/dist/rate-limiter/injectRateLimitedCallback.js +1 -2
  46. package/dist/rate-limiter/injectRateLimitedSignal.d.ts +3 -6
  47. package/dist/rate-limiter/injectRateLimitedSignal.js +1 -2
  48. package/dist/rate-limiter/injectRateLimitedValue.d.ts +3 -6
  49. package/dist/rate-limiter/injectRateLimitedValue.js +1 -2
  50. package/dist/rate-limiter/injectRateLimiter.d.ts +4 -7
  51. package/dist/rate-limiter/injectRateLimiter.js +1 -2
  52. package/dist/throttler/injectThrottledCallback.d.ts +2 -5
  53. package/dist/throttler/injectThrottledCallback.js +1 -2
  54. package/dist/throttler/injectThrottledSignal.d.ts +3 -8
  55. package/dist/throttler/injectThrottledSignal.js +1 -4
  56. package/dist/throttler/injectThrottledValue.d.ts +3 -8
  57. package/dist/throttler/injectThrottledValue.js +1 -2
  58. package/dist/throttler/injectThrottler.d.ts +4 -9
  59. package/dist/throttler/injectThrottler.js +1 -4
  60. package/package.json +25 -72
  61. package/dist/async-batcher/index.cjs +0 -13
  62. package/dist/async-batcher/index.d.cts +0 -4
  63. package/dist/async-batcher/injectAsyncBatchedCallback.cjs +0 -49
  64. package/dist/async-batcher/injectAsyncBatchedCallback.cjs.map +0 -1
  65. package/dist/async-batcher/injectAsyncBatchedCallback.d.cts +0 -45
  66. package/dist/async-batcher/injectAsyncBatchedCallback.js.map +0 -1
  67. package/dist/async-batcher/injectAsyncBatcher.cjs +0 -85
  68. package/dist/async-batcher/injectAsyncBatcher.cjs.map +0 -1
  69. package/dist/async-batcher/injectAsyncBatcher.d.cts +0 -85
  70. package/dist/async-batcher/injectAsyncBatcher.js.map +0 -1
  71. package/dist/async-debouncer/index.cjs +0 -13
  72. package/dist/async-debouncer/index.d.cts +0 -4
  73. package/dist/async-debouncer/injectAsyncDebouncedCallback.cjs +0 -49
  74. package/dist/async-debouncer/injectAsyncDebouncedCallback.cjs.map +0 -1
  75. package/dist/async-debouncer/injectAsyncDebouncedCallback.d.cts +0 -43
  76. package/dist/async-debouncer/injectAsyncDebouncedCallback.js.map +0 -1
  77. package/dist/async-debouncer/injectAsyncDebouncer.cjs +0 -107
  78. package/dist/async-debouncer/injectAsyncDebouncer.cjs.map +0 -1
  79. package/dist/async-debouncer/injectAsyncDebouncer.d.cts +0 -108
  80. package/dist/async-debouncer/injectAsyncDebouncer.js.map +0 -1
  81. package/dist/async-queuer/index.cjs +0 -13
  82. package/dist/async-queuer/index.d.cts +0 -4
  83. package/dist/async-queuer/injectAsyncQueuedSignal.cjs +0 -53
  84. package/dist/async-queuer/injectAsyncQueuedSignal.cjs.map +0 -1
  85. package/dist/async-queuer/injectAsyncQueuedSignal.d.cts +0 -50
  86. package/dist/async-queuer/injectAsyncQueuedSignal.js.map +0 -1
  87. package/dist/async-queuer/injectAsyncQueuer.cjs +0 -85
  88. package/dist/async-queuer/injectAsyncQueuer.cjs.map +0 -1
  89. package/dist/async-queuer/injectAsyncQueuer.d.cts +0 -85
  90. package/dist/async-queuer/injectAsyncQueuer.js.map +0 -1
  91. package/dist/async-rate-limiter/index.cjs +0 -13
  92. package/dist/async-rate-limiter/index.d.cts +0 -4
  93. package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.cjs +0 -52
  94. package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.cjs.map +0 -1
  95. package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.d.cts +0 -46
  96. package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.js.map +0 -1
  97. package/dist/async-rate-limiter/injectAsyncRateLimiter.cjs +0 -69
  98. package/dist/async-rate-limiter/injectAsyncRateLimiter.cjs.map +0 -1
  99. package/dist/async-rate-limiter/injectAsyncRateLimiter.d.cts +0 -72
  100. package/dist/async-rate-limiter/injectAsyncRateLimiter.js.map +0 -1
  101. package/dist/async-retryer/index.cjs +0 -9
  102. package/dist/async-retryer/index.d.cts +0 -1
  103. package/dist/async-throttler/index.cjs +0 -13
  104. package/dist/async-throttler/index.d.cts +0 -4
  105. package/dist/async-throttler/injectAsyncThrottledCallback.cjs +0 -50
  106. package/dist/async-throttler/injectAsyncThrottledCallback.cjs.map +0 -1
  107. package/dist/async-throttler/injectAsyncThrottledCallback.d.cts +0 -44
  108. package/dist/async-throttler/injectAsyncThrottledCallback.js.map +0 -1
  109. package/dist/async-throttler/injectAsyncThrottler.cjs +0 -86
  110. package/dist/async-throttler/injectAsyncThrottler.cjs.map +0 -1
  111. package/dist/async-throttler/injectAsyncThrottler.d.cts +0 -87
  112. package/dist/async-throttler/injectAsyncThrottler.js.map +0 -1
  113. package/dist/batcher/index.cjs +0 -13
  114. package/dist/batcher/index.d.cts +0 -4
  115. package/dist/batcher/injectBatchedCallback.cjs +0 -47
  116. package/dist/batcher/injectBatchedCallback.cjs.map +0 -1
  117. package/dist/batcher/injectBatchedCallback.d.cts +0 -43
  118. package/dist/batcher/injectBatchedCallback.js.map +0 -1
  119. package/dist/batcher/injectBatcher.cjs +0 -75
  120. package/dist/batcher/injectBatcher.cjs.map +0 -1
  121. package/dist/batcher/injectBatcher.d.cts +0 -77
  122. package/dist/batcher/injectBatcher.js.map +0 -1
  123. package/dist/debouncer/index.cjs +0 -17
  124. package/dist/debouncer/index.d.cts +0 -6
  125. package/dist/debouncer/injectDebouncedCallback.cjs +0 -46
  126. package/dist/debouncer/injectDebouncedCallback.cjs.map +0 -1
  127. package/dist/debouncer/injectDebouncedCallback.d.cts +0 -43
  128. package/dist/debouncer/injectDebouncedCallback.js.map +0 -1
  129. package/dist/debouncer/injectDebouncedSignal.cjs +0 -68
  130. package/dist/debouncer/injectDebouncedSignal.cjs.map +0 -1
  131. package/dist/debouncer/injectDebouncedSignal.d.cts +0 -60
  132. package/dist/debouncer/injectDebouncedSignal.js.map +0 -1
  133. package/dist/debouncer/injectDebouncedValue.cjs +0 -17
  134. package/dist/debouncer/injectDebouncedValue.cjs.map +0 -1
  135. package/dist/debouncer/injectDebouncedValue.d.cts +0 -76
  136. package/dist/debouncer/injectDebouncedValue.js.map +0 -1
  137. package/dist/debouncer/injectDebouncer.cjs +0 -95
  138. package/dist/debouncer/injectDebouncer.cjs.map +0 -1
  139. package/dist/debouncer/injectDebouncer.d.cts +0 -98
  140. package/dist/debouncer/injectDebouncer.js.map +0 -1
  141. package/dist/index.cjs +0 -65
  142. package/dist/index.d.cts +0 -30
  143. package/dist/provider/index.cjs +0 -7
  144. package/dist/provider/index.d.cts +0 -3
  145. package/dist/provider/pacer-context.cjs +0 -20
  146. package/dist/provider/pacer-context.cjs.map +0 -1
  147. package/dist/provider/pacer-context.d.cts +0 -21
  148. package/dist/provider/pacer-context.js.map +0 -1
  149. package/dist/provider/pacer-provider.cjs +0 -41
  150. package/dist/provider/pacer-provider.cjs.map +0 -1
  151. package/dist/provider/pacer-provider.d.cts +0 -36
  152. package/dist/provider/pacer-provider.js.map +0 -1
  153. package/dist/queuer/index.cjs +0 -15
  154. package/dist/queuer/index.d.cts +0 -5
  155. package/dist/queuer/injectQueuedSignal.cjs +0 -47
  156. package/dist/queuer/injectQueuedSignal.cjs.map +0 -1
  157. package/dist/queuer/injectQueuedSignal.d.cts +0 -44
  158. package/dist/queuer/injectQueuedSignal.js.map +0 -1
  159. package/dist/queuer/injectQueuedValue.cjs +0 -23
  160. package/dist/queuer/injectQueuedValue.cjs.map +0 -1
  161. package/dist/queuer/injectQueuedValue.d.cts +0 -34
  162. package/dist/queuer/injectQueuedValue.js.map +0 -1
  163. package/dist/queuer/injectQueuer.cjs +0 -80
  164. package/dist/queuer/injectQueuer.cjs.map +0 -1
  165. package/dist/queuer/injectQueuer.d.cts +0 -82
  166. package/dist/queuer/injectQueuer.js.map +0 -1
  167. package/dist/rate-limiter/index.cjs +0 -17
  168. package/dist/rate-limiter/index.d.cts +0 -6
  169. package/dist/rate-limiter/injectRateLimitedCallback.cjs +0 -45
  170. package/dist/rate-limiter/injectRateLimitedCallback.cjs.map +0 -1
  171. package/dist/rate-limiter/injectRateLimitedCallback.d.cts +0 -42
  172. package/dist/rate-limiter/injectRateLimitedCallback.js.map +0 -1
  173. package/dist/rate-limiter/injectRateLimitedSignal.cjs +0 -62
  174. package/dist/rate-limiter/injectRateLimitedSignal.cjs.map +0 -1
  175. package/dist/rate-limiter/injectRateLimitedSignal.d.cts +0 -54
  176. package/dist/rate-limiter/injectRateLimitedSignal.js.map +0 -1
  177. package/dist/rate-limiter/injectRateLimitedValue.cjs +0 -17
  178. package/dist/rate-limiter/injectRateLimitedValue.cjs.map +0 -1
  179. package/dist/rate-limiter/injectRateLimitedValue.d.cts +0 -49
  180. package/dist/rate-limiter/injectRateLimitedValue.js.map +0 -1
  181. package/dist/rate-limiter/injectRateLimiter.cjs +0 -100
  182. package/dist/rate-limiter/injectRateLimiter.cjs.map +0 -1
  183. package/dist/rate-limiter/injectRateLimiter.d.cts +0 -103
  184. package/dist/rate-limiter/injectRateLimiter.js.map +0 -1
  185. package/dist/throttler/index.cjs +0 -17
  186. package/dist/throttler/index.d.cts +0 -6
  187. package/dist/throttler/injectThrottledCallback.cjs +0 -45
  188. package/dist/throttler/injectThrottledCallback.cjs.map +0 -1
  189. package/dist/throttler/injectThrottledCallback.d.cts +0 -42
  190. package/dist/throttler/injectThrottledCallback.js.map +0 -1
  191. package/dist/throttler/injectThrottledSignal.cjs +0 -69
  192. package/dist/throttler/injectThrottledSignal.cjs.map +0 -1
  193. package/dist/throttler/injectThrottledSignal.d.cts +0 -61
  194. package/dist/throttler/injectThrottledSignal.js.map +0 -1
  195. package/dist/throttler/injectThrottledValue.cjs +0 -17
  196. package/dist/throttler/injectThrottledValue.cjs.map +0 -1
  197. package/dist/throttler/injectThrottledValue.d.cts +0 -74
  198. package/dist/throttler/injectThrottledValue.js.map +0 -1
  199. package/dist/throttler/injectThrottler.cjs +0 -95
  200. package/dist/throttler/injectThrottler.cjs.map +0 -1
  201. package/dist/throttler/injectThrottler.d.cts +0 -98
  202. package/dist/throttler/injectThrottler.js.map +0 -1
  203. package/dist/types/index.cjs +0 -9
  204. package/dist/types/index.d.cts +0 -1
  205. package/dist/utils/index.cjs +0 -9
  206. package/dist/utils/index.d.cts +0 -1
  207. package/src/async-batcher/index.ts +0 -4
  208. package/src/async-batcher/injectAsyncBatchedCallback.ts +0 -48
  209. package/src/async-batcher/injectAsyncBatcher.ts +0 -126
  210. package/src/async-debouncer/index.ts +0 -4
  211. package/src/async-debouncer/injectAsyncDebouncedCallback.ts +0 -50
  212. package/src/async-debouncer/injectAsyncDebouncer.ts +0 -152
  213. package/src/async-queuer/index.ts +0 -4
  214. package/src/async-queuer/injectAsyncQueuedSignal.ts +0 -74
  215. package/src/async-queuer/injectAsyncQueuer.ts +0 -126
  216. package/src/async-rate-limiter/index.ts +0 -4
  217. package/src/async-rate-limiter/injectAsyncRateLimitedCallback.ts +0 -52
  218. package/src/async-rate-limiter/injectAsyncRateLimiter.ts +0 -115
  219. package/src/async-retryer/index.ts +0 -1
  220. package/src/async-throttler/index.ts +0 -4
  221. package/src/async-throttler/injectAsyncThrottledCallback.ts +0 -50
  222. package/src/async-throttler/injectAsyncThrottler.ts +0 -131
  223. package/src/batcher/index.ts +0 -4
  224. package/src/batcher/injectBatchedCallback.ts +0 -46
  225. package/src/batcher/injectBatcher.ts +0 -114
  226. package/src/debouncer/index.ts +0 -6
  227. package/src/debouncer/injectDebouncedCallback.ts +0 -46
  228. package/src/debouncer/injectDebouncedSignal.ts +0 -94
  229. package/src/debouncer/injectDebouncedValue.ts +0 -126
  230. package/src/debouncer/injectDebouncer.ts +0 -137
  231. package/src/index.ts +0 -40
  232. package/src/provider/index.ts +0 -2
  233. package/src/provider/pacer-context.ts +0 -46
  234. package/src/provider/pacer-provider.ts +0 -38
  235. package/src/queuer/index.ts +0 -5
  236. package/src/queuer/injectQueuedSignal.ts +0 -65
  237. package/src/queuer/injectQueuedValue.ts +0 -101
  238. package/src/queuer/injectQueuer.ts +0 -118
  239. package/src/rate-limiter/index.ts +0 -6
  240. package/src/rate-limiter/injectRateLimitedCallback.ts +0 -45
  241. package/src/rate-limiter/injectRateLimitedSignal.ts +0 -88
  242. package/src/rate-limiter/injectRateLimitedValue.ts +0 -99
  243. package/src/rate-limiter/injectRateLimiter.ts +0 -140
  244. package/src/throttler/index.ts +0 -6
  245. package/src/throttler/injectThrottledCallback.ts +0 -45
  246. package/src/throttler/injectThrottledSignal.ts +0 -95
  247. package/src/throttler/injectThrottledValue.ts +0 -124
  248. package/src/throttler/injectThrottler.ts +0 -137
  249. package/src/types/index.ts +0 -1
  250. package/src/utils/index.ts +0 -1
@@ -1,46 +0,0 @@
1
- import { injectDebouncer } from './injectDebouncer'
2
- import type { DebouncerOptions } from '@tanstack/pacer/debouncer'
3
- import type { AnyFunction } from '@tanstack/pacer/types'
4
-
5
- /**
6
- * An Angular function that creates a debounced version of a callback function.
7
- * This function is essentially a wrapper around `injectDebouncer` that provides
8
- * a simplified API for basic debouncing needs.
9
- *
10
- * The debounced function will only execute after the specified wait time has elapsed
11
- * since its last invocation. If called again before the wait time expires, the timer
12
- * resets and starts waiting again.
13
- *
14
- * This function provides a simpler API compared to `injectDebouncer`, making it ideal for basic
15
- * debouncing needs. However, it does not expose the underlying Debouncer instance.
16
- *
17
- * For advanced usage requiring features like:
18
- * - Manual cancellation
19
- * - Access to execution counts
20
- * - State tracking
21
- *
22
- * Consider using the `injectDebouncer` function instead.
23
- *
24
- * @example
25
- * ```ts
26
- * // Debounce a search handler
27
- * const handleSearch = injectDebouncedCallback((query: string) => {
28
- * fetchSearchResults(query);
29
- * }, {
30
- * wait: 500 // Wait 500ms between executions
31
- * });
32
- *
33
- * // Use in an input
34
- * <input
35
- * type="search"
36
- * (input)="handleSearch($event.target.value)"
37
- * />
38
- * ```
39
- */
40
- export function injectDebouncedCallback<TFn extends AnyFunction>(
41
- fn: TFn,
42
- options: DebouncerOptions<TFn>,
43
- ): (...args: Parameters<TFn>) => void {
44
- const debouncer = injectDebouncer(fn, options)
45
- return (...args: Parameters<TFn>) => debouncer.maybeExecute(...args)
46
- }
@@ -1,94 +0,0 @@
1
- import { signal } from '@angular/core'
2
- import { injectDebouncer } from './injectDebouncer'
3
- import type { AngularDebouncer } from './injectDebouncer'
4
- import type {
5
- DebouncerOptions,
6
- DebouncerState,
7
- } from '@tanstack/pacer/debouncer'
8
-
9
- type Setter<T> = (value: T | ((prev: T) => T)) => void
10
-
11
- export interface DebouncedSignal<TValue, TSelected = {}> {
12
- (): TValue
13
- set: Setter<TValue>
14
- debouncer: AngularDebouncer<Setter<TValue>, TSelected>
15
- }
16
-
17
- /**
18
- * An Angular function that creates a debounced state signal, combining Angular's signal with debouncing functionality.
19
- * This function provides both the current debounced value and methods to update it.
20
- *
21
- * The state value is only updated after the specified wait time has elapsed since the last update attempt.
22
- * If another update is attempted before the wait time expires, the timer resets and starts waiting again.
23
- * This is useful for handling frequent state updates that should be throttled, like search input values
24
- * or window resize dimensions.
25
- *
26
- * The function returns a callable object:
27
- * - `debounced()`: Get the current debounced value
28
- * - `debounced.set(...)`: Set or update the debounced value (debounced via maybeExecute)
29
- * - `debounced.debouncer`: The debouncer instance with additional control methods and state signals
30
- *
31
- * ## State Management and Selector
32
- *
33
- * The function uses TanStack Store for reactive state management via the underlying debouncer instance.
34
- * The `selector` parameter allows you to specify which debouncer state changes will trigger signal updates,
35
- * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
36
- *
37
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
38
- * tracking by providing a selector function. This prevents unnecessary updates and gives you
39
- * full control over when your component tracks state changes. Only when you provide a selector will
40
- * the reactive system track the selected state values.
41
- *
42
- * Available debouncer state properties:
43
- * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
44
- * - `executionCount`: Number of function executions that have been completed
45
- * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
46
- * - `lastArgs`: The arguments from the most recent call to maybeExecute
47
- * - `status`: Current execution status ('disabled' | 'idle' | 'pending')
48
- *
49
- * @example
50
- * ```ts
51
- * const debouncedQuery = injectDebouncedSignal('', { wait: 500 })
52
- *
53
- * // Get value
54
- * console.log(debouncedQuery())
55
- *
56
- * // Set/update value (debounced)
57
- * debouncedQuery.set('hello')
58
- *
59
- * // Access debouncer
60
- * console.log(debouncedQuery.debouncer.state().isPending)
61
- * ```
62
- */
63
- export function injectDebouncedSignal<TValue, TSelected = {}>(
64
- value: TValue,
65
- initialOptions: DebouncerOptions<Setter<TValue>>,
66
- selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,
67
- ): DebouncedSignal<TValue, TSelected> {
68
- const debouncedValue = signal<TValue>(value)
69
-
70
- const debouncer = injectDebouncer(
71
- (newValue: TValue | ((prev: TValue) => TValue)) => {
72
- if (typeof newValue === 'function') {
73
- debouncedValue.update(newValue as (prev: TValue) => TValue)
74
- } else {
75
- debouncedValue.set(newValue)
76
- }
77
- },
78
- initialOptions,
79
- selector,
80
- )
81
-
82
- const set: Setter<TValue> = (
83
- newValue: TValue | ((prev: TValue) => TValue),
84
- ) => {
85
- debouncer.maybeExecute(newValue)
86
- }
87
-
88
- const debounced = Object.assign(() => debouncedValue(), {
89
- set,
90
- debouncer,
91
- }) as DebouncedSignal<TValue, TSelected>
92
-
93
- return debounced
94
- }
@@ -1,126 +0,0 @@
1
- import { effect } from '@angular/core'
2
- import { injectDebouncedSignal } from './injectDebouncedSignal'
3
- import type { DebouncedSignal } from './injectDebouncedSignal'
4
- import type { Signal } from '@angular/core'
5
- import type {
6
- DebouncerOptions,
7
- DebouncerState,
8
- } from '@tanstack/pacer/debouncer'
9
-
10
- type Setter<T> = (value: T | ((prev: T) => T)) => void
11
-
12
- /**
13
- * An Angular function that creates a debounced value that updates only after a specified delay.
14
- * Unlike injectDebouncedSignal, this function automatically tracks changes to the input signal
15
- * and updates the debounced value accordingly.
16
- *
17
- * The debounced value will only update after the specified wait time has elapsed since
18
- * the last change to the input value. If the input value changes again before the wait
19
- * time expires, the timer resets and starts waiting again.
20
- *
21
- * This is useful for deriving debounced values from signals that change frequently,
22
- * like search queries or form inputs, where you want to limit how often downstream effects
23
- * or calculations occur.
24
- *
25
- * The function returns a tuple containing:
26
- * - A Signal that provides the current debounced value
27
- * - The debouncer instance with control methods
28
- *
29
- * ## State Management and Selector
30
- *
31
- * The function uses TanStack Store for reactive state management via the underlying debouncer instance.
32
- * The `selector` parameter allows you to specify which debouncer state changes will trigger signal updates,
33
- * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
34
- *
35
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
36
- * tracking by providing a selector function. This prevents unnecessary updates and gives you
37
- * full control over when your component tracks state changes. Only when you provide a selector will
38
- * the reactive system track the selected state values.
39
- *
40
- * Available debouncer state properties:
41
- * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
42
- * - `executionCount`: Number of function executions that have been completed
43
- * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
44
- * - `lastArgs`: The arguments from the most recent call to maybeExecute
45
- * - `status`: Current execution status ('disabled' | 'idle' | 'pending')
46
- *
47
- *
48
- * @example
49
- * ```ts
50
- * // Default behavior - no reactive state subscriptions
51
- * const searchQuery = signal('')
52
- * const debounced = injectDebouncedValue(searchQuery, {
53
- * wait: 500, // Wait 500ms after last change
54
- * })
55
- *
56
- * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)
57
- * const debouncedWithPending = injectDebouncedValue(
58
- * searchQuery,
59
- * { wait: 500 },
60
- * (state) => ({ isPending: state.isPending }),
61
- * )
62
- *
63
- * // Debounced value will update 500ms after searchQuery stops changing
64
- * effect(() => {
65
- * fetchSearchResults(debounced())
66
- * })
67
- *
68
- * // Access selected debouncer state via signals (only if you provided a selector)
69
- * effect(() => {
70
- * console.log('Is pending:', debouncedWithPending.state().isPending)
71
- * })
72
- *
73
- * // Control the debouncer
74
- * debounced.cancel() // Cancel any pending updates
75
- * ```
76
- */
77
- export function injectDebouncedValue<TValue, TSelected = {}>(
78
- value: Signal<TValue>,
79
- initialOptions: DebouncerOptions<Setter<TValue>>,
80
- selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,
81
- ): DebouncedSignal<TValue, TSelected>
82
- export function injectDebouncedValue<TValue, TSelected = {}>(
83
- value: Signal<TValue>,
84
- initialValue: TValue,
85
- initialOptions: DebouncerOptions<Setter<TValue>>,
86
- selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,
87
- ): DebouncedSignal<TValue, TSelected>
88
- export function injectDebouncedValue<TValue, TSelected = {}>(
89
- value: Signal<TValue>,
90
- initialValueOrOptions: TValue | DebouncerOptions<Setter<TValue>>,
91
- initialOptionsOrSelector?:
92
- | DebouncerOptions<Setter<TValue>>
93
- | ((state: DebouncerState<Setter<TValue>>) => TSelected),
94
- maybeSelector?: (state: DebouncerState<Setter<TValue>>) => TSelected,
95
- ): DebouncedSignal<TValue, TSelected> {
96
- const hasSelector = typeof initialOptionsOrSelector === 'function'
97
-
98
- const hasInitialValue =
99
- (initialOptionsOrSelector !== undefined && !hasSelector) ||
100
- maybeSelector !== undefined
101
-
102
- const initialValue = hasInitialValue
103
- ? (initialValueOrOptions as TValue)
104
- : (undefined as unknown as TValue)
105
- const initialOptions = hasInitialValue
106
- ? (initialOptionsOrSelector as DebouncerOptions<Setter<TValue>>)
107
- : (initialValueOrOptions as DebouncerOptions<Setter<TValue>>)
108
- const selector = hasInitialValue
109
- ? maybeSelector
110
- : (initialOptionsOrSelector as
111
- | ((state: DebouncerState<Setter<TValue>>) => TSelected)
112
- | undefined)
113
-
114
- const debounced = injectDebouncedSignal(
115
- initialValue,
116
- initialOptions,
117
- selector,
118
- )
119
-
120
- effect(() => {
121
- const latest = value()
122
- debounced.set(latest)
123
- })
124
-
125
- return debounced
126
- }
@@ -1,137 +0,0 @@
1
- import { DestroyRef, inject } from '@angular/core'
2
- import { injectSelector } from '@tanstack/angular-store'
3
- import { Debouncer } from '@tanstack/pacer/debouncer'
4
- import { injectPacerOptions } from '../provider/pacer-context'
5
- import type { Signal } from '@angular/core'
6
- import type { Store } from '@tanstack/angular-store'
7
- import type { AnyFunction } from '@tanstack/pacer/types'
8
- import type {
9
- DebouncerOptions,
10
- DebouncerState,
11
- } from '@tanstack/pacer/debouncer'
12
-
13
- export interface AngularDebouncerOptions<
14
- TFn extends AnyFunction,
15
- TSelected = {},
16
- > extends DebouncerOptions<TFn> {
17
- /**
18
- * Optional callback invoked when the component is destroyed. Receives the debouncer instance.
19
- * When provided, replaces the default cleanup (cancel); use it to call flush(), cancel(), add logging, etc.
20
- */
21
- onUnmount?: (debouncer: AngularDebouncer<TFn, TSelected>) => void
22
- }
23
-
24
- export interface AngularDebouncer<
25
- TFn extends AnyFunction,
26
- TSelected = {},
27
- > extends Omit<Debouncer<TFn>, 'store'> {
28
- /**
29
- * Reactive state signal that will be updated when the debouncer state changes
30
- *
31
- * Use this instead of `debouncer.store.state`
32
- */
33
- readonly state: Signal<Readonly<TSelected>>
34
- /**
35
- * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.
36
- * The state on the store object is not reactive in Angular signals.
37
- */
38
- readonly store: Store<Readonly<DebouncerState<TFn>>>
39
- }
40
-
41
- /**
42
- * An Angular function that creates and manages a Debouncer instance.
43
- *
44
- * This is a lower-level function that provides direct access to the Debouncer's functionality.
45
- * This allows you to integrate it with any state management solution you prefer.
46
- *
47
- * This function provides debouncing functionality to limit how often a function can be called,
48
- * waiting for a specified delay before executing the latest call. This is useful for handling
49
- * frequent events like window resizing, scroll events, or real-time search inputs.
50
- *
51
- * The debouncer will only execute the function after the specified wait time has elapsed
52
- * since the last call. If the function is called again before the wait time expires, the
53
- * timer resets and starts waiting again.
54
- *
55
- * ## State Management and Selector
56
- *
57
- * The function uses TanStack Store for state management and wraps it with Angular signals.
58
- * The `selector` parameter allows you to specify which state changes will trigger signal updates,
59
- * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
60
- *
61
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
62
- * tracking by providing a selector function. This prevents unnecessary updates and gives you
63
- * full control over when your component tracks state changes.
64
- *
65
- * Available state properties:
66
- * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
67
- * - `executionCount`: Number of function executions that have been completed
68
- * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
69
- * - `lastArgs`: The arguments from the most recent call to maybeExecute
70
- * - `status`: Current execution status ('disabled' | 'idle' | 'pending')
71
- *
72
- * ## Cleanup on Destroy
73
- *
74
- * By default, the function cancels any pending execution when the component is destroyed.
75
- * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
76
- *
77
- * ```ts
78
- * const debouncer = injectDebouncer(fn, {
79
- * wait: 500,
80
- * onUnmount: (d) => d.flush()
81
- * });
82
- * ```
83
- *
84
- * @example
85
- * ```ts
86
- * // Default behavior - no reactive state subscriptions
87
- * const debouncer = injectDebouncer(
88
- * (query: string) => fetchSearchResults(query),
89
- * { wait: 500 }
90
- * );
91
- *
92
- * // Opt-in to track isPending changes (optimized for loading states)
93
- * const debouncer = injectDebouncer(
94
- * (query: string) => fetchSearchResults(query),
95
- * { wait: 500 },
96
- * (state) => ({ isPending: state.isPending })
97
- * );
98
- *
99
- * // In an event handler
100
- * const handleChange = (e: Event) => {
101
- * const target = e.target as HTMLInputElement
102
- * debouncer.maybeExecute(target.value);
103
- * };
104
- *
105
- * // Access the selected state (will be empty object {} unless selector provided)
106
- * const { isPending } = debouncer.state();
107
- * ```
108
- */
109
- export function injectDebouncer<TFn extends AnyFunction, TSelected = {}>(
110
- fn: TFn,
111
- options: AngularDebouncerOptions<TFn, TSelected>,
112
- selector: (state: DebouncerState<TFn>) => TSelected = () => ({}) as TSelected,
113
- ): AngularDebouncer<TFn, TSelected> {
114
- const mergedOptions = {
115
- ...injectPacerOptions().debouncer,
116
- ...options,
117
- } as AngularDebouncerOptions<TFn, TSelected>
118
-
119
- const debouncer = new Debouncer<TFn>(fn, mergedOptions)
120
- const state = injectSelector(debouncer.store, selector)
121
-
122
- const result = {
123
- ...debouncer,
124
- state,
125
- } as AngularDebouncer<TFn, TSelected>
126
-
127
- const destroyRef = inject(DestroyRef, { optional: true })
128
- destroyRef?.onDestroy(() => {
129
- if (mergedOptions.onUnmount) {
130
- mergedOptions.onUnmount(result)
131
- } else {
132
- debouncer.cancel()
133
- }
134
- })
135
-
136
- return result
137
- }
package/src/index.ts DELETED
@@ -1,40 +0,0 @@
1
- export * from '@tanstack/pacer'
2
-
3
- export * from './provider/pacer-provider'
4
-
5
- export * from './async-batcher/injectAsyncBatchedCallback'
6
- export * from './async-batcher/injectAsyncBatcher'
7
-
8
- export * from './async-debouncer/injectAsyncDebouncedCallback'
9
- export * from './async-debouncer/injectAsyncDebouncer'
10
-
11
- export * from './async-queuer/injectAsyncQueuedSignal'
12
- export * from './async-queuer/injectAsyncQueuer'
13
-
14
- export * from './async-rate-limiter/injectAsyncRateLimitedCallback'
15
- export * from './async-rate-limiter/injectAsyncRateLimiter'
16
-
17
- export * from './async-throttler/injectAsyncThrottledCallback'
18
- export * from './async-throttler/injectAsyncThrottler'
19
-
20
- export * from './batcher/injectBatchedCallback'
21
- export * from './batcher/injectBatcher'
22
-
23
- export * from './debouncer/injectDebouncedCallback'
24
- export * from './debouncer/injectDebouncedSignal'
25
- export * from './debouncer/injectDebouncedValue'
26
- export * from './debouncer/injectDebouncer'
27
-
28
- export * from './queuer/injectQueuedSignal'
29
- export * from './queuer/injectQueuedValue'
30
- export * from './queuer/injectQueuer'
31
-
32
- export * from './rate-limiter/injectRateLimitedCallback'
33
- export * from './rate-limiter/injectRateLimitedSignal'
34
- export * from './rate-limiter/injectRateLimitedValue'
35
- export * from './rate-limiter/injectRateLimiter'
36
-
37
- export * from './throttler/injectThrottledCallback'
38
- export * from './throttler/injectThrottledSignal'
39
- export * from './throttler/injectThrottledValue'
40
- export * from './throttler/injectThrottler'
@@ -1,2 +0,0 @@
1
- export * from './pacer-context'
2
- export * from './pacer-provider'
@@ -1,46 +0,0 @@
1
- import { InjectionToken, inject } from '@angular/core'
2
- import type {
3
- AnyAsyncFunction,
4
- AnyFunction,
5
- AsyncBatcherOptions,
6
- AsyncDebouncerOptions,
7
- AsyncQueuerOptions,
8
- AsyncRateLimiterOptions,
9
- AsyncThrottlerOptions,
10
- BatcherOptions,
11
- DebouncerOptions,
12
- QueuerOptions,
13
- RateLimiterOptions,
14
- ThrottlerOptions,
15
- } from '@tanstack/pacer'
16
-
17
- export interface PacerProviderOptions {
18
- asyncBatcher?: Partial<AsyncBatcherOptions<any>>
19
- asyncDebouncer?: Partial<AsyncDebouncerOptions<AnyAsyncFunction>>
20
- asyncQueuer?: Partial<AsyncQueuerOptions<any>>
21
- asyncRateLimiter?: Partial<AsyncRateLimiterOptions<AnyAsyncFunction>>
22
- asyncThrottler?: Partial<AsyncThrottlerOptions<AnyAsyncFunction>>
23
- batcher?: Partial<BatcherOptions<any>>
24
- debouncer?: Partial<DebouncerOptions<AnyFunction>>
25
- queuer?: Partial<QueuerOptions<any>>
26
- rateLimiter?: Partial<RateLimiterOptions<AnyFunction>>
27
- throttler?: Partial<ThrottlerOptions<AnyFunction>>
28
- }
29
-
30
- const DEFAULT_OPTIONS: PacerProviderOptions = {}
31
-
32
- export const PACER_OPTIONS = new InjectionToken<PacerProviderOptions>(
33
- 'PACER_OPTIONS',
34
- {
35
- providedIn: 'root',
36
- factory: () => DEFAULT_OPTIONS,
37
- },
38
- )
39
-
40
- export function injectPacerOptions(): PacerProviderOptions {
41
- try {
42
- return inject(PACER_OPTIONS, { optional: true }) ?? DEFAULT_OPTIONS
43
- } catch {
44
- return DEFAULT_OPTIONS
45
- }
46
- }
@@ -1,38 +0,0 @@
1
- import { PACER_OPTIONS } from './pacer-context'
2
- import type { Provider } from '@angular/core'
3
- import type { PacerProviderOptions } from './pacer-context'
4
-
5
- /**
6
- * Provides default options for all Pacer utilities in the Angular application.
7
- * Use this function when configuring your Angular application to set default options
8
- * that will be used by all Pacer utilities throughout your app.
9
- *
10
- * @example
11
- * ```ts
12
- * // In your app.config.ts (standalone)
13
- * export const appConfig: ApplicationConfig = {
14
- * providers: [
15
- * providePacerOptions({
16
- * debouncer: { wait: 300 },
17
- * throttler: { wait: 100 },
18
- * }),
19
- * ],
20
- * };
21
- *
22
- * // Or in NgModule (module-based)
23
- * @NgModule({
24
- * providers: [
25
- * providePacerOptions({
26
- * debouncer: { wait: 300 },
27
- * }),
28
- * ],
29
- * })
30
- * export class AppModule {}
31
- * ```
32
- */
33
- export function providePacerOptions(options: PacerProviderOptions): Provider {
34
- return {
35
- provide: PACER_OPTIONS,
36
- useValue: options,
37
- }
38
- }
@@ -1,5 +0,0 @@
1
- export * from '@tanstack/pacer/queuer'
2
-
3
- export * from './injectQueuedSignal'
4
- export * from './injectQueuedValue'
5
- export * from './injectQueuer'
@@ -1,65 +0,0 @@
1
- import { computed } from '@angular/core'
2
- import { injectQueuer } from './injectQueuer'
3
- import type { AngularQueuer } from './injectQueuer'
4
- import type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'
5
-
6
- export interface QueuedSignal<TValue, TSelected = {}> {
7
- (): Array<TValue>
8
- addItem: AngularQueuer<TValue, TSelected>['addItem']
9
- queuer: AngularQueuer<TValue, TSelected>
10
- }
11
-
12
- /**
13
- * An Angular function that creates a queuer with managed state, combining Angular's signals with queuing functionality.
14
- * This function provides both the current queue state and queue control methods.
15
- *
16
- * The queue state is automatically updated whenever items are added, removed, or reordered in the queue.
17
- * All queue operations are reflected in the state array returned by the function.
18
- *
19
- * The function returns a callable object:
20
- * - `queued()`: Get the current queue items as an array
21
- * - `queued.addItem(...)`: Add an item to the queue
22
- * - `queued.queue`: The queuer instance with additional control methods
23
- *
24
- * @example
25
- * ```ts
26
- * // Default behavior - track items
27
- * const queued = injectQueuedSignal(
28
- * (item) => console.log('Processing:', item),
29
- * { started: true, wait: 1000 }
30
- * );
31
- *
32
- * // Add items
33
- * queued.addItem('task1');
34
- *
35
- * // Access items
36
- * console.log(queued()); // ['task1']
37
- *
38
- * // Control the queue
39
- * queued.queuer.start();
40
- * queued.queuer.stop();
41
- * ```
42
- */
43
- export function injectQueuedSignal<
44
- TValue,
45
- TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<
46
- QueuerState<TValue>,
47
- 'items'
48
- >,
49
- >(
50
- fn: (item: TValue) => void,
51
- options: QueuerOptions<TValue> = {},
52
- selector: (state: QueuerState<TValue>) => TSelected = (state) =>
53
- ({ items: state.items }) as TSelected,
54
- ): QueuedSignal<TValue, TSelected> {
55
- const queuer = injectQueuer(fn, options, selector)
56
-
57
- const items = computed(() => queuer.state().items as Array<TValue>)
58
-
59
- const queued = Object.assign(items, {
60
- addItem: queuer.addItem.bind(queuer),
61
- queuer,
62
- }) as QueuedSignal<TValue, TSelected>
63
-
64
- return queued
65
- }