@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,101 +0,0 @@
1
- import { effect, linkedSignal, signal } from '@angular/core'
2
- import { injectQueuedSignal } from './injectQueuedSignal'
3
- import type { QueuedSignal } from './injectQueuedSignal'
4
- import type { Signal } from '@angular/core'
5
- import type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'
6
-
7
- /**
8
- * An Angular function that creates a queued value that processes state changes in order with an optional delay.
9
- * This function uses injectQueuedSignal internally to manage a queue of state changes and apply them sequentially.
10
- *
11
- * The queued value will process changes in the order they are received, with optional delays between
12
- * processing each change. This is useful for handling state updates that need to be processed
13
- * in a specific order, like animations or sequential UI updates.
14
- *
15
- * The function returns a tuple containing:
16
- * - A Signal that provides the current queued value
17
- * - The queuer instance with control methods
18
- *
19
- * @example
20
- * ```ts
21
- * const initialValue = signal('initial')
22
- * const queued = injectQueuedValue(initialValue, {
23
- * wait: 500,
24
- * started: true,
25
- * })
26
- *
27
- * // Add changes to the queue
28
- * queued.addItem('new value')
29
- * ```
30
- */
31
- export function injectQueuedValue<
32
- TValue,
33
- TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<
34
- QueuerState<TValue>,
35
- 'items'
36
- >,
37
- >(
38
- value: Signal<TValue>,
39
- options?: QueuerOptions<TValue>,
40
- selector?: (state: QueuerState<TValue>) => TSelected,
41
- ): QueuedSignal<TValue, TSelected>
42
- export function injectQueuedValue<
43
- TValue,
44
- TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<
45
- QueuerState<TValue>,
46
- 'items'
47
- >,
48
- >(
49
- value: Signal<TValue>,
50
- initialValue: TValue,
51
- options?: QueuerOptions<TValue>,
52
- selector?: (state: QueuerState<TValue>) => TSelected,
53
- ): QueuedSignal<TValue, TSelected>
54
- export function injectQueuedValue<
55
- TValue,
56
- TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<
57
- QueuerState<TValue>,
58
- 'items'
59
- >,
60
- >(
61
- value: Signal<TValue>,
62
- initialValueOrOptions?: TValue | QueuerOptions<TValue>,
63
- initialOptionsOrSelector?:
64
- | QueuerOptions<TValue>
65
- | ((state: QueuerState<TValue>) => TSelected),
66
- maybeSelector?: (state: QueuerState<TValue>) => TSelected,
67
- ): QueuedSignal<TValue, TSelected> {
68
- const hasSelector = typeof initialOptionsOrSelector === 'function'
69
- const hasInitialValue =
70
- (initialOptionsOrSelector !== undefined && !hasSelector) ||
71
- maybeSelector !== undefined
72
-
73
- const initialValue = hasInitialValue
74
- ? (initialValueOrOptions as TValue)
75
- : value()
76
- const initialOptions = hasInitialValue
77
- ? (initialOptionsOrSelector as QueuerOptions<TValue>)
78
- : (initialValueOrOptions as QueuerOptions<TValue>)
79
- const selector = hasInitialValue
80
- ? maybeSelector
81
- : (initialOptionsOrSelector as
82
- | ((state: QueuerState<TValue>) => TSelected)
83
- | undefined)
84
-
85
- const linkedValue = linkedSignal(() => value())
86
- const queuedValue = signal<TValue>(initialValue)
87
-
88
- const queued = injectQueuedSignal(
89
- (item) => {
90
- queuedValue.set(item)
91
- },
92
- initialOptions,
93
- selector,
94
- )
95
-
96
- effect(() => {
97
- queued.addItem(linkedValue())
98
- })
99
-
100
- return queued
101
- }
@@ -1,118 +0,0 @@
1
- import { DestroyRef, inject } from '@angular/core'
2
- import { injectSelector } from '@tanstack/angular-store'
3
- import { Queuer } from '@tanstack/pacer/queuer'
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 { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'
8
-
9
- export interface AngularQueuerOptions<
10
- TValue,
11
- TSelected = {},
12
- > extends QueuerOptions<TValue> {
13
- /**
14
- * Optional callback invoked when the component is destroyed. Receives the queuer instance.
15
- * When provided, replaces the default cleanup (stop); use it to call flush(), stop(), add logging, etc.
16
- */
17
- onUnmount?: (queuer: AngularQueuer<TValue, TSelected>) => void
18
- }
19
-
20
- export interface AngularQueuer<TValue, TSelected = {}> extends Omit<
21
- Queuer<TValue>,
22
- 'store'
23
- > {
24
- /**
25
- * Reactive state signal that will be updated when the queuer state changes
26
- *
27
- * Use this instead of `queuer.store.state`
28
- */
29
- readonly state: Signal<Readonly<TSelected>>
30
- /**
31
- * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.
32
- * The state on the store object is not reactive in Angular signals.
33
- */
34
- readonly store: Store<Readonly<QueuerState<TValue>>>
35
- }
36
-
37
- /**
38
- * An Angular function that creates and manages a Queuer instance.
39
- *
40
- * This is a lower-level function that provides direct access to the Queuer's functionality.
41
- * This allows you to integrate it with any state management solution you prefer.
42
- *
43
- * The Queuer processes items synchronously in order, with optional delays between processing each item.
44
- * The queuer includes an internal tick mechanism that can be started and stopped, making it useful as a scheduler.
45
- *
46
- * ## State Management and Selector
47
- *
48
- * The function uses TanStack Store for state management and wraps it with Angular signals.
49
- * The `selector` parameter allows you to specify which state changes will trigger signal updates,
50
- * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
51
- *
52
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
53
- * tracking by providing a selector function. This prevents unnecessary updates and gives you
54
- * full control over when your component tracks state changes.
55
- *
56
- * @example
57
- * ```ts
58
- * // Default behavior - no reactive state subscriptions
59
- * const queue = injectQueuer(
60
- * (item) => console.log('Processing:', item),
61
- * { started: true, wait: 1000 }
62
- * );
63
- *
64
- * // Opt-in to track queue contents changes
65
- * const queue = injectQueuer(
66
- * (item) => console.log('Processing:', item),
67
- * { started: true, wait: 1000 },
68
- * (state) => ({ items: state.items, size: state.size })
69
- * );
70
- *
71
- * // Add items
72
- * queue.addItem('task1');
73
- *
74
- * // Access the selected state
75
- * const { items, isRunning } = queue.state();
76
- * ```
77
- *
78
- * ## Cleanup on Destroy
79
- *
80
- * By default, the function stops the queuer when the component is destroyed.
81
- * Use the `onUnmount` option to customize this. For example, to flush pending items instead:
82
- *
83
- * ```ts
84
- * const queue = injectQueuer(fn, {
85
- * started: true,
86
- * onUnmount: (q) => q.flush()
87
- * });
88
- * ```
89
- */
90
- export function injectQueuer<TValue, TSelected = {}>(
91
- fn: (item: TValue) => void,
92
- options: AngularQueuerOptions<TValue, TSelected> = {},
93
- selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,
94
- ): AngularQueuer<TValue, TSelected> {
95
- const mergedOptions = {
96
- ...injectPacerOptions().queuer,
97
- ...options,
98
- } as AngularQueuerOptions<TValue, TSelected>
99
-
100
- const queuer = new Queuer<TValue>(fn, mergedOptions)
101
- const state = injectSelector(queuer.store, selector)
102
-
103
- const result = {
104
- ...queuer,
105
- state,
106
- } as AngularQueuer<TValue, TSelected>
107
-
108
- const destroyRef = inject(DestroyRef, { optional: true })
109
- destroyRef?.onDestroy(() => {
110
- if (mergedOptions.onUnmount) {
111
- mergedOptions.onUnmount(result)
112
- } else {
113
- queuer.stop()
114
- }
115
- })
116
-
117
- return result
118
- }
@@ -1,6 +0,0 @@
1
- export * from '@tanstack/pacer/rate-limiter'
2
-
3
- export * from './injectRateLimitedCallback'
4
- export * from './injectRateLimitedSignal'
5
- export * from './injectRateLimitedValue'
6
- export * from './injectRateLimiter'
@@ -1,45 +0,0 @@
1
- import { injectRateLimiter } from './injectRateLimiter'
2
- import type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'
3
- import type { AnyFunction } from '@tanstack/pacer/types'
4
-
5
- /**
6
- * An Angular function that creates a rate-limited version of a callback function.
7
- * This function is essentially a wrapper around `injectRateLimiter` that provides
8
- * a simplified API for basic rate limiting needs.
9
- *
10
- * Rate limiting is a simple "hard limit" approach - it allows all calls until the limit
11
- * is reached, then blocks subsequent calls until the window resets. Unlike throttling
12
- * or debouncing, it does not attempt to space out or intelligently collapse calls.
13
- *
14
- * This function provides a simpler API compared to `injectRateLimiter`, making it ideal for basic
15
- * rate limiting needs. However, it does not expose the underlying RateLimiter instance.
16
- *
17
- * For advanced usage requiring features like:
18
- * - Manual cancellation/reset
19
- * - Access to execution counts
20
- * - State tracking
21
- *
22
- * Consider using the `injectRateLimiter` function instead.
23
- *
24
- * @example
25
- * ```ts
26
- * // Rate limit API calls to maximum 5 calls per minute
27
- * const makeApiCall = injectRateLimitedCallback(
28
- * (data: ApiData) => {
29
- * return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) });
30
- * },
31
- * {
32
- * limit: 5,
33
- * window: 60000, // 1 minute
34
- * windowType: 'sliding',
35
- * }
36
- * );
37
- * ```
38
- */
39
- export function injectRateLimitedCallback<TFn extends AnyFunction>(
40
- fn: TFn,
41
- options: RateLimiterOptions<TFn>,
42
- ): (...args: Parameters<TFn>) => boolean {
43
- const rateLimiter = injectRateLimiter(fn, options)
44
- return (...args: Parameters<TFn>) => rateLimiter.maybeExecute(...args)
45
- }
@@ -1,88 +0,0 @@
1
- import { signal } from '@angular/core'
2
- import { injectRateLimiter } from './injectRateLimiter'
3
- import type { AngularRateLimiter } from './injectRateLimiter'
4
- import type {
5
- RateLimiterOptions,
6
- RateLimiterState,
7
- } from '@tanstack/pacer/rate-limiter'
8
-
9
- type Setter<T> = (value: T | ((prev: T) => T)) => void
10
-
11
- export interface RateLimitedSignal<TValue, TSelected = {}> {
12
- (): TValue
13
- set: Setter<TValue>
14
- rateLimiter: AngularRateLimiter<Setter<TValue>, TSelected>
15
- }
16
-
17
- /**
18
- * An Angular function that creates a rate-limited state signal, combining Angular's signal with rate limiting functionality.
19
- * This function provides both the current rate-limited value and methods to update it.
20
- *
21
- * Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks
22
- * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out
23
- * or intelligently collapse updates.
24
- *
25
- * The function returns a callable object:
26
- * - `rateLimited()`: Get the current rate-limited value
27
- * - `rateLimited.set(...)`: Set or update the rate-limited value (rate-limited via maybeExecute)
28
- * - `rateLimited.rateLimiter`: The rate limiter instance with additional control methods and state signals
29
- *
30
- * ## State Management and Selector
31
- *
32
- * The function uses TanStack Store for reactive state management via the underlying rate limiter instance.
33
- * The `selector` parameter allows you to specify which rate limiter state changes will trigger signal updates,
34
- * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
35
- *
36
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
37
- * tracking by providing a selector function. This prevents unnecessary updates and gives you
38
- * full control over when your component tracks state changes.
39
- *
40
- * @example
41
- * ```ts
42
- * // Default behavior - no reactive state subscriptions
43
- * const rateLimited = injectRateLimitedSignal(0, {
44
- * limit: 5,
45
- * window: 60000,
46
- * windowType: 'sliding'
47
- * });
48
- *
49
- * // Opt-in to reactive updates when limit state changes
50
- * const rateLimited = injectRateLimitedSignal(
51
- * 0,
52
- * { limit: 5, window: 60000 },
53
- * (state) => ({ rejectionCount: state.rejectionCount })
54
- * );
55
- * ```
56
- */
57
- export function injectRateLimitedSignal<TValue, TSelected = {}>(
58
- value: TValue,
59
- initialOptions: RateLimiterOptions<Setter<TValue>>,
60
- selector?: (state: RateLimiterState) => TSelected,
61
- ): RateLimitedSignal<TValue, TSelected> {
62
- const rateLimitedValue = signal<TValue>(value)
63
-
64
- const rateLimiter = injectRateLimiter(
65
- (newValue: TValue | ((prev: TValue) => TValue)) => {
66
- if (typeof newValue === 'function') {
67
- rateLimitedValue.update(newValue as (prev: TValue) => TValue)
68
- } else {
69
- rateLimitedValue.set(newValue)
70
- }
71
- },
72
- initialOptions,
73
- selector,
74
- )
75
-
76
- const set: Setter<TValue> = (
77
- newValue: TValue | ((prev: TValue) => TValue),
78
- ) => {
79
- rateLimiter.maybeExecute(newValue)
80
- }
81
-
82
- const rateLimited = Object.assign(() => rateLimitedValue(), {
83
- set,
84
- rateLimiter,
85
- }) as RateLimitedSignal<TValue, TSelected>
86
-
87
- return rateLimited
88
- }
@@ -1,99 +0,0 @@
1
- import { effect } from '@angular/core'
2
- import { injectRateLimitedSignal } from './injectRateLimitedSignal'
3
- import type { RateLimitedSignal } from './injectRateLimitedSignal'
4
- import type { Signal } from '@angular/core'
5
- import type {
6
- RateLimiterOptions,
7
- RateLimiterState,
8
- } from '@tanstack/pacer/rate-limiter'
9
-
10
- type Setter<T> = (value: T | ((prev: T) => T)) => void
11
-
12
- /**
13
- * An Angular function that creates a rate-limited value that updates at most a certain number of times within a time window.
14
- * Unlike injectRateLimitedSignal, this function automatically tracks changes to the input signal
15
- * and updates the rate-limited value accordingly.
16
- *
17
- * The rate-limited value will update according to the configured rate limit, blocking updates
18
- * once the limit is reached until the window resets.
19
- *
20
- * The function returns a rate-limited signal object containing:
21
- * - A Signal that provides the current rate-limited value
22
- * - The rate limiter instance with control methods
23
- *
24
- * ## State Management and Selector
25
- *
26
- * The function uses TanStack Store for reactive state management via the underlying rate limiter instance.
27
- * The `selector` parameter allows you to specify which rate limiter state changes will trigger signal updates,
28
- * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
29
- *
30
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
31
- * tracking by providing a selector function. This prevents unnecessary updates and gives you
32
- * full control over when your component tracks state changes.
33
- *
34
- * @example
35
- * ```ts
36
- * // Default behavior - no reactive state subscriptions
37
- * const value = signal(0)
38
- * const rateLimited = injectRateLimitedValue(value, {
39
- * limit: 5,
40
- * window: 60000,
41
- * windowType: 'sliding',
42
- * })
43
- *
44
- * // rateLimited() will update at most 5 times per 60 seconds
45
- * effect(() => {
46
- * updateUI(rateLimited())
47
- * })
48
- * ```
49
- */
50
- export function injectRateLimitedValue<TValue, TSelected = {}>(
51
- value: Signal<TValue>,
52
- initialOptions: RateLimiterOptions<Setter<TValue>>,
53
- selector?: (state: RateLimiterState) => TSelected,
54
- ): RateLimitedSignal<TValue, TSelected>
55
- export function injectRateLimitedValue<TValue, TSelected = {}>(
56
- value: Signal<TValue>,
57
- initialValue: TValue,
58
- initialOptions: RateLimiterOptions<Setter<TValue>>,
59
- selector?: (state: RateLimiterState) => TSelected,
60
- ): RateLimitedSignal<TValue, TSelected>
61
- export function injectRateLimitedValue<TValue, TSelected = {}>(
62
- value: Signal<TValue>,
63
- initialValueOrOptions: TValue | RateLimiterOptions<Setter<TValue>>,
64
- initialOptionsOrSelector?:
65
- | RateLimiterOptions<Setter<TValue>>
66
- | ((state: RateLimiterState) => TSelected),
67
- maybeSelector?: (state: RateLimiterState) => TSelected,
68
- ): RateLimitedSignal<TValue, TSelected> {
69
- const hasSelector = typeof initialOptionsOrSelector === 'function'
70
-
71
- const hasInitialValue =
72
- (initialOptionsOrSelector !== undefined && !hasSelector) ||
73
- maybeSelector !== undefined
74
-
75
- const initialValue = hasInitialValue
76
- ? (initialValueOrOptions as TValue)
77
- : (undefined as unknown as TValue)
78
- const initialOptions = hasInitialValue
79
- ? (initialOptionsOrSelector as RateLimiterOptions<Setter<TValue>>)
80
- : (initialValueOrOptions as RateLimiterOptions<Setter<TValue>>)
81
- const selector = hasInitialValue
82
- ? maybeSelector
83
- : (initialOptionsOrSelector as
84
- | ((state: RateLimiterState) => TSelected)
85
- | undefined)
86
-
87
- const rateLimited = injectRateLimitedSignal(
88
- initialValue,
89
- initialOptions,
90
- selector,
91
- )
92
-
93
- effect(() => {
94
- const latest = value()
95
- rateLimited.set(latest)
96
- })
97
-
98
- return rateLimited
99
- }
@@ -1,140 +0,0 @@
1
- import { DestroyRef, inject } from '@angular/core'
2
- import { injectSelector } from '@tanstack/angular-store'
3
- import { RateLimiter } from '@tanstack/pacer/rate-limiter'
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
- RateLimiterOptions,
10
- RateLimiterState,
11
- } from '@tanstack/pacer/rate-limiter'
12
-
13
- export interface AngularRateLimiterOptions<
14
- TFn extends AnyFunction,
15
- TSelected = {},
16
- > extends RateLimiterOptions<TFn> {
17
- /**
18
- * Optional callback invoked when the component is destroyed. Receives the rate limiter instance.
19
- */
20
- onUnmount?: (rateLimiter: AngularRateLimiter<TFn, TSelected>) => void
21
- }
22
-
23
- export interface AngularRateLimiter<
24
- TFn extends AnyFunction,
25
- TSelected = {},
26
- > extends Omit<RateLimiter<TFn>, 'store'> {
27
- /**
28
- * Reactive state signal that will be updated when the rate limiter state changes
29
- *
30
- * Use this instead of `rateLimiter.store.state`
31
- */
32
- readonly state: Signal<Readonly<TSelected>>
33
- /**
34
- * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.
35
- * The state on the store object is not reactive in Angular signals.
36
- */
37
- readonly store: Store<Readonly<RateLimiterState>>
38
- }
39
-
40
- /**
41
- * An Angular function that creates and manages a RateLimiter instance.
42
- *
43
- * This is a lower-level function that provides direct access to the RateLimiter's functionality.
44
- * This allows you to integrate it with any state management solution you prefer.
45
- *
46
- * Rate limiting is a simple "hard limit" approach that allows executions until a maximum count is reached within
47
- * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,
48
- * it does not attempt to space out or collapse executions intelligently.
49
- *
50
- * The rate limiter supports two types of windows:
51
- * - 'fixed': A strict window that resets after the window period. All executions within the window count
52
- * towards the limit, and the window resets completely after the period.
53
- * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more
54
- * consistent rate of execution over time.
55
- *
56
- * For smoother execution patterns:
57
- * - Use throttling when you want consistent spacing between executions (e.g. UI updates)
58
- * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)
59
- * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)
60
- *
61
- * ## State Management and Selector
62
- *
63
- * The function uses TanStack Store for state management and wraps it with Angular signals.
64
- * The `selector` parameter allows you to specify which state changes will trigger signal updates,
65
- * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
66
- *
67
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
68
- * tracking by providing a selector function. This prevents unnecessary updates and gives you
69
- * full control over when your component tracks state changes.
70
- *
71
- * Available state properties:
72
- * - `executionCount`: Number of function executions that have been completed
73
- * - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations
74
- * - `rejectionCount`: Number of function executions that have been rejected due to rate limiting
75
- *
76
- * ## Cleanup on Destroy
77
- *
78
- * Use the `onUnmount` option to run a callback when the component is destroyed.
79
- *
80
- * @example
81
- * ```ts
82
- * // Default behavior - no reactive state subscriptions
83
- * const rateLimiter = injectRateLimiter(apiCall, {
84
- * limit: 5,
85
- * window: 60000,
86
- * windowType: 'sliding',
87
- * });
88
- *
89
- * // Opt-in to track execution count changes
90
- * const rateLimiter = injectRateLimiter(
91
- * apiCall,
92
- * {
93
- * limit: 5,
94
- * window: 60000,
95
- * windowType: 'sliding',
96
- * },
97
- * (state) => ({ executionCount: state.executionCount })
98
- * );
99
- *
100
- * // Monitor rate limit status
101
- * const handleClick = () => {
102
- * const remaining = rateLimiter.getRemainingInWindow();
103
- * if (remaining > 0) {
104
- * rateLimiter.maybeExecute(data);
105
- * } else {
106
- * showRateLimitWarning();
107
- * }
108
- * };
109
- *
110
- * // Access the selected state (will be empty object {} unless selector provided)
111
- * const { executionCount, rejectionCount } = rateLimiter.state();
112
- * ```
113
- */
114
- export function injectRateLimiter<TFn extends AnyFunction, TSelected = {}>(
115
- fn: TFn,
116
- options: AngularRateLimiterOptions<TFn, TSelected>,
117
- selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,
118
- ): AngularRateLimiter<TFn, TSelected> {
119
- const mergedOptions = {
120
- ...injectPacerOptions().rateLimiter,
121
- ...options,
122
- } as AngularRateLimiterOptions<TFn, TSelected>
123
-
124
- const rateLimiter = new RateLimiter<TFn>(fn, mergedOptions)
125
- const state = injectSelector(rateLimiter.store, selector)
126
-
127
- const result = {
128
- ...rateLimiter,
129
- state,
130
- } as AngularRateLimiter<TFn, TSelected>
131
-
132
- const destroyRef = inject(DestroyRef, { optional: true })
133
- destroyRef?.onDestroy(() => {
134
- if (mergedOptions.onUnmount) {
135
- mergedOptions.onUnmount(result)
136
- }
137
- })
138
-
139
- return result
140
- }
@@ -1,6 +0,0 @@
1
- export * from '@tanstack/pacer/throttler'
2
-
3
- export * from './injectThrottledCallback'
4
- export * from './injectThrottledSignal'
5
- export * from './injectThrottledValue'
6
- export * from './injectThrottler'
@@ -1,45 +0,0 @@
1
- import { injectThrottler } from './injectThrottler'
2
- import type { ThrottlerOptions } from '@tanstack/pacer/throttler'
3
- import type { AnyFunction } from '@tanstack/pacer/types'
4
-
5
- /**
6
- * An Angular function that creates a throttled version of a callback function.
7
- * This function is essentially a wrapper around `injectThrottler` that provides
8
- * a simplified API for basic throttling needs.
9
- *
10
- * The throttled function will execute at most once within the specified wait time.
11
- * If called multiple times within the wait period, only the first call (if leading is enabled)
12
- * or the last call (if trailing is enabled) will execute.
13
- *
14
- * This function provides a simpler API compared to `injectThrottler`, making it ideal for basic
15
- * throttling needs. However, it does not expose the underlying Throttler 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 `injectThrottler` function instead.
23
- *
24
- * @example
25
- * ```ts
26
- * // Throttle a scroll handler
27
- * const handleScroll = injectThrottledCallback((scrollY: number) => {
28
- * updateScrollPosition(scrollY);
29
- * }, {
30
- * wait: 100 // Execute at most once per 100ms
31
- * });
32
- *
33
- * // Use in an event listener
34
- * window.addEventListener('scroll', () => {
35
- * handleScroll(window.scrollY);
36
- * });
37
- * ```
38
- */
39
- export function injectThrottledCallback<TFn extends AnyFunction>(
40
- fn: TFn,
41
- options: ThrottlerOptions<TFn>,
42
- ): (...args: Parameters<TFn>) => void {
43
- const throttler = injectThrottler(fn, options)
44
- return (...args: Parameters<TFn>) => throttler.maybeExecute(...args)
45
- }