本页还没有译文
本页 26 段还没译成简体中文,下面显示的是英文原文。injectThrottledSignal
还没翻译译自英文(tanstack.com)本页 26 段都还没译
function injectThrottledSignal<TValue, TSelected>(
value,
initialOptions,
selector?): ThrottledSignal<TValue, TSelected>;Defined in: throttler/injectThrottledSignal.ts:63
An Angular function that creates a throttled state signal, combining Angular's signal with throttling functionality. This function provides both the current throttled value and methods to update it.
The state value is updated at most once within the specified wait time. This is useful for handling frequent state updates that should be rate-limited, like scroll positions or mouse movements.
The function returns a callable object:
throttled(): Get the current throttled valuethrottled.set(...): Set or update the throttled value (throttled via maybeExecute)throttled.throttler: The throttler instance with additional control methods and state signals
State Management and Selector
The function uses TanStack Store for reactive state management via the underlying throttler instance.
The selector parameter allows you to specify which throttler state changes will trigger signal updates,
optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
By default, there will be no reactive state subscriptions and you must opt-in to state tracking by providing a selector function. This prevents unnecessary updates and gives you full control over when your component tracks state changes.
Available throttler state properties:
executionCount: Number of function executions that have been completedisPending: Whether the throttler is waiting for the timeout to trigger executionlastArgs: The arguments from the most recent call to maybeExecutelastExecutionTime: Timestamp of the last executionnextExecutionTime: Timestamp of the next allowed executionstatus: Current execution status ('disabled' | 'idle' | 'pending')
Type Parameters
TValue
TValue
TSelected
TSelected = {
}
Parameters
value
TValue
initialOptions
AngularPacerOptions<ThrottlerOptions<Setter<TValue>>>
selector?
(state) => TSelected
Returns
ThrottledSignal<TValue, TSelected>
Example
const throttledScrollY = injectThrottledSignal(0, { wait: 100 })
// Get value
console.log(throttledScrollY())
// Set/update value (throttled)
throttledScrollY.set(window.scrollY)
// Access throttler
console.log(throttledScrollY.throttler.state().isPending)