@tanstack/angular-pacer 0.23.0 → 0.23.1
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/dist/async-batcher/injectAsyncBatchedCallback.cjs.map +1 -1
- package/dist/async-batcher/injectAsyncBatchedCallback.js.map +1 -1
- package/dist/async-batcher/injectAsyncBatcher.cjs.map +1 -1
- package/dist/async-batcher/injectAsyncBatcher.js.map +1 -1
- package/dist/async-debouncer/injectAsyncDebouncedCallback.cjs.map +1 -1
- package/dist/async-debouncer/injectAsyncDebouncedCallback.js.map +1 -1
- package/dist/async-debouncer/injectAsyncDebouncer.cjs.map +1 -1
- package/dist/async-debouncer/injectAsyncDebouncer.js.map +1 -1
- package/dist/async-queuer/injectAsyncQueuedSignal.cjs.map +1 -1
- package/dist/async-queuer/injectAsyncQueuedSignal.js.map +1 -1
- package/dist/async-queuer/injectAsyncQueuer.cjs.map +1 -1
- package/dist/async-queuer/injectAsyncQueuer.js.map +1 -1
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.cjs.map +1 -1
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.js.map +1 -1
- package/dist/async-rate-limiter/injectAsyncRateLimiter.cjs.map +1 -1
- package/dist/async-rate-limiter/injectAsyncRateLimiter.js.map +1 -1
- package/dist/async-throttler/injectAsyncThrottledCallback.cjs.map +1 -1
- package/dist/async-throttler/injectAsyncThrottledCallback.js.map +1 -1
- package/dist/async-throttler/injectAsyncThrottler.cjs.map +1 -1
- package/dist/async-throttler/injectAsyncThrottler.js.map +1 -1
- package/dist/batcher/injectBatchedCallback.cjs.map +1 -1
- package/dist/batcher/injectBatchedCallback.js.map +1 -1
- package/dist/batcher/injectBatcher.cjs.map +1 -1
- package/dist/batcher/injectBatcher.js.map +1 -1
- package/dist/debouncer/injectDebouncedCallback.cjs.map +1 -1
- package/dist/debouncer/injectDebouncedCallback.js.map +1 -1
- package/dist/debouncer/injectDebouncedSignal.cjs.map +1 -1
- package/dist/debouncer/injectDebouncedSignal.js.map +1 -1
- package/dist/debouncer/injectDebouncedValue.cjs.map +1 -1
- package/dist/debouncer/injectDebouncedValue.js.map +1 -1
- package/dist/debouncer/injectDebouncer.cjs.map +1 -1
- package/dist/debouncer/injectDebouncer.js.map +1 -1
- package/dist/provider/pacer-context.cjs.map +1 -1
- package/dist/provider/pacer-context.js.map +1 -1
- package/dist/provider/pacer-provider.cjs.map +1 -1
- package/dist/provider/pacer-provider.js.map +1 -1
- package/dist/queuer/injectQueuedSignal.cjs.map +1 -1
- package/dist/queuer/injectQueuedSignal.js.map +1 -1
- package/dist/queuer/injectQueuedValue.cjs.map +1 -1
- package/dist/queuer/injectQueuedValue.js.map +1 -1
- package/dist/queuer/injectQueuer.cjs.map +1 -1
- package/dist/queuer/injectQueuer.js.map +1 -1
- package/dist/rate-limiter/injectRateLimitedCallback.cjs.map +1 -1
- package/dist/rate-limiter/injectRateLimitedCallback.js.map +1 -1
- package/dist/rate-limiter/injectRateLimitedSignal.cjs.map +1 -1
- package/dist/rate-limiter/injectRateLimitedSignal.js.map +1 -1
- package/dist/rate-limiter/injectRateLimitedValue.cjs.map +1 -1
- package/dist/rate-limiter/injectRateLimitedValue.js.map +1 -1
- package/dist/rate-limiter/injectRateLimiter.cjs.map +1 -1
- package/dist/rate-limiter/injectRateLimiter.js.map +1 -1
- package/dist/throttler/injectThrottledCallback.cjs.map +1 -1
- package/dist/throttler/injectThrottledCallback.js.map +1 -1
- package/dist/throttler/injectThrottledSignal.cjs.map +1 -1
- package/dist/throttler/injectThrottledSignal.js.map +1 -1
- package/dist/throttler/injectThrottledValue.cjs.map +1 -1
- package/dist/throttler/injectThrottledValue.js.map +1 -1
- package/dist/throttler/injectThrottler.cjs.map +1 -1
- package/dist/throttler/injectThrottler.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +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;
|
|
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;CAC9C,QAAQ,GAAG,SAA0B,UAAU,aAAa,GAAG,KAAK"}
|
|
@@ -1 +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;
|
|
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;CAC9C,QAAQ,GAAG,SAA0B,UAAU,aAAa,GAAG,KAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectThrottledSignal.cjs","names":["injectThrottler"],"sources":["../../src/throttler/injectThrottledSignal.ts"],"sourcesContent":["import { signal } from '@angular/core'\nimport { injectThrottler } from './injectThrottler'\nimport type { AngularThrottler } from './injectThrottler'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\nexport interface ThrottledSignal<TValue, TSelected = {}> {\n (): TValue\n set: Setter<TValue>\n throttler: AngularThrottler<Setter<TValue>, TSelected>\n}\n\n/**\n * An Angular function that creates a throttled state signal, combining Angular's signal with throttling functionality.\n * This function provides both the current throttled value and methods to update it.\n *\n * The state value is updated at most once within the specified wait time.\n * This is useful for handling frequent state updates that should be rate-limited, like scroll positions\n * or mouse movements.\n *\n * The function returns a callable object:\n * - `throttled()`: Get the current throttled value\n * - `throttled.set(...)`: Set or update the throttled value (throttled via maybeExecute)\n * - `throttled.throttler`: The throttler 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 throttler instance.\n * The `selector` parameter allows you to specify which throttler state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * Available throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * const throttledScrollY = injectThrottledSignal(0, { wait: 100 })\n *\n * // Get value\n * console.log(throttledScrollY())\n *\n * // Set/update value (throttled)\n * throttledScrollY.set(window.scrollY)\n *\n * // Access throttler\n * console.log(throttledScrollY.throttler.state().isPending)\n * ```\n */\nexport function injectThrottledSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected> {\n const throttledValue = signal<TValue>(value)\n\n const throttler = injectThrottler(\n (newValue: TValue | ((prev: TValue) => TValue)) => {\n if (typeof newValue === 'function') {\n throttledValue.update(newValue as (prev: TValue) => TValue)\n } else {\n throttledValue.set(newValue)\n }\n },\n initialOptions,\n selector,\n )\n\n const set: Setter<TValue> = (\n newValue: TValue | ((prev: TValue) => TValue),\n ) => {\n throttler.maybeExecute(newValue)\n }\n\n const throttled = Object.assign(() => throttledValue(), {\n set,\n throttler,\n }) as ThrottledSignal<TValue, TSelected>\n\n return throttled\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,sBACd,OACA,gBACA,UACoC;CACpC,MAAM,2CAAgC,MAAM;CAE5C,MAAM,YAAYA,yCACf,aAAkD;
|
|
1
|
+
{"version":3,"file":"injectThrottledSignal.cjs","names":["injectThrottler"],"sources":["../../src/throttler/injectThrottledSignal.ts"],"sourcesContent":["import { signal } from '@angular/core'\nimport { injectThrottler } from './injectThrottler'\nimport type { AngularThrottler } from './injectThrottler'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\nexport interface ThrottledSignal<TValue, TSelected = {}> {\n (): TValue\n set: Setter<TValue>\n throttler: AngularThrottler<Setter<TValue>, TSelected>\n}\n\n/**\n * An Angular function that creates a throttled state signal, combining Angular's signal with throttling functionality.\n * This function provides both the current throttled value and methods to update it.\n *\n * The state value is updated at most once within the specified wait time.\n * This is useful for handling frequent state updates that should be rate-limited, like scroll positions\n * or mouse movements.\n *\n * The function returns a callable object:\n * - `throttled()`: Get the current throttled value\n * - `throttled.set(...)`: Set or update the throttled value (throttled via maybeExecute)\n * - `throttled.throttler`: The throttler 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 throttler instance.\n * The `selector` parameter allows you to specify which throttler state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * Available throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * const throttledScrollY = injectThrottledSignal(0, { wait: 100 })\n *\n * // Get value\n * console.log(throttledScrollY())\n *\n * // Set/update value (throttled)\n * throttledScrollY.set(window.scrollY)\n *\n * // Access throttler\n * console.log(throttledScrollY.throttler.state().isPending)\n * ```\n */\nexport function injectThrottledSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected> {\n const throttledValue = signal<TValue>(value)\n\n const throttler = injectThrottler(\n (newValue: TValue | ((prev: TValue) => TValue)) => {\n if (typeof newValue === 'function') {\n throttledValue.update(newValue as (prev: TValue) => TValue)\n } else {\n throttledValue.set(newValue)\n }\n },\n initialOptions,\n selector,\n )\n\n const set: Setter<TValue> = (\n newValue: TValue | ((prev: TValue) => TValue),\n ) => {\n throttler.maybeExecute(newValue)\n }\n\n const throttled = Object.assign(() => throttledValue(), {\n set,\n throttler,\n }) as ThrottledSignal<TValue, TSelected>\n\n return throttled\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,sBACd,OACA,gBACA,UACoC;CACpC,MAAM,2CAAgC,MAAM;CAE5C,MAAM,YAAYA,yCACf,aAAkD;EACjD,IAAI,OAAO,aAAa,YACtB,eAAe,OAAO,SAAqC;OAE3D,eAAe,IAAI,SAAS;IAGhC,gBACA,SACD;CAED,MAAM,OACJ,aACG;EACH,UAAU,aAAa,SAAS;;CAQlC,OALkB,OAAO,aAAa,gBAAgB,EAAE;EACtD;EACA;EACD,CAEe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectThrottledSignal.js","names":[],"sources":["../../src/throttler/injectThrottledSignal.ts"],"sourcesContent":["import { signal } from '@angular/core'\nimport { injectThrottler } from './injectThrottler'\nimport type { AngularThrottler } from './injectThrottler'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\nexport interface ThrottledSignal<TValue, TSelected = {}> {\n (): TValue\n set: Setter<TValue>\n throttler: AngularThrottler<Setter<TValue>, TSelected>\n}\n\n/**\n * An Angular function that creates a throttled state signal, combining Angular's signal with throttling functionality.\n * This function provides both the current throttled value and methods to update it.\n *\n * The state value is updated at most once within the specified wait time.\n * This is useful for handling frequent state updates that should be rate-limited, like scroll positions\n * or mouse movements.\n *\n * The function returns a callable object:\n * - `throttled()`: Get the current throttled value\n * - `throttled.set(...)`: Set or update the throttled value (throttled via maybeExecute)\n * - `throttled.throttler`: The throttler 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 throttler instance.\n * The `selector` parameter allows you to specify which throttler state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * Available throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * const throttledScrollY = injectThrottledSignal(0, { wait: 100 })\n *\n * // Get value\n * console.log(throttledScrollY())\n *\n * // Set/update value (throttled)\n * throttledScrollY.set(window.scrollY)\n *\n * // Access throttler\n * console.log(throttledScrollY.throttler.state().isPending)\n * ```\n */\nexport function injectThrottledSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected> {\n const throttledValue = signal<TValue>(value)\n\n const throttler = injectThrottler(\n (newValue: TValue | ((prev: TValue) => TValue)) => {\n if (typeof newValue === 'function') {\n throttledValue.update(newValue as (prev: TValue) => TValue)\n } else {\n throttledValue.set(newValue)\n }\n },\n initialOptions,\n selector,\n )\n\n const set: Setter<TValue> = (\n newValue: TValue | ((prev: TValue) => TValue),\n ) => {\n throttler.maybeExecute(newValue)\n }\n\n const throttled = Object.assign(() => throttledValue(), {\n set,\n throttler,\n }) as ThrottledSignal<TValue, TSelected>\n\n return throttled\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,sBACd,OACA,gBACA,UACoC;CACpC,MAAM,iBAAiB,OAAe,MAAM;CAE5C,MAAM,YAAY,iBACf,aAAkD;
|
|
1
|
+
{"version":3,"file":"injectThrottledSignal.js","names":[],"sources":["../../src/throttler/injectThrottledSignal.ts"],"sourcesContent":["import { signal } from '@angular/core'\nimport { injectThrottler } from './injectThrottler'\nimport type { AngularThrottler } from './injectThrottler'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\nexport interface ThrottledSignal<TValue, TSelected = {}> {\n (): TValue\n set: Setter<TValue>\n throttler: AngularThrottler<Setter<TValue>, TSelected>\n}\n\n/**\n * An Angular function that creates a throttled state signal, combining Angular's signal with throttling functionality.\n * This function provides both the current throttled value and methods to update it.\n *\n * The state value is updated at most once within the specified wait time.\n * This is useful for handling frequent state updates that should be rate-limited, like scroll positions\n * or mouse movements.\n *\n * The function returns a callable object:\n * - `throttled()`: Get the current throttled value\n * - `throttled.set(...)`: Set or update the throttled value (throttled via maybeExecute)\n * - `throttled.throttler`: The throttler 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 throttler instance.\n * The `selector` parameter allows you to specify which throttler state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * Available throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * const throttledScrollY = injectThrottledSignal(0, { wait: 100 })\n *\n * // Get value\n * console.log(throttledScrollY())\n *\n * // Set/update value (throttled)\n * throttledScrollY.set(window.scrollY)\n *\n * // Access throttler\n * console.log(throttledScrollY.throttler.state().isPending)\n * ```\n */\nexport function injectThrottledSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected> {\n const throttledValue = signal<TValue>(value)\n\n const throttler = injectThrottler(\n (newValue: TValue | ((prev: TValue) => TValue)) => {\n if (typeof newValue === 'function') {\n throttledValue.update(newValue as (prev: TValue) => TValue)\n } else {\n throttledValue.set(newValue)\n }\n },\n initialOptions,\n selector,\n )\n\n const set: Setter<TValue> = (\n newValue: TValue | ((prev: TValue) => TValue),\n ) => {\n throttler.maybeExecute(newValue)\n }\n\n const throttled = Object.assign(() => throttledValue(), {\n set,\n throttler,\n }) as ThrottledSignal<TValue, TSelected>\n\n return throttled\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,sBACd,OACA,gBACA,UACoC;CACpC,MAAM,iBAAiB,OAAe,MAAM;CAE5C,MAAM,YAAY,iBACf,aAAkD;EACjD,IAAI,OAAO,aAAa,YACtB,eAAe,OAAO,SAAqC;OAE3D,eAAe,IAAI,SAAS;IAGhC,gBACA,SACD;CAED,MAAM,OACJ,aACG;EACH,UAAU,aAAa,SAAS;;CAQlC,OALkB,OAAO,aAAa,gBAAgB,EAAE;EACtD;EACA;EACD,CAEe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectThrottledValue.cjs","names":["injectThrottledSignal"],"sources":["../../src/throttler/injectThrottledValue.ts"],"sourcesContent":["import { effect } from '@angular/core'\nimport { injectThrottledSignal } from './injectThrottledSignal'\nimport type { ThrottledSignal } from './injectThrottledSignal'\nimport type { Signal } from '@angular/core'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\n/**\n * An Angular function that creates a throttled value that updates at most once within a specified time window.\n * Unlike injectThrottledSignal, this function automatically tracks changes to the input signal\n * and updates the throttled value accordingly.\n *\n * The throttled value will update at most once within the specified wait time, regardless of\n * how frequently the input value changes.\n *\n * This is useful for deriving throttled values from signals that change frequently,\n * like scroll positions or mouse coordinates, where you want to limit how often downstream effects\n * or calculations occur.\n *\n * The function returns a throttled signal object containing:\n * - A Signal that provides the current throttled value\n * - The throttler instance with control methods\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * Available throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const scrollY = signal(0)\n * const throttledScrollY = injectThrottledValue(scrollY, {\n * wait: 100, // Update at most once per 100ms\n * })\n *\n * // Opt-in to reactive updates when pending state changes\n * const throttledScrollYWithState = injectThrottledValue(\n * scrollY,\n * { wait: 100 },\n * (state) => ({ isPending: state.isPending }),\n * )\n *\n * // Read the throttled signal value\n * effect(() => {\n * updateUI(throttledScrollY())\n * })\n *\n * // Access throttler state via the returned object's state() signal\n * console.log('Is pending:', throttledScrollYWithState.state().isPending)\n *\n * // Control the throttler\n * throttledScrollY.cancel() // Cancel any pending updates\n * ```\n */\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected>\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValue: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected>\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValueOrOptions: TValue | ThrottlerOptions<Setter<TValue>>,\n initialOptionsOrSelector?:\n | ThrottlerOptions<Setter<TValue>>\n | ((state: ThrottlerState<Setter<TValue>>) => TSelected),\n maybeSelector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected> {\n const hasSelector = typeof initialOptionsOrSelector === 'function'\n\n const hasInitialValue =\n (initialOptionsOrSelector !== undefined && !hasSelector) ||\n maybeSelector !== undefined\n\n const initialValue = hasInitialValue\n ? (initialValueOrOptions as TValue)\n : (undefined as unknown as TValue)\n const initialOptions = hasInitialValue\n ? (initialOptionsOrSelector as ThrottlerOptions<Setter<TValue>>)\n : (initialValueOrOptions as ThrottlerOptions<Setter<TValue>>)\n const selector = hasInitialValue\n ? maybeSelector\n : (initialOptionsOrSelector as\n | ((state: ThrottlerState<Setter<TValue>>) => TSelected)\n | undefined)\n\n const throttledValue = injectThrottledSignal(\n initialValue,\n initialOptions,\n selector,\n )\n\n effect(() => {\n const latest = value()\n throttledValue.set(latest)\n })\n\n return throttledValue\n}\n"],"mappings":";;;;AAqFA,SAAgB,qBACd,OACA,uBACA,0BAGA,eACoC;CAGpC,MAAM,kBACH,6BAA6B,UAAa,EAHzB,OAAO,6BAA6B,eAItD,kBAAkB;CAcpB,MAAM,iBAAiBA,oDAZF,kBAChB,wBACA,QACkB,kBAClB,2BACA,uBACY,kBACb,gBACC,yBAQJ;
|
|
1
|
+
{"version":3,"file":"injectThrottledValue.cjs","names":["injectThrottledSignal"],"sources":["../../src/throttler/injectThrottledValue.ts"],"sourcesContent":["import { effect } from '@angular/core'\nimport { injectThrottledSignal } from './injectThrottledSignal'\nimport type { ThrottledSignal } from './injectThrottledSignal'\nimport type { Signal } from '@angular/core'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\n/**\n * An Angular function that creates a throttled value that updates at most once within a specified time window.\n * Unlike injectThrottledSignal, this function automatically tracks changes to the input signal\n * and updates the throttled value accordingly.\n *\n * The throttled value will update at most once within the specified wait time, regardless of\n * how frequently the input value changes.\n *\n * This is useful for deriving throttled values from signals that change frequently,\n * like scroll positions or mouse coordinates, where you want to limit how often downstream effects\n * or calculations occur.\n *\n * The function returns a throttled signal object containing:\n * - A Signal that provides the current throttled value\n * - The throttler instance with control methods\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * Available throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const scrollY = signal(0)\n * const throttledScrollY = injectThrottledValue(scrollY, {\n * wait: 100, // Update at most once per 100ms\n * })\n *\n * // Opt-in to reactive updates when pending state changes\n * const throttledScrollYWithState = injectThrottledValue(\n * scrollY,\n * { wait: 100 },\n * (state) => ({ isPending: state.isPending }),\n * )\n *\n * // Read the throttled signal value\n * effect(() => {\n * updateUI(throttledScrollY())\n * })\n *\n * // Access throttler state via the returned object's state() signal\n * console.log('Is pending:', throttledScrollYWithState.state().isPending)\n *\n * // Control the throttler\n * throttledScrollY.cancel() // Cancel any pending updates\n * ```\n */\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected>\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValue: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected>\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValueOrOptions: TValue | ThrottlerOptions<Setter<TValue>>,\n initialOptionsOrSelector?:\n | ThrottlerOptions<Setter<TValue>>\n | ((state: ThrottlerState<Setter<TValue>>) => TSelected),\n maybeSelector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected> {\n const hasSelector = typeof initialOptionsOrSelector === 'function'\n\n const hasInitialValue =\n (initialOptionsOrSelector !== undefined && !hasSelector) ||\n maybeSelector !== undefined\n\n const initialValue = hasInitialValue\n ? (initialValueOrOptions as TValue)\n : (undefined as unknown as TValue)\n const initialOptions = hasInitialValue\n ? (initialOptionsOrSelector as ThrottlerOptions<Setter<TValue>>)\n : (initialValueOrOptions as ThrottlerOptions<Setter<TValue>>)\n const selector = hasInitialValue\n ? maybeSelector\n : (initialOptionsOrSelector as\n | ((state: ThrottlerState<Setter<TValue>>) => TSelected)\n | undefined)\n\n const throttledValue = injectThrottledSignal(\n initialValue,\n initialOptions,\n selector,\n )\n\n effect(() => {\n const latest = value()\n throttledValue.set(latest)\n })\n\n return throttledValue\n}\n"],"mappings":";;;;AAqFA,SAAgB,qBACd,OACA,uBACA,0BAGA,eACoC;CAGpC,MAAM,kBACH,6BAA6B,UAAa,EAHzB,OAAO,6BAA6B,eAItD,kBAAkB;CAcpB,MAAM,iBAAiBA,oDAZF,kBAChB,wBACA,QACkB,kBAClB,2BACA,uBACY,kBACb,gBACC,yBAQJ;CAED,gCAAa;EACX,MAAM,SAAS,OAAO;EACtB,eAAe,IAAI,OAAO;GAC1B;CAEF,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectThrottledValue.js","names":[],"sources":["../../src/throttler/injectThrottledValue.ts"],"sourcesContent":["import { effect } from '@angular/core'\nimport { injectThrottledSignal } from './injectThrottledSignal'\nimport type { ThrottledSignal } from './injectThrottledSignal'\nimport type { Signal } from '@angular/core'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\n/**\n * An Angular function that creates a throttled value that updates at most once within a specified time window.\n * Unlike injectThrottledSignal, this function automatically tracks changes to the input signal\n * and updates the throttled value accordingly.\n *\n * The throttled value will update at most once within the specified wait time, regardless of\n * how frequently the input value changes.\n *\n * This is useful for deriving throttled values from signals that change frequently,\n * like scroll positions or mouse coordinates, where you want to limit how often downstream effects\n * or calculations occur.\n *\n * The function returns a throttled signal object containing:\n * - A Signal that provides the current throttled value\n * - The throttler instance with control methods\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * Available throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const scrollY = signal(0)\n * const throttledScrollY = injectThrottledValue(scrollY, {\n * wait: 100, // Update at most once per 100ms\n * })\n *\n * // Opt-in to reactive updates when pending state changes\n * const throttledScrollYWithState = injectThrottledValue(\n * scrollY,\n * { wait: 100 },\n * (state) => ({ isPending: state.isPending }),\n * )\n *\n * // Read the throttled signal value\n * effect(() => {\n * updateUI(throttledScrollY())\n * })\n *\n * // Access throttler state via the returned object's state() signal\n * console.log('Is pending:', throttledScrollYWithState.state().isPending)\n *\n * // Control the throttler\n * throttledScrollY.cancel() // Cancel any pending updates\n * ```\n */\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected>\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValue: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected>\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValueOrOptions: TValue | ThrottlerOptions<Setter<TValue>>,\n initialOptionsOrSelector?:\n | ThrottlerOptions<Setter<TValue>>\n | ((state: ThrottlerState<Setter<TValue>>) => TSelected),\n maybeSelector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected> {\n const hasSelector = typeof initialOptionsOrSelector === 'function'\n\n const hasInitialValue =\n (initialOptionsOrSelector !== undefined && !hasSelector) ||\n maybeSelector !== undefined\n\n const initialValue = hasInitialValue\n ? (initialValueOrOptions as TValue)\n : (undefined as unknown as TValue)\n const initialOptions = hasInitialValue\n ? (initialOptionsOrSelector as ThrottlerOptions<Setter<TValue>>)\n : (initialValueOrOptions as ThrottlerOptions<Setter<TValue>>)\n const selector = hasInitialValue\n ? maybeSelector\n : (initialOptionsOrSelector as\n | ((state: ThrottlerState<Setter<TValue>>) => TSelected)\n | undefined)\n\n const throttledValue = injectThrottledSignal(\n initialValue,\n initialOptions,\n selector,\n )\n\n effect(() => {\n const latest = value()\n throttledValue.set(latest)\n })\n\n return throttledValue\n}\n"],"mappings":";;;;AAqFA,SAAgB,qBACd,OACA,uBACA,0BAGA,eACoC;CAGpC,MAAM,kBACH,6BAA6B,UAAa,EAHzB,OAAO,6BAA6B,eAItD,kBAAkB;CAcpB,MAAM,iBAAiB,sBAZF,kBAChB,wBACA,QACkB,kBAClB,2BACA,uBACY,kBACb,gBACC,yBAQJ;
|
|
1
|
+
{"version":3,"file":"injectThrottledValue.js","names":[],"sources":["../../src/throttler/injectThrottledValue.ts"],"sourcesContent":["import { effect } from '@angular/core'\nimport { injectThrottledSignal } from './injectThrottledSignal'\nimport type { ThrottledSignal } from './injectThrottledSignal'\nimport type { Signal } from '@angular/core'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\n/**\n * An Angular function that creates a throttled value that updates at most once within a specified time window.\n * Unlike injectThrottledSignal, this function automatically tracks changes to the input signal\n * and updates the throttled value accordingly.\n *\n * The throttled value will update at most once within the specified wait time, regardless of\n * how frequently the input value changes.\n *\n * This is useful for deriving throttled values from signals that change frequently,\n * like scroll positions or mouse coordinates, where you want to limit how often downstream effects\n * or calculations occur.\n *\n * The function returns a throttled signal object containing:\n * - A Signal that provides the current throttled value\n * - The throttler instance with control methods\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * Available throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const scrollY = signal(0)\n * const throttledScrollY = injectThrottledValue(scrollY, {\n * wait: 100, // Update at most once per 100ms\n * })\n *\n * // Opt-in to reactive updates when pending state changes\n * const throttledScrollYWithState = injectThrottledValue(\n * scrollY,\n * { wait: 100 },\n * (state) => ({ isPending: state.isPending }),\n * )\n *\n * // Read the throttled signal value\n * effect(() => {\n * updateUI(throttledScrollY())\n * })\n *\n * // Access throttler state via the returned object's state() signal\n * console.log('Is pending:', throttledScrollYWithState.state().isPending)\n *\n * // Control the throttler\n * throttledScrollY.cancel() // Cancel any pending updates\n * ```\n */\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected>\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValue: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected>\nexport function injectThrottledValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValueOrOptions: TValue | ThrottlerOptions<Setter<TValue>>,\n initialOptionsOrSelector?:\n | ThrottlerOptions<Setter<TValue>>\n | ((state: ThrottlerState<Setter<TValue>>) => TSelected),\n maybeSelector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected> {\n const hasSelector = typeof initialOptionsOrSelector === 'function'\n\n const hasInitialValue =\n (initialOptionsOrSelector !== undefined && !hasSelector) ||\n maybeSelector !== undefined\n\n const initialValue = hasInitialValue\n ? (initialValueOrOptions as TValue)\n : (undefined as unknown as TValue)\n const initialOptions = hasInitialValue\n ? (initialOptionsOrSelector as ThrottlerOptions<Setter<TValue>>)\n : (initialValueOrOptions as ThrottlerOptions<Setter<TValue>>)\n const selector = hasInitialValue\n ? maybeSelector\n : (initialOptionsOrSelector as\n | ((state: ThrottlerState<Setter<TValue>>) => TSelected)\n | undefined)\n\n const throttledValue = injectThrottledSignal(\n initialValue,\n initialOptions,\n selector,\n )\n\n effect(() => {\n const latest = value()\n throttledValue.set(latest)\n })\n\n return throttledValue\n}\n"],"mappings":";;;;AAqFA,SAAgB,qBACd,OACA,uBACA,0BAGA,eACoC;CAGpC,MAAM,kBACH,6BAA6B,UAAa,EAHzB,OAAO,6BAA6B,eAItD,kBAAkB;CAcpB,MAAM,iBAAiB,sBAZF,kBAChB,wBACA,QACkB,kBAClB,2BACA,uBACY,kBACb,gBACC,yBAQJ;CAED,aAAa;EACX,MAAM,SAAS,OAAO;EACtB,eAAe,IAAI,OAAO;GAC1B;CAEF,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectThrottler.cjs","names":["injectPacerOptions","Throttler","DestroyRef"],"sources":["../../src/throttler/injectThrottler.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { Throttler } from '@tanstack/pacer/throttler'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\nexport interface AngularThrottlerOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends ThrottlerOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the throttler instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), cancel(), add logging, etc.\n */\n onUnmount?: (throttler: AngularThrottler<TFn, TSelected>) => void\n}\n\nexport interface AngularThrottler<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Throttler<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<ThrottlerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages a Throttler instance.\n *\n * This is a lower-level function that provides direct access to the Throttler's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides throttling functionality to limit how often a function can be called,\n * ensuring it executes at most once within a specified time window.\n *\n * The throttler will execute the function immediately (if leading is enabled) and then\n * prevent further executions until the wait period has elapsed.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * ## Cleanup on Destroy\n *\n * By default, the function cancels any pending execution when the component is destroyed.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```ts\n * const throttler = injectThrottler(fn, {\n * wait: 100,\n * onUnmount: (t) => t.flush()\n * });\n * ```\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const throttler = injectThrottler(\n * (scrollY: number) => updateScrollPosition(scrollY),\n * { wait: 100 }\n * );\n *\n * // Opt-in to track isPending changes (optimized for loading states)\n * const throttler = injectThrottler(\n * (scrollY: number) => updateScrollPosition(scrollY),\n * { wait: 100 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // In an event handler\n * window.addEventListener('scroll', () => {\n * throttler.maybeExecute(window.scrollY);\n * });\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = throttler.state();\n * ```\n */\nexport function injectThrottler<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: AngularThrottlerOptions<TFn, TSelected>,\n selector: (state: ThrottlerState<TFn>) => TSelected = () => ({}) as TSelected,\n): AngularThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().throttler,\n ...options,\n } as AngularThrottlerOptions<TFn, TSelected>\n\n const throttler = new Throttler<TFn>(fn, mergedOptions)\n const state = injectSelector(throttler.store, selector)\n\n const result = {\n ...throttler,\n state,\n } as AngularThrottler<TFn, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n throttler.cancel()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4GA,SAAgB,gBACd,IACA,SACA,kBAA6D,EAAE,GAC7B;CAClC,MAAM,gBAAgB;EACpB,GAAGA,0CAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,YAAY,IAAIC,oCAAe,IAAI,cAAc;CACvD,MAAM,oDAAuB,UAAU,OAAO,SAAS;CAEvD,MAAM,SAAS;EACb,GAAG;EACH;EACD;
|
|
1
|
+
{"version":3,"file":"injectThrottler.cjs","names":["injectPacerOptions","Throttler","DestroyRef"],"sources":["../../src/throttler/injectThrottler.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { Throttler } from '@tanstack/pacer/throttler'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\nexport interface AngularThrottlerOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends ThrottlerOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the throttler instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), cancel(), add logging, etc.\n */\n onUnmount?: (throttler: AngularThrottler<TFn, TSelected>) => void\n}\n\nexport interface AngularThrottler<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Throttler<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<ThrottlerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages a Throttler instance.\n *\n * This is a lower-level function that provides direct access to the Throttler's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides throttling functionality to limit how often a function can be called,\n * ensuring it executes at most once within a specified time window.\n *\n * The throttler will execute the function immediately (if leading is enabled) and then\n * prevent further executions until the wait period has elapsed.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * ## Cleanup on Destroy\n *\n * By default, the function cancels any pending execution when the component is destroyed.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```ts\n * const throttler = injectThrottler(fn, {\n * wait: 100,\n * onUnmount: (t) => t.flush()\n * });\n * ```\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const throttler = injectThrottler(\n * (scrollY: number) => updateScrollPosition(scrollY),\n * { wait: 100 }\n * );\n *\n * // Opt-in to track isPending changes (optimized for loading states)\n * const throttler = injectThrottler(\n * (scrollY: number) => updateScrollPosition(scrollY),\n * { wait: 100 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // In an event handler\n * window.addEventListener('scroll', () => {\n * throttler.maybeExecute(window.scrollY);\n * });\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = throttler.state();\n * ```\n */\nexport function injectThrottler<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: AngularThrottlerOptions<TFn, TSelected>,\n selector: (state: ThrottlerState<TFn>) => TSelected = () => ({}) as TSelected,\n): AngularThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().throttler,\n ...options,\n } as AngularThrottlerOptions<TFn, TSelected>\n\n const throttler = new Throttler<TFn>(fn, mergedOptions)\n const state = injectSelector(throttler.store, selector)\n\n const result = {\n ...throttler,\n state,\n } as AngularThrottler<TFn, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n throttler.cancel()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4GA,SAAgB,gBACd,IACA,SACA,kBAA6D,EAAE,GAC7B;CAClC,MAAM,gBAAgB;EACpB,GAAGA,0CAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,YAAY,IAAIC,oCAAe,IAAI,cAAc;CACvD,MAAM,oDAAuB,UAAU,OAAO,SAAS;CAEvD,MAAM,SAAS;EACb,GAAG;EACH;EACD;CAGD,0BAD0BC,0BAAY,EAAE,UAAU,MAAM,CAC9C,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,OAAO;OAE/B,UAAU,QAAQ;GAEpB;CAEF,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectThrottler.js","names":[],"sources":["../../src/throttler/injectThrottler.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { Throttler } from '@tanstack/pacer/throttler'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\nexport interface AngularThrottlerOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends ThrottlerOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the throttler instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), cancel(), add logging, etc.\n */\n onUnmount?: (throttler: AngularThrottler<TFn, TSelected>) => void\n}\n\nexport interface AngularThrottler<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Throttler<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<ThrottlerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages a Throttler instance.\n *\n * This is a lower-level function that provides direct access to the Throttler's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides throttling functionality to limit how often a function can be called,\n * ensuring it executes at most once within a specified time window.\n *\n * The throttler will execute the function immediately (if leading is enabled) and then\n * prevent further executions until the wait period has elapsed.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * ## Cleanup on Destroy\n *\n * By default, the function cancels any pending execution when the component is destroyed.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```ts\n * const throttler = injectThrottler(fn, {\n * wait: 100,\n * onUnmount: (t) => t.flush()\n * });\n * ```\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const throttler = injectThrottler(\n * (scrollY: number) => updateScrollPosition(scrollY),\n * { wait: 100 }\n * );\n *\n * // Opt-in to track isPending changes (optimized for loading states)\n * const throttler = injectThrottler(\n * (scrollY: number) => updateScrollPosition(scrollY),\n * { wait: 100 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // In an event handler\n * window.addEventListener('scroll', () => {\n * throttler.maybeExecute(window.scrollY);\n * });\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = throttler.state();\n * ```\n */\nexport function injectThrottler<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: AngularThrottlerOptions<TFn, TSelected>,\n selector: (state: ThrottlerState<TFn>) => TSelected = () => ({}) as TSelected,\n): AngularThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().throttler,\n ...options,\n } as AngularThrottlerOptions<TFn, TSelected>\n\n const throttler = new Throttler<TFn>(fn, mergedOptions)\n const state = injectSelector(throttler.store, selector)\n\n const result = {\n ...throttler,\n state,\n } as AngularThrottler<TFn, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n throttler.cancel()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4GA,SAAgB,gBACd,IACA,SACA,kBAA6D,EAAE,GAC7B;CAClC,MAAM,gBAAgB;EACpB,GAAG,oBAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,YAAY,IAAI,UAAe,IAAI,cAAc;CACvD,MAAM,QAAQ,eAAe,UAAU,OAAO,SAAS;CAEvD,MAAM,SAAS;EACb,GAAG;EACH;EACD;
|
|
1
|
+
{"version":3,"file":"injectThrottler.js","names":[],"sources":["../../src/throttler/injectThrottler.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { Throttler } from '@tanstack/pacer/throttler'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\nexport interface AngularThrottlerOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends ThrottlerOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the throttler instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), cancel(), add logging, etc.\n */\n onUnmount?: (throttler: AngularThrottler<TFn, TSelected>) => void\n}\n\nexport interface AngularThrottler<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Throttler<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<ThrottlerState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages a Throttler instance.\n *\n * This is a lower-level function that provides direct access to the Throttler's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides throttling functionality to limit how often a function can be called,\n * ensuring it executes at most once within a specified time window.\n *\n * The throttler will execute the function immediately (if leading is enabled) and then\n * prevent further executions until the wait period has elapsed.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * ## Cleanup on Destroy\n *\n * By default, the function cancels any pending execution when the component is destroyed.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```ts\n * const throttler = injectThrottler(fn, {\n * wait: 100,\n * onUnmount: (t) => t.flush()\n * });\n * ```\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const throttler = injectThrottler(\n * (scrollY: number) => updateScrollPosition(scrollY),\n * { wait: 100 }\n * );\n *\n * // Opt-in to track isPending changes (optimized for loading states)\n * const throttler = injectThrottler(\n * (scrollY: number) => updateScrollPosition(scrollY),\n * { wait: 100 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // In an event handler\n * window.addEventListener('scroll', () => {\n * throttler.maybeExecute(window.scrollY);\n * });\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = throttler.state();\n * ```\n */\nexport function injectThrottler<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: AngularThrottlerOptions<TFn, TSelected>,\n selector: (state: ThrottlerState<TFn>) => TSelected = () => ({}) as TSelected,\n): AngularThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().throttler,\n ...options,\n } as AngularThrottlerOptions<TFn, TSelected>\n\n const throttler = new Throttler<TFn>(fn, mergedOptions)\n const state = injectSelector(throttler.store, selector)\n\n const result = {\n ...throttler,\n state,\n } as AngularThrottler<TFn, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n throttler.cancel()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4GA,SAAgB,gBACd,IACA,SACA,kBAA6D,EAAE,GAC7B;CAClC,MAAM,gBAAgB;EACpB,GAAG,oBAAoB,CAAC;EACxB,GAAG;EACJ;CAED,MAAM,YAAY,IAAI,UAAe,IAAI,cAAc;CACvD,MAAM,QAAQ,eAAe,UAAU,OAAO,SAAS;CAEvD,MAAM,SAAS;EACb,GAAG;EACH;EACD;CAGD,AADmB,OAAO,YAAY,EAAE,UAAU,MAAM,CAC9C,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,OAAO;OAE/B,UAAU,QAAQ;GAEpB;CAEF,OAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/angular-pacer",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.1",
|
|
4
4
|
"description": "Utilities for debouncing and throttling functions in Angular.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -100,11 +100,11 @@
|
|
|
100
100
|
],
|
|
101
101
|
"dependencies": {
|
|
102
102
|
"@tanstack/angular-store": "^0.11.0",
|
|
103
|
-
"@tanstack/pacer": "0.21.
|
|
103
|
+
"@tanstack/pacer": "0.21.1"
|
|
104
104
|
},
|
|
105
105
|
"devDependencies": {
|
|
106
|
-
"@angular/core": "^21.2.
|
|
107
|
-
"@types/node": "^25.
|
|
106
|
+
"@angular/core": "^21.2.12",
|
|
107
|
+
"@types/node": "^25.7.0"
|
|
108
108
|
},
|
|
109
109
|
"peerDependencies": {
|
|
110
110
|
"@angular/core": ">=17.0.0"
|