@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 @@
|
|
|
1
|
+
{"version":3,"file":"injectRateLimitedValue.js","names":[],"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,cAAc,wBAZC,kBAChB,wBACA,QACkB,kBAClB,2BACA,uBACY,kBACb,gBACC,yBAQJ;AAED,cAAa;EACX,MAAM,SAAS,OAAO;AACtB,cAAY,IAAI,OAAO;GACvB;AAEF,QAAO"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const require_pacer_context = require('../provider/pacer-context.cjs');
|
|
2
|
+
let _tanstack_angular_store = require("@tanstack/angular-store");
|
|
3
|
+
let _tanstack_pacer_rate_limiter = require("@tanstack/pacer/rate-limiter");
|
|
4
|
+
|
|
5
|
+
//#region src/rate-limiter/injectRateLimiter.ts
|
|
6
|
+
/**
|
|
7
|
+
* An Angular function that creates and manages a RateLimiter instance.
|
|
8
|
+
*
|
|
9
|
+
* This is a lower-level function that provides direct access to the RateLimiter's functionality.
|
|
10
|
+
* This allows you to integrate it with any state management solution you prefer.
|
|
11
|
+
*
|
|
12
|
+
* Rate limiting is a simple "hard limit" approach that allows executions until a maximum count is reached within
|
|
13
|
+
* a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,
|
|
14
|
+
* it does not attempt to space out or collapse executions intelligently.
|
|
15
|
+
*
|
|
16
|
+
* The rate limiter supports two types of windows:
|
|
17
|
+
* - 'fixed': A strict window that resets after the window period. All executions within the window count
|
|
18
|
+
* towards the limit, and the window resets completely after the period.
|
|
19
|
+
* - 'sliding': A rolling window that allows executions as old ones expire. This provides a more
|
|
20
|
+
* consistent rate of execution over time.
|
|
21
|
+
*
|
|
22
|
+
* For smoother execution patterns:
|
|
23
|
+
* - Use throttling when you want consistent spacing between executions (e.g. UI updates)
|
|
24
|
+
* - Use debouncing when you want to collapse rapid-fire events (e.g. search input)
|
|
25
|
+
* - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)
|
|
26
|
+
*
|
|
27
|
+
* ## State Management and Selector
|
|
28
|
+
*
|
|
29
|
+
* The function uses TanStack Store for state management and wraps it with Angular signals.
|
|
30
|
+
* The `selector` parameter allows you to specify which state changes will trigger signal updates,
|
|
31
|
+
* optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
|
|
32
|
+
*
|
|
33
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
34
|
+
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
35
|
+
* full control over when your component tracks state changes.
|
|
36
|
+
*
|
|
37
|
+
* Available state properties:
|
|
38
|
+
* - `executionCount`: Number of function executions that have been completed
|
|
39
|
+
* - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations
|
|
40
|
+
* - `rejectionCount`: Number of function executions that have been rejected due to rate limiting
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* // Default behavior - no reactive state subscriptions
|
|
45
|
+
* const rateLimiter = injectRateLimiter(apiCall, {
|
|
46
|
+
* limit: 5,
|
|
47
|
+
* window: 60000,
|
|
48
|
+
* windowType: 'sliding',
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* // Opt-in to track execution count changes
|
|
52
|
+
* const rateLimiter = injectRateLimiter(
|
|
53
|
+
* apiCall,
|
|
54
|
+
* {
|
|
55
|
+
* limit: 5,
|
|
56
|
+
* window: 60000,
|
|
57
|
+
* windowType: 'sliding',
|
|
58
|
+
* },
|
|
59
|
+
* (state) => ({ executionCount: state.executionCount })
|
|
60
|
+
* );
|
|
61
|
+
*
|
|
62
|
+
* // Monitor rate limit status
|
|
63
|
+
* const handleClick = () => {
|
|
64
|
+
* const remaining = rateLimiter.getRemainingInWindow();
|
|
65
|
+
* if (remaining > 0) {
|
|
66
|
+
* rateLimiter.maybeExecute(data);
|
|
67
|
+
* } else {
|
|
68
|
+
* showRateLimitWarning();
|
|
69
|
+
* }
|
|
70
|
+
* };
|
|
71
|
+
*
|
|
72
|
+
* // Access the selected state (will be empty object {} unless selector provided)
|
|
73
|
+
* const { executionCount, rejectionCount } = rateLimiter.state();
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
function injectRateLimiter(fn, options, selector = () => ({})) {
|
|
77
|
+
const rateLimiter = new _tanstack_pacer_rate_limiter.RateLimiter(fn, {
|
|
78
|
+
...require_pacer_context.injectPacerOptions().rateLimiter,
|
|
79
|
+
...options
|
|
80
|
+
});
|
|
81
|
+
const state = (0, _tanstack_angular_store.injectStore)(rateLimiter.store, selector);
|
|
82
|
+
return {
|
|
83
|
+
...rateLimiter,
|
|
84
|
+
state
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
exports.injectRateLimiter = injectRateLimiter;
|
|
90
|
+
//# sourceMappingURL=injectRateLimiter.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectRateLimiter.cjs","names":["RateLimiter","injectPacerOptions"],"sources":["../../src/rate-limiter/injectRateLimiter.ts"],"sourcesContent":["import { injectStore } from '@tanstack/angular-store'\nimport { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/store'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\nexport interface AngularRateLimiter<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<RateLimiter<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<RateLimiterState>>\n}\n\n/**\n * An Angular function that creates and manages a RateLimiter instance.\n *\n * This is a lower-level function that provides direct access to the RateLimiter's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * Rate limiting is a simple \"hard limit\" approach that allows executions until a maximum count is reached within\n * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,\n * it does not attempt to space out or collapse executions intelligently.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n * consistent rate of execution over time.\n *\n * For smoother execution patterns:\n * - Use throttling when you want consistent spacing between executions (e.g. UI updates)\n * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)\n * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations\n * - `rejectionCount`: Number of function executions that have been rejected due to rate limiting\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = injectRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * });\n *\n * // Opt-in to track execution count changes\n * const rateLimiter = injectRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Monitor rate limit status\n * const handleClick = () => {\n * const remaining = rateLimiter.getRemainingInWindow();\n * if (remaining > 0) {\n * rateLimiter.maybeExecute(data);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { executionCount, rejectionCount } = rateLimiter.state();\n * ```\n */\nexport function injectRateLimiter<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: RateLimiterOptions<TFn>,\n selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,\n): AngularRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().rateLimiter,\n ...options,\n } as RateLimiterOptions<TFn>\n\n const rateLimiter = new RateLimiter<TFn>(fn, mergedOptions)\n const state = injectStore(rateLimiter.store, selector)\n\n return {\n ...rateLimiter,\n state,\n } as AngularRateLimiter<TFn, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkGA,SAAgB,kBACd,IACA,SACA,kBAA0D,EAAE,GACxB;CAMpC,MAAM,cAAc,IAAIA,yCAAiB,IALnB;EACpB,GAAGC,0CAAoB,CAAC;EACxB,GAAG;EACJ,CAE0D;CAC3D,MAAM,iDAAoB,YAAY,OAAO,SAAS;AAEtD,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Signal } from "@angular/core";
|
|
2
|
+
import { Store } from "@tanstack/store";
|
|
3
|
+
import { AnyFunction } from "@tanstack/pacer/types";
|
|
4
|
+
import { RateLimiter, RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
5
|
+
|
|
6
|
+
//#region src/rate-limiter/injectRateLimiter.d.ts
|
|
7
|
+
interface AngularRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Omit<RateLimiter<TFn>, 'store'> {
|
|
8
|
+
/**
|
|
9
|
+
* Reactive state signal that will be updated when the rate limiter state changes
|
|
10
|
+
*
|
|
11
|
+
* Use this instead of `rateLimiter.store.state`
|
|
12
|
+
*/
|
|
13
|
+
readonly state: Signal<Readonly<TSelected>>;
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.
|
|
16
|
+
* The state on the store object is not reactive in Angular signals.
|
|
17
|
+
*/
|
|
18
|
+
readonly store: Store<Readonly<RateLimiterState>>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* An Angular function that creates and manages a RateLimiter instance.
|
|
22
|
+
*
|
|
23
|
+
* This is a lower-level function that provides direct access to the RateLimiter's functionality.
|
|
24
|
+
* This allows you to integrate it with any state management solution you prefer.
|
|
25
|
+
*
|
|
26
|
+
* Rate limiting is a simple "hard limit" approach that allows executions until a maximum count is reached within
|
|
27
|
+
* a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,
|
|
28
|
+
* it does not attempt to space out or collapse executions intelligently.
|
|
29
|
+
*
|
|
30
|
+
* The rate limiter supports two types of windows:
|
|
31
|
+
* - 'fixed': A strict window that resets after the window period. All executions within the window count
|
|
32
|
+
* towards the limit, and the window resets completely after the period.
|
|
33
|
+
* - 'sliding': A rolling window that allows executions as old ones expire. This provides a more
|
|
34
|
+
* consistent rate of execution over time.
|
|
35
|
+
*
|
|
36
|
+
* For smoother execution patterns:
|
|
37
|
+
* - Use throttling when you want consistent spacing between executions (e.g. UI updates)
|
|
38
|
+
* - Use debouncing when you want to collapse rapid-fire events (e.g. search input)
|
|
39
|
+
* - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)
|
|
40
|
+
*
|
|
41
|
+
* ## State Management and Selector
|
|
42
|
+
*
|
|
43
|
+
* The function uses TanStack Store for state management and wraps it with Angular signals.
|
|
44
|
+
* The `selector` parameter allows you to specify which state changes will trigger signal updates,
|
|
45
|
+
* optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
|
|
46
|
+
*
|
|
47
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
48
|
+
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
49
|
+
* full control over when your component tracks state changes.
|
|
50
|
+
*
|
|
51
|
+
* Available state properties:
|
|
52
|
+
* - `executionCount`: Number of function executions that have been completed
|
|
53
|
+
* - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations
|
|
54
|
+
* - `rejectionCount`: Number of function executions that have been rejected due to rate limiting
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* // Default behavior - no reactive state subscriptions
|
|
59
|
+
* const rateLimiter = injectRateLimiter(apiCall, {
|
|
60
|
+
* limit: 5,
|
|
61
|
+
* window: 60000,
|
|
62
|
+
* windowType: 'sliding',
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* // Opt-in to track execution count changes
|
|
66
|
+
* const rateLimiter = injectRateLimiter(
|
|
67
|
+
* apiCall,
|
|
68
|
+
* {
|
|
69
|
+
* limit: 5,
|
|
70
|
+
* window: 60000,
|
|
71
|
+
* windowType: 'sliding',
|
|
72
|
+
* },
|
|
73
|
+
* (state) => ({ executionCount: state.executionCount })
|
|
74
|
+
* );
|
|
75
|
+
*
|
|
76
|
+
* // Monitor rate limit status
|
|
77
|
+
* const handleClick = () => {
|
|
78
|
+
* const remaining = rateLimiter.getRemainingInWindow();
|
|
79
|
+
* if (remaining > 0) {
|
|
80
|
+
* rateLimiter.maybeExecute(data);
|
|
81
|
+
* } else {
|
|
82
|
+
* showRateLimitWarning();
|
|
83
|
+
* }
|
|
84
|
+
* };
|
|
85
|
+
*
|
|
86
|
+
* // Access the selected state (will be empty object {} unless selector provided)
|
|
87
|
+
* const { executionCount, rejectionCount } = rateLimiter.state();
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
declare function injectRateLimiter<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: RateLimiterOptions<TFn>, selector?: (state: RateLimiterState) => TSelected): AngularRateLimiter<TFn, TSelected>;
|
|
91
|
+
//#endregion
|
|
92
|
+
export { AngularRateLimiter, injectRateLimiter };
|
|
93
|
+
//# sourceMappingURL=injectRateLimiter.d.cts.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Signal } from "@angular/core";
|
|
2
|
+
import { RateLimiter, RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
3
|
+
import { AnyFunction } from "@tanstack/pacer/types";
|
|
4
|
+
import { Store } from "@tanstack/store";
|
|
5
|
+
|
|
6
|
+
//#region src/rate-limiter/injectRateLimiter.d.ts
|
|
7
|
+
interface AngularRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Omit<RateLimiter<TFn>, 'store'> {
|
|
8
|
+
/**
|
|
9
|
+
* Reactive state signal that will be updated when the rate limiter state changes
|
|
10
|
+
*
|
|
11
|
+
* Use this instead of `rateLimiter.store.state`
|
|
12
|
+
*/
|
|
13
|
+
readonly state: Signal<Readonly<TSelected>>;
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.
|
|
16
|
+
* The state on the store object is not reactive in Angular signals.
|
|
17
|
+
*/
|
|
18
|
+
readonly store: Store<Readonly<RateLimiterState>>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* An Angular function that creates and manages a RateLimiter instance.
|
|
22
|
+
*
|
|
23
|
+
* This is a lower-level function that provides direct access to the RateLimiter's functionality.
|
|
24
|
+
* This allows you to integrate it with any state management solution you prefer.
|
|
25
|
+
*
|
|
26
|
+
* Rate limiting is a simple "hard limit" approach that allows executions until a maximum count is reached within
|
|
27
|
+
* a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,
|
|
28
|
+
* it does not attempt to space out or collapse executions intelligently.
|
|
29
|
+
*
|
|
30
|
+
* The rate limiter supports two types of windows:
|
|
31
|
+
* - 'fixed': A strict window that resets after the window period. All executions within the window count
|
|
32
|
+
* towards the limit, and the window resets completely after the period.
|
|
33
|
+
* - 'sliding': A rolling window that allows executions as old ones expire. This provides a more
|
|
34
|
+
* consistent rate of execution over time.
|
|
35
|
+
*
|
|
36
|
+
* For smoother execution patterns:
|
|
37
|
+
* - Use throttling when you want consistent spacing between executions (e.g. UI updates)
|
|
38
|
+
* - Use debouncing when you want to collapse rapid-fire events (e.g. search input)
|
|
39
|
+
* - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)
|
|
40
|
+
*
|
|
41
|
+
* ## State Management and Selector
|
|
42
|
+
*
|
|
43
|
+
* The function uses TanStack Store for state management and wraps it with Angular signals.
|
|
44
|
+
* The `selector` parameter allows you to specify which state changes will trigger signal updates,
|
|
45
|
+
* optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
|
|
46
|
+
*
|
|
47
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
48
|
+
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
49
|
+
* full control over when your component tracks state changes.
|
|
50
|
+
*
|
|
51
|
+
* Available state properties:
|
|
52
|
+
* - `executionCount`: Number of function executions that have been completed
|
|
53
|
+
* - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations
|
|
54
|
+
* - `rejectionCount`: Number of function executions that have been rejected due to rate limiting
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* // Default behavior - no reactive state subscriptions
|
|
59
|
+
* const rateLimiter = injectRateLimiter(apiCall, {
|
|
60
|
+
* limit: 5,
|
|
61
|
+
* window: 60000,
|
|
62
|
+
* windowType: 'sliding',
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* // Opt-in to track execution count changes
|
|
66
|
+
* const rateLimiter = injectRateLimiter(
|
|
67
|
+
* apiCall,
|
|
68
|
+
* {
|
|
69
|
+
* limit: 5,
|
|
70
|
+
* window: 60000,
|
|
71
|
+
* windowType: 'sliding',
|
|
72
|
+
* },
|
|
73
|
+
* (state) => ({ executionCount: state.executionCount })
|
|
74
|
+
* );
|
|
75
|
+
*
|
|
76
|
+
* // Monitor rate limit status
|
|
77
|
+
* const handleClick = () => {
|
|
78
|
+
* const remaining = rateLimiter.getRemainingInWindow();
|
|
79
|
+
* if (remaining > 0) {
|
|
80
|
+
* rateLimiter.maybeExecute(data);
|
|
81
|
+
* } else {
|
|
82
|
+
* showRateLimitWarning();
|
|
83
|
+
* }
|
|
84
|
+
* };
|
|
85
|
+
*
|
|
86
|
+
* // Access the selected state (will be empty object {} unless selector provided)
|
|
87
|
+
* const { executionCount, rejectionCount } = rateLimiter.state();
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
declare function injectRateLimiter<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: RateLimiterOptions<TFn>, selector?: (state: RateLimiterState) => TSelected): AngularRateLimiter<TFn, TSelected>;
|
|
91
|
+
//#endregion
|
|
92
|
+
export { AngularRateLimiter, injectRateLimiter };
|
|
93
|
+
//# sourceMappingURL=injectRateLimiter.d.ts.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { injectPacerOptions } from "../provider/pacer-context.js";
|
|
2
|
+
import { injectStore } from "@tanstack/angular-store";
|
|
3
|
+
import { RateLimiter } from "@tanstack/pacer/rate-limiter";
|
|
4
|
+
|
|
5
|
+
//#region src/rate-limiter/injectRateLimiter.ts
|
|
6
|
+
/**
|
|
7
|
+
* An Angular function that creates and manages a RateLimiter instance.
|
|
8
|
+
*
|
|
9
|
+
* This is a lower-level function that provides direct access to the RateLimiter's functionality.
|
|
10
|
+
* This allows you to integrate it with any state management solution you prefer.
|
|
11
|
+
*
|
|
12
|
+
* Rate limiting is a simple "hard limit" approach that allows executions until a maximum count is reached within
|
|
13
|
+
* a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,
|
|
14
|
+
* it does not attempt to space out or collapse executions intelligently.
|
|
15
|
+
*
|
|
16
|
+
* The rate limiter supports two types of windows:
|
|
17
|
+
* - 'fixed': A strict window that resets after the window period. All executions within the window count
|
|
18
|
+
* towards the limit, and the window resets completely after the period.
|
|
19
|
+
* - 'sliding': A rolling window that allows executions as old ones expire. This provides a more
|
|
20
|
+
* consistent rate of execution over time.
|
|
21
|
+
*
|
|
22
|
+
* For smoother execution patterns:
|
|
23
|
+
* - Use throttling when you want consistent spacing between executions (e.g. UI updates)
|
|
24
|
+
* - Use debouncing when you want to collapse rapid-fire events (e.g. search input)
|
|
25
|
+
* - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)
|
|
26
|
+
*
|
|
27
|
+
* ## State Management and Selector
|
|
28
|
+
*
|
|
29
|
+
* The function uses TanStack Store for state management and wraps it with Angular signals.
|
|
30
|
+
* The `selector` parameter allows you to specify which state changes will trigger signal updates,
|
|
31
|
+
* optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
|
|
32
|
+
*
|
|
33
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
34
|
+
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
35
|
+
* full control over when your component tracks state changes.
|
|
36
|
+
*
|
|
37
|
+
* Available state properties:
|
|
38
|
+
* - `executionCount`: Number of function executions that have been completed
|
|
39
|
+
* - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations
|
|
40
|
+
* - `rejectionCount`: Number of function executions that have been rejected due to rate limiting
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* // Default behavior - no reactive state subscriptions
|
|
45
|
+
* const rateLimiter = injectRateLimiter(apiCall, {
|
|
46
|
+
* limit: 5,
|
|
47
|
+
* window: 60000,
|
|
48
|
+
* windowType: 'sliding',
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* // Opt-in to track execution count changes
|
|
52
|
+
* const rateLimiter = injectRateLimiter(
|
|
53
|
+
* apiCall,
|
|
54
|
+
* {
|
|
55
|
+
* limit: 5,
|
|
56
|
+
* window: 60000,
|
|
57
|
+
* windowType: 'sliding',
|
|
58
|
+
* },
|
|
59
|
+
* (state) => ({ executionCount: state.executionCount })
|
|
60
|
+
* );
|
|
61
|
+
*
|
|
62
|
+
* // Monitor rate limit status
|
|
63
|
+
* const handleClick = () => {
|
|
64
|
+
* const remaining = rateLimiter.getRemainingInWindow();
|
|
65
|
+
* if (remaining > 0) {
|
|
66
|
+
* rateLimiter.maybeExecute(data);
|
|
67
|
+
* } else {
|
|
68
|
+
* showRateLimitWarning();
|
|
69
|
+
* }
|
|
70
|
+
* };
|
|
71
|
+
*
|
|
72
|
+
* // Access the selected state (will be empty object {} unless selector provided)
|
|
73
|
+
* const { executionCount, rejectionCount } = rateLimiter.state();
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
function injectRateLimiter(fn, options, selector = () => ({})) {
|
|
77
|
+
const rateLimiter = new RateLimiter(fn, {
|
|
78
|
+
...injectPacerOptions().rateLimiter,
|
|
79
|
+
...options
|
|
80
|
+
});
|
|
81
|
+
const state = injectStore(rateLimiter.store, selector);
|
|
82
|
+
return {
|
|
83
|
+
...rateLimiter,
|
|
84
|
+
state
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
export { injectRateLimiter };
|
|
90
|
+
//# sourceMappingURL=injectRateLimiter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectRateLimiter.js","names":[],"sources":["../../src/rate-limiter/injectRateLimiter.ts"],"sourcesContent":["import { injectStore } from '@tanstack/angular-store'\nimport { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/store'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\nexport interface AngularRateLimiter<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<RateLimiter<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<RateLimiterState>>\n}\n\n/**\n * An Angular function that creates and manages a RateLimiter instance.\n *\n * This is a lower-level function that provides direct access to the RateLimiter's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * Rate limiting is a simple \"hard limit\" approach that allows executions until a maximum count is reached within\n * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,\n * it does not attempt to space out or collapse executions intelligently.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n * consistent rate of execution over time.\n *\n * For smoother execution patterns:\n * - Use throttling when you want consistent spacing between executions (e.g. UI updates)\n * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)\n * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations\n * - `rejectionCount`: Number of function executions that have been rejected due to rate limiting\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = injectRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * });\n *\n * // Opt-in to track execution count changes\n * const rateLimiter = injectRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Monitor rate limit status\n * const handleClick = () => {\n * const remaining = rateLimiter.getRemainingInWindow();\n * if (remaining > 0) {\n * rateLimiter.maybeExecute(data);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { executionCount, rejectionCount } = rateLimiter.state();\n * ```\n */\nexport function injectRateLimiter<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: RateLimiterOptions<TFn>,\n selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,\n): AngularRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().rateLimiter,\n ...options,\n } as RateLimiterOptions<TFn>\n\n const rateLimiter = new RateLimiter<TFn>(fn, mergedOptions)\n const state = injectStore(rateLimiter.store, selector)\n\n return {\n ...rateLimiter,\n state,\n } as AngularRateLimiter<TFn, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkGA,SAAgB,kBACd,IACA,SACA,kBAA0D,EAAE,GACxB;CAMpC,MAAM,cAAc,IAAI,YAAiB,IALnB;EACpB,GAAG,oBAAoB,CAAC;EACxB,GAAG;EACJ,CAE0D;CAC3D,MAAM,QAAQ,YAAY,YAAY,OAAO,SAAS;AAEtD,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_injectThrottler = require('./injectThrottler.cjs');
|
|
3
|
+
const require_injectThrottledCallback = require('./injectThrottledCallback.cjs');
|
|
4
|
+
const require_injectThrottledSignal = require('./injectThrottledSignal.cjs');
|
|
5
|
+
const require_injectThrottledValue = require('./injectThrottledValue.cjs');
|
|
6
|
+
|
|
7
|
+
exports.injectThrottledCallback = require_injectThrottledCallback.injectThrottledCallback;
|
|
8
|
+
exports.injectThrottledSignal = require_injectThrottledSignal.injectThrottledSignal;
|
|
9
|
+
exports.injectThrottledValue = require_injectThrottledValue.injectThrottledValue;
|
|
10
|
+
exports.injectThrottler = require_injectThrottler.injectThrottler;
|
|
11
|
+
var _tanstack_pacer_throttler = require("@tanstack/pacer/throttler");
|
|
12
|
+
Object.keys(_tanstack_pacer_throttler).forEach(function (k) {
|
|
13
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return _tanstack_pacer_throttler[k]; }
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { injectThrottledCallback } from "./injectThrottledCallback.cjs";
|
|
2
|
+
import { AngularThrottler, injectThrottler } from "./injectThrottler.cjs";
|
|
3
|
+
import { ThrottledSignal, injectThrottledSignal } from "./injectThrottledSignal.cjs";
|
|
4
|
+
import { injectThrottledValue } from "./injectThrottledValue.cjs";
|
|
5
|
+
export * from "@tanstack/pacer/throttler";
|
|
6
|
+
export { AngularThrottler, ThrottledSignal, injectThrottledCallback, injectThrottledSignal, injectThrottledValue, injectThrottler };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { injectThrottledCallback } from "./injectThrottledCallback.js";
|
|
2
|
+
import { AngularThrottler, injectThrottler } from "./injectThrottler.js";
|
|
3
|
+
import { ThrottledSignal, injectThrottledSignal } from "./injectThrottledSignal.js";
|
|
4
|
+
import { injectThrottledValue } from "./injectThrottledValue.js";
|
|
5
|
+
export * from "@tanstack/pacer/throttler";
|
|
6
|
+
export { AngularThrottler, ThrottledSignal, injectThrottledCallback, injectThrottledSignal, injectThrottledValue, injectThrottler };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { injectThrottler } from "./injectThrottler.js";
|
|
2
|
+
import { injectThrottledCallback } from "./injectThrottledCallback.js";
|
|
3
|
+
import { injectThrottledSignal } from "./injectThrottledSignal.js";
|
|
4
|
+
import { injectThrottledValue } from "./injectThrottledValue.js";
|
|
5
|
+
|
|
6
|
+
export * from "@tanstack/pacer/throttler"
|
|
7
|
+
|
|
8
|
+
export { injectThrottledCallback, injectThrottledSignal, injectThrottledValue, injectThrottler };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const require_injectThrottler = require('./injectThrottler.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/throttler/injectThrottledCallback.ts
|
|
4
|
+
/**
|
|
5
|
+
* An Angular function that creates a throttled version of a callback function.
|
|
6
|
+
* This function is essentially a wrapper around `injectThrottler` that provides
|
|
7
|
+
* a simplified API for basic throttling needs.
|
|
8
|
+
*
|
|
9
|
+
* The throttled function will execute at most once within the specified wait time.
|
|
10
|
+
* If called multiple times within the wait period, only the first call (if leading is enabled)
|
|
11
|
+
* or the last call (if trailing is enabled) will execute.
|
|
12
|
+
*
|
|
13
|
+
* This function provides a simpler API compared to `injectThrottler`, making it ideal for basic
|
|
14
|
+
* throttling needs. However, it does not expose the underlying Throttler instance.
|
|
15
|
+
*
|
|
16
|
+
* For advanced usage requiring features like:
|
|
17
|
+
* - Manual cancellation
|
|
18
|
+
* - Access to execution counts
|
|
19
|
+
* - State tracking
|
|
20
|
+
*
|
|
21
|
+
* Consider using the `injectThrottler` function instead.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* // Throttle a scroll handler
|
|
26
|
+
* const handleScroll = injectThrottledCallback((scrollY: number) => {
|
|
27
|
+
* updateScrollPosition(scrollY);
|
|
28
|
+
* }, {
|
|
29
|
+
* wait: 100 // Execute at most once per 100ms
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Use in an event listener
|
|
33
|
+
* window.addEventListener('scroll', () => {
|
|
34
|
+
* handleScroll(window.scrollY);
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function injectThrottledCallback(fn, options) {
|
|
39
|
+
const throttler = require_injectThrottler.injectThrottler(fn, options);
|
|
40
|
+
return (...args) => throttler.maybeExecute(...args);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
exports.injectThrottledCallback = injectThrottledCallback;
|
|
45
|
+
//# sourceMappingURL=injectThrottledCallback.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectThrottledCallback.cjs","names":["injectThrottler"],"sources":["../../src/throttler/injectThrottledCallback.ts"],"sourcesContent":["import { injectThrottler } from './injectThrottler'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\nimport type { AnyFunction } from '@tanstack/pacer/types'\n\n/**\n * An Angular function that creates a throttled version of a callback function.\n * This function is essentially a wrapper around `injectThrottler` that provides\n * a simplified API for basic throttling needs.\n *\n * The throttled function will execute at most once within the specified wait time.\n * If called multiple times within the wait period, only the first call (if leading is enabled)\n * or the last call (if trailing is enabled) will execute.\n *\n * This function provides a simpler API compared to `injectThrottler`, making it ideal for basic\n * throttling needs. However, it does not expose the underlying Throttler instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - State tracking\n *\n * Consider using the `injectThrottler` function instead.\n *\n * @example\n * ```ts\n * // Throttle a scroll handler\n * const handleScroll = injectThrottledCallback((scrollY: number) => {\n * updateScrollPosition(scrollY);\n * }, {\n * wait: 100 // Execute at most once per 100ms\n * });\n *\n * // Use in an event listener\n * window.addEventListener('scroll', () => {\n * handleScroll(window.scrollY);\n * });\n * ```\n */\nexport function injectThrottledCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: ThrottlerOptions<TFn>,\n): (...args: Parameters<TFn>) => void {\n const throttler = injectThrottler(fn, options)\n return (...args: Parameters<TFn>) => throttler.maybeExecute(...args)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,wBACd,IACA,SACoC;CACpC,MAAM,YAAYA,wCAAgB,IAAI,QAAQ;AAC9C,SAAQ,GAAG,SAA0B,UAAU,aAAa,GAAG,KAAK"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AnyFunction } from "@tanstack/pacer/types";
|
|
2
|
+
import { ThrottlerOptions } from "@tanstack/pacer/throttler";
|
|
3
|
+
|
|
4
|
+
//#region src/throttler/injectThrottledCallback.d.ts
|
|
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
|
+
declare function injectThrottledCallback<TFn extends AnyFunction>(fn: TFn, options: ThrottlerOptions<TFn>): (...args: Parameters<TFn>) => void;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { injectThrottledCallback };
|
|
42
|
+
//# sourceMappingURL=injectThrottledCallback.d.cts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ThrottlerOptions } from "@tanstack/pacer/throttler";
|
|
2
|
+
import { AnyFunction } from "@tanstack/pacer/types";
|
|
3
|
+
|
|
4
|
+
//#region src/throttler/injectThrottledCallback.d.ts
|
|
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
|
+
declare function injectThrottledCallback<TFn extends AnyFunction>(fn: TFn, options: ThrottlerOptions<TFn>): (...args: Parameters<TFn>) => void;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { injectThrottledCallback };
|
|
42
|
+
//# sourceMappingURL=injectThrottledCallback.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { injectThrottler } from "./injectThrottler.js";
|
|
2
|
+
|
|
3
|
+
//#region src/throttler/injectThrottledCallback.ts
|
|
4
|
+
/**
|
|
5
|
+
* An Angular function that creates a throttled version of a callback function.
|
|
6
|
+
* This function is essentially a wrapper around `injectThrottler` that provides
|
|
7
|
+
* a simplified API for basic throttling needs.
|
|
8
|
+
*
|
|
9
|
+
* The throttled function will execute at most once within the specified wait time.
|
|
10
|
+
* If called multiple times within the wait period, only the first call (if leading is enabled)
|
|
11
|
+
* or the last call (if trailing is enabled) will execute.
|
|
12
|
+
*
|
|
13
|
+
* This function provides a simpler API compared to `injectThrottler`, making it ideal for basic
|
|
14
|
+
* throttling needs. However, it does not expose the underlying Throttler instance.
|
|
15
|
+
*
|
|
16
|
+
* For advanced usage requiring features like:
|
|
17
|
+
* - Manual cancellation
|
|
18
|
+
* - Access to execution counts
|
|
19
|
+
* - State tracking
|
|
20
|
+
*
|
|
21
|
+
* Consider using the `injectThrottler` function instead.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* // Throttle a scroll handler
|
|
26
|
+
* const handleScroll = injectThrottledCallback((scrollY: number) => {
|
|
27
|
+
* updateScrollPosition(scrollY);
|
|
28
|
+
* }, {
|
|
29
|
+
* wait: 100 // Execute at most once per 100ms
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Use in an event listener
|
|
33
|
+
* window.addEventListener('scroll', () => {
|
|
34
|
+
* handleScroll(window.scrollY);
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function injectThrottledCallback(fn, options) {
|
|
39
|
+
const throttler = injectThrottler(fn, options);
|
|
40
|
+
return (...args) => throttler.maybeExecute(...args);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { injectThrottledCallback };
|
|
45
|
+
//# sourceMappingURL=injectThrottledCallback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectThrottledCallback.js","names":[],"sources":["../../src/throttler/injectThrottledCallback.ts"],"sourcesContent":["import { injectThrottler } from './injectThrottler'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\nimport type { AnyFunction } from '@tanstack/pacer/types'\n\n/**\n * An Angular function that creates a throttled version of a callback function.\n * This function is essentially a wrapper around `injectThrottler` that provides\n * a simplified API for basic throttling needs.\n *\n * The throttled function will execute at most once within the specified wait time.\n * If called multiple times within the wait period, only the first call (if leading is enabled)\n * or the last call (if trailing is enabled) will execute.\n *\n * This function provides a simpler API compared to `injectThrottler`, making it ideal for basic\n * throttling needs. However, it does not expose the underlying Throttler instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - State tracking\n *\n * Consider using the `injectThrottler` function instead.\n *\n * @example\n * ```ts\n * // Throttle a scroll handler\n * const handleScroll = injectThrottledCallback((scrollY: number) => {\n * updateScrollPosition(scrollY);\n * }, {\n * wait: 100 // Execute at most once per 100ms\n * });\n *\n * // Use in an event listener\n * window.addEventListener('scroll', () => {\n * handleScroll(window.scrollY);\n * });\n * ```\n */\nexport function injectThrottledCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: ThrottlerOptions<TFn>,\n): (...args: Parameters<TFn>) => void {\n const throttler = injectThrottler(fn, options)\n return (...args: Parameters<TFn>) => throttler.maybeExecute(...args)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,wBACd,IACA,SACoC;CACpC,MAAM,YAAY,gBAAgB,IAAI,QAAQ;AAC9C,SAAQ,GAAG,SAA0B,UAAU,aAAa,GAAG,KAAK"}
|