function injectDebouncedSignal<TValue, TSelected>(
value,
initialOptions,
selector?): DebouncedSignal<TValue, TSelected>;
Defined in: debouncer/injectDebouncedSignal.ts:70
An Angular function that creates a debounced state signal, combining Angular's signal with debouncing functionality. This function provides both the current debounced value and methods to update it.
The state value is only updated after the specified wait time has elapsed since the last update attempt. If another update is attempted before the wait time expires, the timer resets and starts waiting again. This is useful for handling frequent state updates that should be throttled, like search input values or window resize dimensions.
The function returns a callable object:
The function uses TanStack Store for reactive state management via the underlying debouncer instance. The selector parameter allows you to specify which debouncer 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. Only when you provide a selector will the reactive system track the selected state values.
Available debouncer state properties:
TValue
TSelected = { }
TValue
DebouncerOptions<Setter<TValue>>
(state) => TSelected
DebouncedSignal<TValue, TSelected>
const debouncedQuery = injectDebouncedSignal('', { wait: 500 })
// Get value
console.log(debouncedQuery())
// Set/update value (debounced)
debouncedQuery.set('hello')
// Access debouncer
console.log(debouncedQuery.debouncer.state().isPending)