function injectThrottledSignal<TValue, TSelected>(
value,
initialOptions,
selector?): ThrottledSignal<TValue, TSelected>;
Defined in: throttler/injectThrottledSignal.ts:71
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:
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:
TValue
TSelected = { }
TValue
ThrottlerOptions<Setter<TValue>>
(state) => TSelected
ThrottledSignal<TValue, TSelected>
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)