@tanstack/angular-pacer 0.20.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.
- package/README.md +165 -0
- package/dist/async-batcher/index.cjs +13 -0
- package/dist/async-batcher/index.d.cts +4 -0
- package/dist/async-batcher/index.d.ts +4 -0
- package/dist/async-batcher/index.js +6 -0
- package/dist/async-batcher/injectAsyncBatchedCallback.cjs +49 -0
- package/dist/async-batcher/injectAsyncBatchedCallback.cjs.map +1 -0
- package/dist/async-batcher/injectAsyncBatchedCallback.d.cts +45 -0
- package/dist/async-batcher/injectAsyncBatchedCallback.d.ts +45 -0
- package/dist/async-batcher/injectAsyncBatchedCallback.js +49 -0
- package/dist/async-batcher/injectAsyncBatchedCallback.js.map +1 -0
- package/dist/async-batcher/injectAsyncBatcher.cjs +61 -0
- package/dist/async-batcher/injectAsyncBatcher.cjs.map +1 -0
- package/dist/async-batcher/injectAsyncBatcher.d.cts +63 -0
- package/dist/async-batcher/injectAsyncBatcher.d.ts +63 -0
- package/dist/async-batcher/injectAsyncBatcher.js +61 -0
- package/dist/async-batcher/injectAsyncBatcher.js.map +1 -0
- package/dist/async-debouncer/index.cjs +13 -0
- package/dist/async-debouncer/index.d.cts +4 -0
- package/dist/async-debouncer/index.d.ts +4 -0
- package/dist/async-debouncer/index.js +6 -0
- package/dist/async-debouncer/injectAsyncDebouncedCallback.cjs +49 -0
- package/dist/async-debouncer/injectAsyncDebouncedCallback.cjs.map +1 -0
- package/dist/async-debouncer/injectAsyncDebouncedCallback.d.cts +43 -0
- package/dist/async-debouncer/injectAsyncDebouncedCallback.d.ts +43 -0
- package/dist/async-debouncer/injectAsyncDebouncedCallback.js +49 -0
- package/dist/async-debouncer/injectAsyncDebouncedCallback.js.map +1 -0
- package/dist/async-debouncer/injectAsyncDebouncer.cjs +83 -0
- package/dist/async-debouncer/injectAsyncDebouncer.cjs.map +1 -0
- package/dist/async-debouncer/injectAsyncDebouncer.d.cts +86 -0
- package/dist/async-debouncer/injectAsyncDebouncer.d.ts +86 -0
- package/dist/async-debouncer/injectAsyncDebouncer.js +83 -0
- package/dist/async-debouncer/injectAsyncDebouncer.js.map +1 -0
- package/dist/async-queuer/index.cjs +13 -0
- package/dist/async-queuer/index.d.cts +4 -0
- package/dist/async-queuer/index.d.ts +4 -0
- package/dist/async-queuer/index.js +6 -0
- package/dist/async-queuer/injectAsyncQueuedSignal.cjs +53 -0
- package/dist/async-queuer/injectAsyncQueuedSignal.cjs.map +1 -0
- package/dist/async-queuer/injectAsyncQueuedSignal.d.cts +55 -0
- package/dist/async-queuer/injectAsyncQueuedSignal.d.ts +55 -0
- package/dist/async-queuer/injectAsyncQueuedSignal.js +53 -0
- package/dist/async-queuer/injectAsyncQueuedSignal.js.map +1 -0
- package/dist/async-queuer/injectAsyncQueuer.cjs +61 -0
- package/dist/async-queuer/injectAsyncQueuer.cjs.map +1 -0
- package/dist/async-queuer/injectAsyncQueuer.d.cts +63 -0
- package/dist/async-queuer/injectAsyncQueuer.d.ts +63 -0
- package/dist/async-queuer/injectAsyncQueuer.js +61 -0
- package/dist/async-queuer/injectAsyncQueuer.js.map +1 -0
- package/dist/async-rate-limiter/index.cjs +13 -0
- package/dist/async-rate-limiter/index.d.cts +4 -0
- package/dist/async-rate-limiter/index.d.ts +4 -0
- package/dist/async-rate-limiter/index.js +6 -0
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.cjs +52 -0
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.cjs.map +1 -0
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.d.cts +46 -0
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.d.ts +46 -0
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.js +52 -0
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.js.map +1 -0
- package/dist/async-rate-limiter/injectAsyncRateLimiter.cjs +57 -0
- package/dist/async-rate-limiter/injectAsyncRateLimiter.cjs.map +1 -0
- package/dist/async-rate-limiter/injectAsyncRateLimiter.d.cts +60 -0
- package/dist/async-rate-limiter/injectAsyncRateLimiter.d.ts +60 -0
- package/dist/async-rate-limiter/injectAsyncRateLimiter.js +57 -0
- package/dist/async-rate-limiter/injectAsyncRateLimiter.js.map +1 -0
- package/dist/async-retryer/index.cjs +9 -0
- package/dist/async-retryer/index.d.cts +1 -0
- package/dist/async-retryer/index.d.ts +1 -0
- package/dist/async-retryer/index.js +3 -0
- package/dist/async-throttler/index.cjs +13 -0
- package/dist/async-throttler/index.d.cts +4 -0
- package/dist/async-throttler/index.d.ts +4 -0
- package/dist/async-throttler/index.js +6 -0
- package/dist/async-throttler/injectAsyncThrottledCallback.cjs +50 -0
- package/dist/async-throttler/injectAsyncThrottledCallback.cjs.map +1 -0
- package/dist/async-throttler/injectAsyncThrottledCallback.d.cts +44 -0
- package/dist/async-throttler/injectAsyncThrottledCallback.d.ts +44 -0
- package/dist/async-throttler/injectAsyncThrottledCallback.js +50 -0
- package/dist/async-throttler/injectAsyncThrottledCallback.js.map +1 -0
- package/dist/async-throttler/injectAsyncThrottler.cjs +62 -0
- package/dist/async-throttler/injectAsyncThrottler.cjs.map +1 -0
- package/dist/async-throttler/injectAsyncThrottler.d.cts +65 -0
- package/dist/async-throttler/injectAsyncThrottler.d.ts +65 -0
- package/dist/async-throttler/injectAsyncThrottler.js +62 -0
- package/dist/async-throttler/injectAsyncThrottler.js.map +1 -0
- package/dist/batcher/index.cjs +13 -0
- package/dist/batcher/index.d.cts +4 -0
- package/dist/batcher/index.d.ts +4 -0
- package/dist/batcher/index.js +6 -0
- package/dist/batcher/injectBatchedCallback.cjs +47 -0
- package/dist/batcher/injectBatchedCallback.cjs.map +1 -0
- package/dist/batcher/injectBatchedCallback.d.cts +43 -0
- package/dist/batcher/injectBatchedCallback.d.ts +43 -0
- package/dist/batcher/injectBatchedCallback.js +47 -0
- package/dist/batcher/injectBatchedCallback.js.map +1 -0
- package/dist/batcher/injectBatcher.cjs +56 -0
- package/dist/batcher/injectBatcher.cjs.map +1 -0
- package/dist/batcher/injectBatcher.d.cts +58 -0
- package/dist/batcher/injectBatcher.d.ts +58 -0
- package/dist/batcher/injectBatcher.js +56 -0
- package/dist/batcher/injectBatcher.js.map +1 -0
- package/dist/debouncer/index.cjs +17 -0
- package/dist/debouncer/index.d.cts +6 -0
- package/dist/debouncer/index.d.ts +6 -0
- package/dist/debouncer/index.js +8 -0
- package/dist/debouncer/injectDebouncedCallback.cjs +46 -0
- package/dist/debouncer/injectDebouncedCallback.cjs.map +1 -0
- package/dist/debouncer/injectDebouncedCallback.d.cts +43 -0
- package/dist/debouncer/injectDebouncedCallback.d.ts +43 -0
- package/dist/debouncer/injectDebouncedCallback.js +46 -0
- package/dist/debouncer/injectDebouncedCallback.js.map +1 -0
- package/dist/debouncer/injectDebouncedSignal.cjs +68 -0
- package/dist/debouncer/injectDebouncedSignal.cjs.map +1 -0
- package/dist/debouncer/injectDebouncedSignal.d.cts +65 -0
- package/dist/debouncer/injectDebouncedSignal.d.ts +65 -0
- package/dist/debouncer/injectDebouncedSignal.js +68 -0
- package/dist/debouncer/injectDebouncedSignal.js.map +1 -0
- package/dist/debouncer/injectDebouncedValue.cjs +17 -0
- package/dist/debouncer/injectDebouncedValue.cjs.map +1 -0
- package/dist/debouncer/injectDebouncedValue.d.cts +76 -0
- package/dist/debouncer/injectDebouncedValue.d.ts +76 -0
- package/dist/debouncer/injectDebouncedValue.js +17 -0
- package/dist/debouncer/injectDebouncedValue.js.map +1 -0
- package/dist/debouncer/injectDebouncer.cjs +76 -0
- package/dist/debouncer/injectDebouncer.cjs.map +1 -0
- package/dist/debouncer/injectDebouncer.d.cts +79 -0
- package/dist/debouncer/injectDebouncer.d.ts +79 -0
- package/dist/debouncer/injectDebouncer.js +76 -0
- package/dist/debouncer/injectDebouncer.js.map +1 -0
- package/dist/index.cjs +65 -0
- package/dist/index.d.cts +30 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +32 -0
- package/dist/provider/index.cjs +7 -0
- package/dist/provider/index.d.cts +3 -0
- package/dist/provider/index.d.ts +3 -0
- package/dist/provider/index.js +4 -0
- package/dist/provider/pacer-context.cjs +20 -0
- package/dist/provider/pacer-context.cjs.map +1 -0
- package/dist/provider/pacer-context.d.cts +21 -0
- package/dist/provider/pacer-context.d.ts +21 -0
- package/dist/provider/pacer-context.js +19 -0
- package/dist/provider/pacer-context.js.map +1 -0
- package/dist/provider/pacer-provider.cjs +41 -0
- package/dist/provider/pacer-provider.cjs.map +1 -0
- package/dist/provider/pacer-provider.d.cts +36 -0
- package/dist/provider/pacer-provider.d.ts +36 -0
- package/dist/provider/pacer-provider.js +41 -0
- package/dist/provider/pacer-provider.js.map +1 -0
- package/dist/queuer/index.cjs +15 -0
- package/dist/queuer/index.d.cts +5 -0
- package/dist/queuer/index.d.ts +5 -0
- package/dist/queuer/index.js +7 -0
- package/dist/queuer/injectQueuedSignal.cjs +47 -0
- package/dist/queuer/injectQueuedSignal.cjs.map +1 -0
- package/dist/queuer/injectQueuedSignal.d.cts +49 -0
- package/dist/queuer/injectQueuedSignal.d.ts +49 -0
- package/dist/queuer/injectQueuedSignal.js +47 -0
- package/dist/queuer/injectQueuedSignal.js.map +1 -0
- package/dist/queuer/injectQueuedValue.cjs +23 -0
- package/dist/queuer/injectQueuedValue.cjs.map +1 -0
- package/dist/queuer/injectQueuedValue.d.cts +34 -0
- package/dist/queuer/injectQueuedValue.d.ts +34 -0
- package/dist/queuer/injectQueuedValue.js +23 -0
- package/dist/queuer/injectQueuedValue.js.map +1 -0
- package/dist/queuer/injectQueuer.cjs +61 -0
- package/dist/queuer/injectQueuer.cjs.map +1 -0
- package/dist/queuer/injectQueuer.d.cts +63 -0
- package/dist/queuer/injectQueuer.d.ts +63 -0
- package/dist/queuer/injectQueuer.js +61 -0
- package/dist/queuer/injectQueuer.js.map +1 -0
- package/dist/rate-limiter/index.cjs +17 -0
- package/dist/rate-limiter/index.d.cts +6 -0
- package/dist/rate-limiter/index.d.ts +6 -0
- package/dist/rate-limiter/index.js +8 -0
- package/dist/rate-limiter/injectRateLimitedCallback.cjs +45 -0
- package/dist/rate-limiter/injectRateLimitedCallback.cjs.map +1 -0
- package/dist/rate-limiter/injectRateLimitedCallback.d.cts +42 -0
- package/dist/rate-limiter/injectRateLimitedCallback.d.ts +42 -0
- package/dist/rate-limiter/injectRateLimitedCallback.js +45 -0
- package/dist/rate-limiter/injectRateLimitedCallback.js.map +1 -0
- package/dist/rate-limiter/injectRateLimitedSignal.cjs +62 -0
- package/dist/rate-limiter/injectRateLimitedSignal.cjs.map +1 -0
- package/dist/rate-limiter/injectRateLimitedSignal.d.cts +59 -0
- package/dist/rate-limiter/injectRateLimitedSignal.d.ts +59 -0
- package/dist/rate-limiter/injectRateLimitedSignal.js +62 -0
- package/dist/rate-limiter/injectRateLimitedSignal.js.map +1 -0
- package/dist/rate-limiter/injectRateLimitedValue.cjs +17 -0
- package/dist/rate-limiter/injectRateLimitedValue.cjs.map +1 -0
- package/dist/rate-limiter/injectRateLimitedValue.d.cts +49 -0
- package/dist/rate-limiter/injectRateLimitedValue.d.ts +49 -0
- package/dist/rate-limiter/injectRateLimitedValue.js +17 -0
- package/dist/rate-limiter/injectRateLimitedValue.js.map +1 -0
- package/dist/rate-limiter/injectRateLimiter.cjs +90 -0
- package/dist/rate-limiter/injectRateLimiter.cjs.map +1 -0
- package/dist/rate-limiter/injectRateLimiter.d.cts +93 -0
- package/dist/rate-limiter/injectRateLimiter.d.ts +93 -0
- package/dist/rate-limiter/injectRateLimiter.js +90 -0
- package/dist/rate-limiter/injectRateLimiter.js.map +1 -0
- package/dist/throttler/index.cjs +17 -0
- package/dist/throttler/index.d.cts +6 -0
- package/dist/throttler/index.d.ts +6 -0
- package/dist/throttler/index.js +8 -0
- package/dist/throttler/injectThrottledCallback.cjs +45 -0
- package/dist/throttler/injectThrottledCallback.cjs.map +1 -0
- package/dist/throttler/injectThrottledCallback.d.cts +42 -0
- package/dist/throttler/injectThrottledCallback.d.ts +42 -0
- package/dist/throttler/injectThrottledCallback.js +45 -0
- package/dist/throttler/injectThrottledCallback.js.map +1 -0
- package/dist/throttler/injectThrottledSignal.cjs +69 -0
- package/dist/throttler/injectThrottledSignal.cjs.map +1 -0
- package/dist/throttler/injectThrottledSignal.d.cts +66 -0
- package/dist/throttler/injectThrottledSignal.d.ts +66 -0
- package/dist/throttler/injectThrottledSignal.js +69 -0
- package/dist/throttler/injectThrottledSignal.js.map +1 -0
- package/dist/throttler/injectThrottledValue.cjs +17 -0
- package/dist/throttler/injectThrottledValue.cjs.map +1 -0
- package/dist/throttler/injectThrottledValue.d.cts +74 -0
- package/dist/throttler/injectThrottledValue.d.ts +74 -0
- package/dist/throttler/injectThrottledValue.js +17 -0
- package/dist/throttler/injectThrottledValue.js.map +1 -0
- package/dist/throttler/injectThrottler.cjs +76 -0
- package/dist/throttler/injectThrottler.cjs.map +1 -0
- package/dist/throttler/injectThrottler.d.cts +79 -0
- package/dist/throttler/injectThrottler.d.ts +79 -0
- package/dist/throttler/injectThrottler.js +76 -0
- package/dist/throttler/injectThrottler.js.map +1 -0
- package/dist/types/index.cjs +9 -0
- package/dist/types/index.d.cts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +3 -0
- package/dist/utils/index.cjs +9 -0
- package/dist/utils/index.d.cts +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +3 -0
- package/package.json +121 -0
- package/src/async-batcher/index.ts +4 -0
- package/src/async-batcher/injectAsyncBatchedCallback.ts +48 -0
- package/src/async-batcher/injectAsyncBatcher.ts +87 -0
- package/src/async-debouncer/index.ts +4 -0
- package/src/async-debouncer/injectAsyncDebouncedCallback.ts +50 -0
- package/src/async-debouncer/injectAsyncDebouncer.ts +113 -0
- package/src/async-queuer/index.ts +4 -0
- package/src/async-queuer/injectAsyncQueuedSignal.ts +82 -0
- package/src/async-queuer/injectAsyncQueuer.ts +87 -0
- package/src/async-rate-limiter/index.ts +4 -0
- package/src/async-rate-limiter/injectAsyncRateLimitedCallback.ts +52 -0
- package/src/async-rate-limiter/injectAsyncRateLimiter.ts +87 -0
- package/src/async-retryer/index.ts +1 -0
- package/src/async-throttler/index.ts +4 -0
- package/src/async-throttler/injectAsyncThrottledCallback.ts +50 -0
- package/src/async-throttler/injectAsyncThrottler.ts +92 -0
- package/src/batcher/index.ts +4 -0
- package/src/batcher/injectBatchedCallback.ts +46 -0
- package/src/batcher/injectBatcher.ts +79 -0
- package/src/debouncer/index.ts +6 -0
- package/src/debouncer/injectDebouncedCallback.ts +46 -0
- package/src/debouncer/injectDebouncedSignal.ts +101 -0
- package/src/debouncer/injectDebouncedValue.ts +126 -0
- package/src/debouncer/injectDebouncer.ts +102 -0
- package/src/index.ts +40 -0
- package/src/provider/index.ts +2 -0
- package/src/provider/pacer-context.ts +46 -0
- package/src/provider/pacer-provider.ts +38 -0
- package/src/queuer/index.ts +5 -0
- package/src/queuer/injectQueuedSignal.ts +70 -0
- package/src/queuer/injectQueuedValue.ts +101 -0
- package/src/queuer/injectQueuer.ts +83 -0
- package/src/rate-limiter/index.ts +6 -0
- package/src/rate-limiter/injectRateLimitedCallback.ts +45 -0
- package/src/rate-limiter/injectRateLimitedSignal.ts +95 -0
- package/src/rate-limiter/injectRateLimitedValue.ts +99 -0
- package/src/rate-limiter/injectRateLimiter.ts +116 -0
- package/src/throttler/index.ts +6 -0
- package/src/throttler/injectThrottledCallback.ts +45 -0
- package/src/throttler/injectThrottledSignal.ts +102 -0
- package/src/throttler/injectThrottledValue.ts +124 -0
- package/src/throttler/injectThrottler.ts +102 -0
- package/src/types/index.ts +1 -0
- package/src/utils/index.ts +1 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { injectRateLimitedCallback } from "./injectRateLimitedCallback.cjs";
|
|
2
|
+
import { AngularRateLimiter, injectRateLimiter } from "./injectRateLimiter.cjs";
|
|
3
|
+
import { RateLimitedSignal, injectRateLimitedSignal } from "./injectRateLimitedSignal.cjs";
|
|
4
|
+
import { injectRateLimitedValue } from "./injectRateLimitedValue.cjs";
|
|
5
|
+
export * from "@tanstack/pacer/rate-limiter";
|
|
6
|
+
export { AngularRateLimiter, RateLimitedSignal, injectRateLimitedCallback, injectRateLimitedSignal, injectRateLimitedValue, injectRateLimiter };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { injectRateLimitedCallback } from "./injectRateLimitedCallback.js";
|
|
2
|
+
import { AngularRateLimiter, injectRateLimiter } from "./injectRateLimiter.js";
|
|
3
|
+
import { RateLimitedSignal, injectRateLimitedSignal } from "./injectRateLimitedSignal.js";
|
|
4
|
+
import { injectRateLimitedValue } from "./injectRateLimitedValue.js";
|
|
5
|
+
export * from "@tanstack/pacer/rate-limiter";
|
|
6
|
+
export { AngularRateLimiter, RateLimitedSignal, injectRateLimitedCallback, injectRateLimitedSignal, injectRateLimitedValue, injectRateLimiter };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { injectRateLimiter } from "./injectRateLimiter.js";
|
|
2
|
+
import { injectRateLimitedCallback } from "./injectRateLimitedCallback.js";
|
|
3
|
+
import { injectRateLimitedSignal } from "./injectRateLimitedSignal.js";
|
|
4
|
+
import { injectRateLimitedValue } from "./injectRateLimitedValue.js";
|
|
5
|
+
|
|
6
|
+
export * from "@tanstack/pacer/rate-limiter"
|
|
7
|
+
|
|
8
|
+
export { injectRateLimitedCallback, injectRateLimitedSignal, injectRateLimitedValue, injectRateLimiter };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const require_injectRateLimiter = require('./injectRateLimiter.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/rate-limiter/injectRateLimitedCallback.ts
|
|
4
|
+
/**
|
|
5
|
+
* An Angular function that creates a rate-limited version of a callback function.
|
|
6
|
+
* This function is essentially a wrapper around `injectRateLimiter` that provides
|
|
7
|
+
* a simplified API for basic rate limiting needs.
|
|
8
|
+
*
|
|
9
|
+
* Rate limiting is a simple "hard limit" approach - it allows all calls until the limit
|
|
10
|
+
* is reached, then blocks subsequent calls until the window resets. Unlike throttling
|
|
11
|
+
* or debouncing, it does not attempt to space out or intelligently collapse calls.
|
|
12
|
+
*
|
|
13
|
+
* This function provides a simpler API compared to `injectRateLimiter`, making it ideal for basic
|
|
14
|
+
* rate limiting needs. However, it does not expose the underlying RateLimiter instance.
|
|
15
|
+
*
|
|
16
|
+
* For advanced usage requiring features like:
|
|
17
|
+
* - Manual cancellation/reset
|
|
18
|
+
* - Access to execution counts
|
|
19
|
+
* - State tracking
|
|
20
|
+
*
|
|
21
|
+
* Consider using the `injectRateLimiter` function instead.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* // Rate limit API calls to maximum 5 calls per minute
|
|
26
|
+
* const makeApiCall = injectRateLimitedCallback(
|
|
27
|
+
* (data: ApiData) => {
|
|
28
|
+
* return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) });
|
|
29
|
+
* },
|
|
30
|
+
* {
|
|
31
|
+
* limit: 5,
|
|
32
|
+
* window: 60000, // 1 minute
|
|
33
|
+
* windowType: 'sliding',
|
|
34
|
+
* }
|
|
35
|
+
* );
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function injectRateLimitedCallback(fn, options) {
|
|
39
|
+
const rateLimiter = require_injectRateLimiter.injectRateLimiter(fn, options);
|
|
40
|
+
return (...args) => rateLimiter.maybeExecute(...args);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
exports.injectRateLimitedCallback = injectRateLimitedCallback;
|
|
45
|
+
//# sourceMappingURL=injectRateLimitedCallback.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectRateLimitedCallback.cjs","names":["injectRateLimiter"],"sources":["../../src/rate-limiter/injectRateLimitedCallback.ts"],"sourcesContent":["import { injectRateLimiter } from './injectRateLimiter'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\nimport type { AnyFunction } from '@tanstack/pacer/types'\n\n/**\n * An Angular function that creates a rate-limited version of a callback function.\n * This function is essentially a wrapper around `injectRateLimiter` that provides\n * a simplified API for basic rate limiting needs.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all calls until the limit\n * is reached, then blocks subsequent calls until the window resets. Unlike throttling\n * or debouncing, it does not attempt to space out or intelligently collapse calls.\n *\n * This function provides a simpler API compared to `injectRateLimiter`, making it ideal for basic\n * rate limiting needs. However, it does not expose the underlying RateLimiter instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation/reset\n * - Access to execution counts\n * - State tracking\n *\n * Consider using the `injectRateLimiter` function instead.\n *\n * @example\n * ```ts\n * // Rate limit API calls to maximum 5 calls per minute\n * const makeApiCall = injectRateLimitedCallback(\n * (data: ApiData) => {\n * return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) });\n * },\n * {\n * limit: 5,\n * window: 60000, // 1 minute\n * windowType: 'sliding',\n * }\n * );\n * ```\n */\nexport function injectRateLimitedCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: RateLimiterOptions<TFn>,\n): (...args: Parameters<TFn>) => boolean {\n const rateLimiter = injectRateLimiter(fn, options)\n return (...args: Parameters<TFn>) => rateLimiter.maybeExecute(...args)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,0BACd,IACA,SACuC;CACvC,MAAM,cAAcA,4CAAkB,IAAI,QAAQ;AAClD,SAAQ,GAAG,SAA0B,YAAY,aAAa,GAAG,KAAK"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AnyFunction } from "@tanstack/pacer/types";
|
|
2
|
+
import { RateLimiterOptions } from "@tanstack/pacer/rate-limiter";
|
|
3
|
+
|
|
4
|
+
//#region src/rate-limiter/injectRateLimitedCallback.d.ts
|
|
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
|
+
declare function injectRateLimitedCallback<TFn extends AnyFunction>(fn: TFn, options: RateLimiterOptions<TFn>): (...args: Parameters<TFn>) => boolean;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { injectRateLimitedCallback };
|
|
42
|
+
//# sourceMappingURL=injectRateLimitedCallback.d.cts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { RateLimiterOptions } from "@tanstack/pacer/rate-limiter";
|
|
2
|
+
import { AnyFunction } from "@tanstack/pacer/types";
|
|
3
|
+
|
|
4
|
+
//#region src/rate-limiter/injectRateLimitedCallback.d.ts
|
|
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
|
+
declare function injectRateLimitedCallback<TFn extends AnyFunction>(fn: TFn, options: RateLimiterOptions<TFn>): (...args: Parameters<TFn>) => boolean;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { injectRateLimitedCallback };
|
|
42
|
+
//# sourceMappingURL=injectRateLimitedCallback.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { injectRateLimiter } from "./injectRateLimiter.js";
|
|
2
|
+
|
|
3
|
+
//#region src/rate-limiter/injectRateLimitedCallback.ts
|
|
4
|
+
/**
|
|
5
|
+
* An Angular function that creates a rate-limited version of a callback function.
|
|
6
|
+
* This function is essentially a wrapper around `injectRateLimiter` that provides
|
|
7
|
+
* a simplified API for basic rate limiting needs.
|
|
8
|
+
*
|
|
9
|
+
* Rate limiting is a simple "hard limit" approach - it allows all calls until the limit
|
|
10
|
+
* is reached, then blocks subsequent calls until the window resets. Unlike throttling
|
|
11
|
+
* or debouncing, it does not attempt to space out or intelligently collapse calls.
|
|
12
|
+
*
|
|
13
|
+
* This function provides a simpler API compared to `injectRateLimiter`, making it ideal for basic
|
|
14
|
+
* rate limiting needs. However, it does not expose the underlying RateLimiter instance.
|
|
15
|
+
*
|
|
16
|
+
* For advanced usage requiring features like:
|
|
17
|
+
* - Manual cancellation/reset
|
|
18
|
+
* - Access to execution counts
|
|
19
|
+
* - State tracking
|
|
20
|
+
*
|
|
21
|
+
* Consider using the `injectRateLimiter` function instead.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* // Rate limit API calls to maximum 5 calls per minute
|
|
26
|
+
* const makeApiCall = injectRateLimitedCallback(
|
|
27
|
+
* (data: ApiData) => {
|
|
28
|
+
* return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) });
|
|
29
|
+
* },
|
|
30
|
+
* {
|
|
31
|
+
* limit: 5,
|
|
32
|
+
* window: 60000, // 1 minute
|
|
33
|
+
* windowType: 'sliding',
|
|
34
|
+
* }
|
|
35
|
+
* );
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function injectRateLimitedCallback(fn, options) {
|
|
39
|
+
const rateLimiter = injectRateLimiter(fn, options);
|
|
40
|
+
return (...args) => rateLimiter.maybeExecute(...args);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { injectRateLimitedCallback };
|
|
45
|
+
//# sourceMappingURL=injectRateLimitedCallback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectRateLimitedCallback.js","names":[],"sources":["../../src/rate-limiter/injectRateLimitedCallback.ts"],"sourcesContent":["import { injectRateLimiter } from './injectRateLimiter'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\nimport type { AnyFunction } from '@tanstack/pacer/types'\n\n/**\n * An Angular function that creates a rate-limited version of a callback function.\n * This function is essentially a wrapper around `injectRateLimiter` that provides\n * a simplified API for basic rate limiting needs.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all calls until the limit\n * is reached, then blocks subsequent calls until the window resets. Unlike throttling\n * or debouncing, it does not attempt to space out or intelligently collapse calls.\n *\n * This function provides a simpler API compared to `injectRateLimiter`, making it ideal for basic\n * rate limiting needs. However, it does not expose the underlying RateLimiter instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation/reset\n * - Access to execution counts\n * - State tracking\n *\n * Consider using the `injectRateLimiter` function instead.\n *\n * @example\n * ```ts\n * // Rate limit API calls to maximum 5 calls per minute\n * const makeApiCall = injectRateLimitedCallback(\n * (data: ApiData) => {\n * return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) });\n * },\n * {\n * limit: 5,\n * window: 60000, // 1 minute\n * windowType: 'sliding',\n * }\n * );\n * ```\n */\nexport function injectRateLimitedCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: RateLimiterOptions<TFn>,\n): (...args: Parameters<TFn>) => boolean {\n const rateLimiter = injectRateLimiter(fn, options)\n return (...args: Parameters<TFn>) => rateLimiter.maybeExecute(...args)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,0BACd,IACA,SACuC;CACvC,MAAM,cAAc,kBAAkB,IAAI,QAAQ;AAClD,SAAQ,GAAG,SAA0B,YAAY,aAAa,GAAG,KAAK"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const require_injectRateLimiter = require('./injectRateLimiter.cjs');
|
|
2
|
+
let _angular_core = require("@angular/core");
|
|
3
|
+
|
|
4
|
+
//#region src/rate-limiter/injectRateLimitedSignal.ts
|
|
5
|
+
/**
|
|
6
|
+
* An Angular function that creates a rate-limited state signal, combining Angular's signal with rate limiting functionality.
|
|
7
|
+
* This function provides both the current rate-limited value and methods to update it.
|
|
8
|
+
*
|
|
9
|
+
* Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks
|
|
10
|
+
* subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out
|
|
11
|
+
* or intelligently collapse updates.
|
|
12
|
+
*
|
|
13
|
+
* The function returns a callable object:
|
|
14
|
+
* - `rateLimited()`: Get the current rate-limited value
|
|
15
|
+
* - `rateLimited.set(...)`: Set or update the rate-limited value (rate-limited via maybeExecute)
|
|
16
|
+
* - `rateLimited.rateLimiter`: The rate limiter instance with additional control methods and state signals
|
|
17
|
+
*
|
|
18
|
+
* ## State Management and Selector
|
|
19
|
+
*
|
|
20
|
+
* The function uses TanStack Store for reactive state management via the underlying rate limiter instance.
|
|
21
|
+
* The `selector` parameter allows you to specify which rate limiter state changes will trigger signal updates,
|
|
22
|
+
* optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
|
|
23
|
+
*
|
|
24
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
25
|
+
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
26
|
+
* full control over when your component tracks state changes.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* // Default behavior - no reactive state subscriptions
|
|
31
|
+
* const rateLimited = injectRateLimitedSignal(0, {
|
|
32
|
+
* limit: 5,
|
|
33
|
+
* window: 60000,
|
|
34
|
+
* windowType: 'sliding'
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // Opt-in to reactive updates when limit state changes
|
|
38
|
+
* const rateLimited = injectRateLimitedSignal(
|
|
39
|
+
* 0,
|
|
40
|
+
* { limit: 5, window: 60000 },
|
|
41
|
+
* (state) => ({ rejectionCount: state.rejectionCount })
|
|
42
|
+
* );
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
function injectRateLimitedSignal(value, initialOptions, selector) {
|
|
46
|
+
const rateLimitedValue = (0, _angular_core.signal)(value);
|
|
47
|
+
const rateLimiter = require_injectRateLimiter.injectRateLimiter((newValue) => {
|
|
48
|
+
if (typeof newValue === "function") rateLimitedValue.update(newValue);
|
|
49
|
+
else rateLimitedValue.set(newValue);
|
|
50
|
+
}, initialOptions, selector);
|
|
51
|
+
const set = (newValue) => {
|
|
52
|
+
rateLimiter.maybeExecute(newValue);
|
|
53
|
+
};
|
|
54
|
+
return Object.assign(() => rateLimitedValue(), {
|
|
55
|
+
set,
|
|
56
|
+
rateLimiter
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
exports.injectRateLimitedSignal = injectRateLimitedSignal;
|
|
62
|
+
//# sourceMappingURL=injectRateLimitedSignal.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectRateLimitedSignal.cjs","names":["injectRateLimiter"],"sources":["../../src/rate-limiter/injectRateLimitedSignal.ts"],"sourcesContent":["import { signal } from '@angular/core'\nimport { injectRateLimiter } from './injectRateLimiter'\nimport type { AngularRateLimiter } from './injectRateLimiter'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\nexport type RateLimitedSignal<TValue, TSelected = {}> = ((\n ...args: []\n) => TValue) & {\n /**\n * Set or update the rate-limited value. This calls `rateLimiter.maybeExecute(...)`.\n */\n readonly set: Setter<TValue>\n /**\n * The rate limiter instance with additional control methods and state signals.\n */\n readonly rateLimiter: AngularRateLimiter<Setter<TValue>, TSelected>\n}\n\n/**\n * An Angular function that creates a rate-limited state signal, combining Angular's signal with rate limiting functionality.\n * This function provides both the current rate-limited value and methods to update it.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates.\n *\n * The function returns a callable object:\n * - `rateLimited()`: Get the current rate-limited value\n * - `rateLimited.set(...)`: Set or update the rate-limited value (rate-limited via maybeExecute)\n * - `rateLimited.rateLimiter`: The rate limiter instance with additional control methods and state signals\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for reactive state management via the underlying rate limiter instance.\n * The `selector` parameter allows you to specify which rate limiter 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 * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const rateLimited = injectRateLimitedSignal(0, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to reactive updates when limit state changes\n * const rateLimited = injectRateLimitedSignal(\n * 0,\n * { limit: 5, window: 60000 },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n * ```\n */\nexport function injectRateLimitedSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected> {\n const rateLimitedValue = signal<TValue>(value)\n\n const rateLimiter = injectRateLimiter(\n (newValue: TValue | ((prev: TValue) => TValue)) => {\n if (typeof newValue === 'function') {\n rateLimitedValue.update(newValue as (prev: TValue) => TValue)\n } else {\n rateLimitedValue.set(newValue)\n }\n },\n initialOptions,\n selector,\n )\n\n const set: Setter<TValue> = (\n newValue: TValue | ((prev: TValue) => TValue),\n ) => {\n rateLimiter.maybeExecute(newValue)\n }\n\n const rateLimited = Object.assign(() => rateLimitedValue(), {\n set,\n rateLimiter,\n }) as RateLimitedSignal<TValue, TSelected>\n\n return rateLimited\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,wBACd,OACA,gBACA,UACsC;CACtC,MAAM,6CAAkC,MAAM;CAE9C,MAAM,cAAcA,6CACjB,aAAkD;AACjD,MAAI,OAAO,aAAa,WACtB,kBAAiB,OAAO,SAAqC;MAE7D,kBAAiB,IAAI,SAAS;IAGlC,gBACA,SACD;CAED,MAAM,OACJ,aACG;AACH,cAAY,aAAa,SAAS;;AAQpC,QALoB,OAAO,aAAa,kBAAkB,EAAE;EAC1D;EACA;EACD,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { AngularRateLimiter } from "./injectRateLimiter.cjs";
|
|
2
|
+
import { RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
3
|
+
|
|
4
|
+
//#region src/rate-limiter/injectRateLimitedSignal.d.ts
|
|
5
|
+
type Setter<T> = (value: T | ((prev: T) => T)) => void;
|
|
6
|
+
type RateLimitedSignal<TValue, TSelected = {}> = ((...args: []) => TValue) & {
|
|
7
|
+
/**
|
|
8
|
+
* Set or update the rate-limited value. This calls `rateLimiter.maybeExecute(...)`.
|
|
9
|
+
*/
|
|
10
|
+
readonly set: Setter<TValue>;
|
|
11
|
+
/**
|
|
12
|
+
* The rate limiter instance with additional control methods and state signals.
|
|
13
|
+
*/
|
|
14
|
+
readonly rateLimiter: AngularRateLimiter<Setter<TValue>, TSelected>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* An Angular function that creates a rate-limited state signal, combining Angular's signal with rate limiting functionality.
|
|
18
|
+
* This function provides both the current rate-limited value and methods to update it.
|
|
19
|
+
*
|
|
20
|
+
* Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks
|
|
21
|
+
* subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out
|
|
22
|
+
* or intelligently collapse updates.
|
|
23
|
+
*
|
|
24
|
+
* The function returns a callable object:
|
|
25
|
+
* - `rateLimited()`: Get the current rate-limited value
|
|
26
|
+
* - `rateLimited.set(...)`: Set or update the rate-limited value (rate-limited via maybeExecute)
|
|
27
|
+
* - `rateLimited.rateLimiter`: The rate limiter instance with additional control methods and state signals
|
|
28
|
+
*
|
|
29
|
+
* ## State Management and Selector
|
|
30
|
+
*
|
|
31
|
+
* The function uses TanStack Store for reactive state management via the underlying rate limiter instance.
|
|
32
|
+
* The `selector` parameter allows you to specify which rate limiter 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.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* // Default behavior - no reactive state subscriptions
|
|
42
|
+
* const rateLimited = injectRateLimitedSignal(0, {
|
|
43
|
+
* limit: 5,
|
|
44
|
+
* window: 60000,
|
|
45
|
+
* windowType: 'sliding'
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // Opt-in to reactive updates when limit state changes
|
|
49
|
+
* const rateLimited = injectRateLimitedSignal(
|
|
50
|
+
* 0,
|
|
51
|
+
* { limit: 5, window: 60000 },
|
|
52
|
+
* (state) => ({ rejectionCount: state.rejectionCount })
|
|
53
|
+
* );
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
declare function injectRateLimitedSignal<TValue, TSelected = {}>(value: TValue, initialOptions: RateLimiterOptions<Setter<TValue>>, selector?: (state: RateLimiterState) => TSelected): RateLimitedSignal<TValue, TSelected>;
|
|
57
|
+
//#endregion
|
|
58
|
+
export { RateLimitedSignal, injectRateLimitedSignal };
|
|
59
|
+
//# sourceMappingURL=injectRateLimitedSignal.d.cts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { AngularRateLimiter } from "./injectRateLimiter.js";
|
|
2
|
+
import { RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
3
|
+
|
|
4
|
+
//#region src/rate-limiter/injectRateLimitedSignal.d.ts
|
|
5
|
+
type Setter<T> = (value: T | ((prev: T) => T)) => void;
|
|
6
|
+
type RateLimitedSignal<TValue, TSelected = {}> = ((...args: []) => TValue) & {
|
|
7
|
+
/**
|
|
8
|
+
* Set or update the rate-limited value. This calls `rateLimiter.maybeExecute(...)`.
|
|
9
|
+
*/
|
|
10
|
+
readonly set: Setter<TValue>;
|
|
11
|
+
/**
|
|
12
|
+
* The rate limiter instance with additional control methods and state signals.
|
|
13
|
+
*/
|
|
14
|
+
readonly rateLimiter: AngularRateLimiter<Setter<TValue>, TSelected>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* An Angular function that creates a rate-limited state signal, combining Angular's signal with rate limiting functionality.
|
|
18
|
+
* This function provides both the current rate-limited value and methods to update it.
|
|
19
|
+
*
|
|
20
|
+
* Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks
|
|
21
|
+
* subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out
|
|
22
|
+
* or intelligently collapse updates.
|
|
23
|
+
*
|
|
24
|
+
* The function returns a callable object:
|
|
25
|
+
* - `rateLimited()`: Get the current rate-limited value
|
|
26
|
+
* - `rateLimited.set(...)`: Set or update the rate-limited value (rate-limited via maybeExecute)
|
|
27
|
+
* - `rateLimited.rateLimiter`: The rate limiter instance with additional control methods and state signals
|
|
28
|
+
*
|
|
29
|
+
* ## State Management and Selector
|
|
30
|
+
*
|
|
31
|
+
* The function uses TanStack Store for reactive state management via the underlying rate limiter instance.
|
|
32
|
+
* The `selector` parameter allows you to specify which rate limiter 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.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* // Default behavior - no reactive state subscriptions
|
|
42
|
+
* const rateLimited = injectRateLimitedSignal(0, {
|
|
43
|
+
* limit: 5,
|
|
44
|
+
* window: 60000,
|
|
45
|
+
* windowType: 'sliding'
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // Opt-in to reactive updates when limit state changes
|
|
49
|
+
* const rateLimited = injectRateLimitedSignal(
|
|
50
|
+
* 0,
|
|
51
|
+
* { limit: 5, window: 60000 },
|
|
52
|
+
* (state) => ({ rejectionCount: state.rejectionCount })
|
|
53
|
+
* );
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
declare function injectRateLimitedSignal<TValue, TSelected = {}>(value: TValue, initialOptions: RateLimiterOptions<Setter<TValue>>, selector?: (state: RateLimiterState) => TSelected): RateLimitedSignal<TValue, TSelected>;
|
|
57
|
+
//#endregion
|
|
58
|
+
export { RateLimitedSignal, injectRateLimitedSignal };
|
|
59
|
+
//# sourceMappingURL=injectRateLimitedSignal.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { injectRateLimiter } from "./injectRateLimiter.js";
|
|
2
|
+
import { signal } from "@angular/core";
|
|
3
|
+
|
|
4
|
+
//#region src/rate-limiter/injectRateLimitedSignal.ts
|
|
5
|
+
/**
|
|
6
|
+
* An Angular function that creates a rate-limited state signal, combining Angular's signal with rate limiting functionality.
|
|
7
|
+
* This function provides both the current rate-limited value and methods to update it.
|
|
8
|
+
*
|
|
9
|
+
* Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks
|
|
10
|
+
* subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out
|
|
11
|
+
* or intelligently collapse updates.
|
|
12
|
+
*
|
|
13
|
+
* The function returns a callable object:
|
|
14
|
+
* - `rateLimited()`: Get the current rate-limited value
|
|
15
|
+
* - `rateLimited.set(...)`: Set or update the rate-limited value (rate-limited via maybeExecute)
|
|
16
|
+
* - `rateLimited.rateLimiter`: The rate limiter instance with additional control methods and state signals
|
|
17
|
+
*
|
|
18
|
+
* ## State Management and Selector
|
|
19
|
+
*
|
|
20
|
+
* The function uses TanStack Store for reactive state management via the underlying rate limiter instance.
|
|
21
|
+
* The `selector` parameter allows you to specify which rate limiter state changes will trigger signal updates,
|
|
22
|
+
* optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
|
|
23
|
+
*
|
|
24
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
25
|
+
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
26
|
+
* full control over when your component tracks state changes.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* // Default behavior - no reactive state subscriptions
|
|
31
|
+
* const rateLimited = injectRateLimitedSignal(0, {
|
|
32
|
+
* limit: 5,
|
|
33
|
+
* window: 60000,
|
|
34
|
+
* windowType: 'sliding'
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // Opt-in to reactive updates when limit state changes
|
|
38
|
+
* const rateLimited = injectRateLimitedSignal(
|
|
39
|
+
* 0,
|
|
40
|
+
* { limit: 5, window: 60000 },
|
|
41
|
+
* (state) => ({ rejectionCount: state.rejectionCount })
|
|
42
|
+
* );
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
function injectRateLimitedSignal(value, initialOptions, selector) {
|
|
46
|
+
const rateLimitedValue = signal(value);
|
|
47
|
+
const rateLimiter = injectRateLimiter((newValue) => {
|
|
48
|
+
if (typeof newValue === "function") rateLimitedValue.update(newValue);
|
|
49
|
+
else rateLimitedValue.set(newValue);
|
|
50
|
+
}, initialOptions, selector);
|
|
51
|
+
const set = (newValue) => {
|
|
52
|
+
rateLimiter.maybeExecute(newValue);
|
|
53
|
+
};
|
|
54
|
+
return Object.assign(() => rateLimitedValue(), {
|
|
55
|
+
set,
|
|
56
|
+
rateLimiter
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
export { injectRateLimitedSignal };
|
|
62
|
+
//# sourceMappingURL=injectRateLimitedSignal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectRateLimitedSignal.js","names":[],"sources":["../../src/rate-limiter/injectRateLimitedSignal.ts"],"sourcesContent":["import { signal } from '@angular/core'\nimport { injectRateLimiter } from './injectRateLimiter'\nimport type { AngularRateLimiter } from './injectRateLimiter'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\nexport type RateLimitedSignal<TValue, TSelected = {}> = ((\n ...args: []\n) => TValue) & {\n /**\n * Set or update the rate-limited value. This calls `rateLimiter.maybeExecute(...)`.\n */\n readonly set: Setter<TValue>\n /**\n * The rate limiter instance with additional control methods and state signals.\n */\n readonly rateLimiter: AngularRateLimiter<Setter<TValue>, TSelected>\n}\n\n/**\n * An Angular function that creates a rate-limited state signal, combining Angular's signal with rate limiting functionality.\n * This function provides both the current rate-limited value and methods to update it.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates.\n *\n * The function returns a callable object:\n * - `rateLimited()`: Get the current rate-limited value\n * - `rateLimited.set(...)`: Set or update the rate-limited value (rate-limited via maybeExecute)\n * - `rateLimited.rateLimiter`: The rate limiter instance with additional control methods and state signals\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for reactive state management via the underlying rate limiter instance.\n * The `selector` parameter allows you to specify which rate limiter 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 * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const rateLimited = injectRateLimitedSignal(0, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to reactive updates when limit state changes\n * const rateLimited = injectRateLimitedSignal(\n * 0,\n * { limit: 5, window: 60000 },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n * ```\n */\nexport function injectRateLimitedSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected> {\n const rateLimitedValue = signal<TValue>(value)\n\n const rateLimiter = injectRateLimiter(\n (newValue: TValue | ((prev: TValue) => TValue)) => {\n if (typeof newValue === 'function') {\n rateLimitedValue.update(newValue as (prev: TValue) => TValue)\n } else {\n rateLimitedValue.set(newValue)\n }\n },\n initialOptions,\n selector,\n )\n\n const set: Setter<TValue> = (\n newValue: TValue | ((prev: TValue) => TValue),\n ) => {\n rateLimiter.maybeExecute(newValue)\n }\n\n const rateLimited = Object.assign(() => rateLimitedValue(), {\n set,\n rateLimiter,\n }) as RateLimitedSignal<TValue, TSelected>\n\n return rateLimited\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,wBACd,OACA,gBACA,UACsC;CACtC,MAAM,mBAAmB,OAAe,MAAM;CAE9C,MAAM,cAAc,mBACjB,aAAkD;AACjD,MAAI,OAAO,aAAa,WACtB,kBAAiB,OAAO,SAAqC;MAE7D,kBAAiB,IAAI,SAAS;IAGlC,gBACA,SACD;CAED,MAAM,OACJ,aACG;AACH,cAAY,aAAa,SAAS;;AAQpC,QALoB,OAAO,aAAa,kBAAkB,EAAE;EAC1D;EACA;EACD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const require_injectRateLimitedSignal = require('./injectRateLimitedSignal.cjs');
|
|
2
|
+
let _angular_core = require("@angular/core");
|
|
3
|
+
|
|
4
|
+
//#region src/rate-limiter/injectRateLimitedValue.ts
|
|
5
|
+
function injectRateLimitedValue(value, initialValueOrOptions, initialOptionsOrSelector, maybeSelector) {
|
|
6
|
+
const hasInitialValue = initialOptionsOrSelector !== void 0 && !(typeof initialOptionsOrSelector === "function") || maybeSelector !== void 0;
|
|
7
|
+
const rateLimited = require_injectRateLimitedSignal.injectRateLimitedSignal(hasInitialValue ? initialValueOrOptions : void 0, hasInitialValue ? initialOptionsOrSelector : initialValueOrOptions, hasInitialValue ? maybeSelector : initialOptionsOrSelector);
|
|
8
|
+
(0, _angular_core.effect)(() => {
|
|
9
|
+
const latest = value();
|
|
10
|
+
rateLimited.set(latest);
|
|
11
|
+
});
|
|
12
|
+
return rateLimited;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.injectRateLimitedValue = injectRateLimitedValue;
|
|
17
|
+
//# sourceMappingURL=injectRateLimitedValue.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectRateLimitedValue.cjs","names":["injectRateLimitedSignal"],"sources":["../../src/rate-limiter/injectRateLimitedValue.ts"],"sourcesContent":["import { effect } from '@angular/core'\nimport { injectRateLimitedSignal } from './injectRateLimitedSignal'\nimport type { RateLimitedSignal } from './injectRateLimitedSignal'\nimport type { Signal } from '@angular/core'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\n/**\n * An Angular function that creates a rate-limited value that updates at most a certain number of times within a time window.\n * Unlike injectRateLimitedSignal, this function automatically tracks changes to the input signal\n * and updates the rate-limited value accordingly.\n *\n * The rate-limited value will update according to the configured rate limit, blocking updates\n * once the limit is reached until the window resets.\n *\n * The function returns a rate-limited signal object containing:\n * - A Signal that provides the current rate-limited value\n * - The rate limiter instance with control methods\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for reactive state management via the underlying rate limiter instance.\n * The `selector` parameter allows you to specify which rate limiter 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 * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const value = signal(0)\n * const rateLimited = injectRateLimitedValue(value, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * })\n *\n * // rateLimited() will update at most 5 times per 60 seconds\n * effect(() => {\n * updateUI(rateLimited())\n * })\n * ```\n */\nexport function injectRateLimitedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected>\nexport function injectRateLimitedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValue: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected>\nexport function injectRateLimitedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValueOrOptions: TValue | RateLimiterOptions<Setter<TValue>>,\n initialOptionsOrSelector?:\n | RateLimiterOptions<Setter<TValue>>\n | ((state: RateLimiterState) => TSelected),\n maybeSelector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<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 RateLimiterOptions<Setter<TValue>>)\n : (initialValueOrOptions as RateLimiterOptions<Setter<TValue>>)\n const selector = hasInitialValue\n ? maybeSelector\n : (initialOptionsOrSelector as\n | ((state: RateLimiterState) => TSelected)\n | undefined)\n\n const rateLimited = injectRateLimitedSignal(\n initialValue,\n initialOptions,\n selector,\n )\n\n effect(() => {\n const latest = value()\n rateLimited.set(latest)\n })\n\n return rateLimited\n}\n"],"mappings":";;;;AA4DA,SAAgB,uBACd,OACA,uBACA,0BAGA,eACsC;CAGtC,MAAM,kBACH,6BAA6B,UAAa,EAHzB,OAAO,6BAA6B,eAItD,kBAAkB;CAcpB,MAAM,cAAcA,wDAZC,kBAChB,wBACA,QACkB,kBAClB,2BACA,uBACY,kBACb,gBACC,yBAQJ;AAED,iCAAa;EACX,MAAM,SAAS,OAAO;AACtB,cAAY,IAAI,OAAO;GACvB;AAEF,QAAO"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { RateLimitedSignal } from "./injectRateLimitedSignal.cjs";
|
|
2
|
+
import { Signal } from "@angular/core";
|
|
3
|
+
import { RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
4
|
+
|
|
5
|
+
//#region src/rate-limiter/injectRateLimitedValue.d.ts
|
|
6
|
+
type Setter<T> = (value: T | ((prev: T) => T)) => void;
|
|
7
|
+
/**
|
|
8
|
+
* An Angular function that creates a rate-limited value that updates at most a certain number of times within a time window.
|
|
9
|
+
* Unlike injectRateLimitedSignal, this function automatically tracks changes to the input signal
|
|
10
|
+
* and updates the rate-limited value accordingly.
|
|
11
|
+
*
|
|
12
|
+
* The rate-limited value will update according to the configured rate limit, blocking updates
|
|
13
|
+
* once the limit is reached until the window resets.
|
|
14
|
+
*
|
|
15
|
+
* The function returns a rate-limited signal object containing:
|
|
16
|
+
* - A Signal that provides the current rate-limited value
|
|
17
|
+
* - The rate limiter instance with control methods
|
|
18
|
+
*
|
|
19
|
+
* ## State Management and Selector
|
|
20
|
+
*
|
|
21
|
+
* The function uses TanStack Store for reactive state management via the underlying rate limiter instance.
|
|
22
|
+
* The `selector` parameter allows you to specify which rate limiter state changes will trigger signal updates,
|
|
23
|
+
* optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
|
|
24
|
+
*
|
|
25
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
26
|
+
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
27
|
+
* full control over when your component tracks state changes.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* // Default behavior - no reactive state subscriptions
|
|
32
|
+
* const value = signal(0)
|
|
33
|
+
* const rateLimited = injectRateLimitedValue(value, {
|
|
34
|
+
* limit: 5,
|
|
35
|
+
* window: 60000,
|
|
36
|
+
* windowType: 'sliding',
|
|
37
|
+
* })
|
|
38
|
+
*
|
|
39
|
+
* // rateLimited() will update at most 5 times per 60 seconds
|
|
40
|
+
* effect(() => {
|
|
41
|
+
* updateUI(rateLimited())
|
|
42
|
+
* })
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
declare function injectRateLimitedValue<TValue, TSelected = {}>(value: Signal<TValue>, initialOptions: RateLimiterOptions<Setter<TValue>>, selector?: (state: RateLimiterState) => TSelected): RateLimitedSignal<TValue, TSelected>;
|
|
46
|
+
declare function injectRateLimitedValue<TValue, TSelected = {}>(value: Signal<TValue>, initialValue: TValue, initialOptions: RateLimiterOptions<Setter<TValue>>, selector?: (state: RateLimiterState) => TSelected): RateLimitedSignal<TValue, TSelected>;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { injectRateLimitedValue };
|
|
49
|
+
//# sourceMappingURL=injectRateLimitedValue.d.cts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { RateLimitedSignal } from "./injectRateLimitedSignal.js";
|
|
2
|
+
import { Signal } from "@angular/core";
|
|
3
|
+
import { RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
4
|
+
|
|
5
|
+
//#region src/rate-limiter/injectRateLimitedValue.d.ts
|
|
6
|
+
type Setter<T> = (value: T | ((prev: T) => T)) => void;
|
|
7
|
+
/**
|
|
8
|
+
* An Angular function that creates a rate-limited value that updates at most a certain number of times within a time window.
|
|
9
|
+
* Unlike injectRateLimitedSignal, this function automatically tracks changes to the input signal
|
|
10
|
+
* and updates the rate-limited value accordingly.
|
|
11
|
+
*
|
|
12
|
+
* The rate-limited value will update according to the configured rate limit, blocking updates
|
|
13
|
+
* once the limit is reached until the window resets.
|
|
14
|
+
*
|
|
15
|
+
* The function returns a rate-limited signal object containing:
|
|
16
|
+
* - A Signal that provides the current rate-limited value
|
|
17
|
+
* - The rate limiter instance with control methods
|
|
18
|
+
*
|
|
19
|
+
* ## State Management and Selector
|
|
20
|
+
*
|
|
21
|
+
* The function uses TanStack Store for reactive state management via the underlying rate limiter instance.
|
|
22
|
+
* The `selector` parameter allows you to specify which rate limiter state changes will trigger signal updates,
|
|
23
|
+
* optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
|
|
24
|
+
*
|
|
25
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
26
|
+
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
27
|
+
* full control over when your component tracks state changes.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* // Default behavior - no reactive state subscriptions
|
|
32
|
+
* const value = signal(0)
|
|
33
|
+
* const rateLimited = injectRateLimitedValue(value, {
|
|
34
|
+
* limit: 5,
|
|
35
|
+
* window: 60000,
|
|
36
|
+
* windowType: 'sliding',
|
|
37
|
+
* })
|
|
38
|
+
*
|
|
39
|
+
* // rateLimited() will update at most 5 times per 60 seconds
|
|
40
|
+
* effect(() => {
|
|
41
|
+
* updateUI(rateLimited())
|
|
42
|
+
* })
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
declare function injectRateLimitedValue<TValue, TSelected = {}>(value: Signal<TValue>, initialOptions: RateLimiterOptions<Setter<TValue>>, selector?: (state: RateLimiterState) => TSelected): RateLimitedSignal<TValue, TSelected>;
|
|
46
|
+
declare function injectRateLimitedValue<TValue, TSelected = {}>(value: Signal<TValue>, initialValue: TValue, initialOptions: RateLimiterOptions<Setter<TValue>>, selector?: (state: RateLimiterState) => TSelected): RateLimitedSignal<TValue, TSelected>;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { injectRateLimitedValue };
|
|
49
|
+
//# sourceMappingURL=injectRateLimitedValue.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { injectRateLimitedSignal } from "./injectRateLimitedSignal.js";
|
|
2
|
+
import { effect } from "@angular/core";
|
|
3
|
+
|
|
4
|
+
//#region src/rate-limiter/injectRateLimitedValue.ts
|
|
5
|
+
function injectRateLimitedValue(value, initialValueOrOptions, initialOptionsOrSelector, maybeSelector) {
|
|
6
|
+
const hasInitialValue = initialOptionsOrSelector !== void 0 && !(typeof initialOptionsOrSelector === "function") || maybeSelector !== void 0;
|
|
7
|
+
const rateLimited = injectRateLimitedSignal(hasInitialValue ? initialValueOrOptions : void 0, hasInitialValue ? initialOptionsOrSelector : initialValueOrOptions, hasInitialValue ? maybeSelector : initialOptionsOrSelector);
|
|
8
|
+
effect(() => {
|
|
9
|
+
const latest = value();
|
|
10
|
+
rateLimited.set(latest);
|
|
11
|
+
});
|
|
12
|
+
return rateLimited;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { injectRateLimitedValue };
|
|
17
|
+
//# sourceMappingURL=injectRateLimitedValue.js.map
|