本页还没有译文
本页 44 段还没译成Deutsch,下面显示的是英文原文。UseDebouncer
还没翻译译自英文(tanstack.com)本页 44 段都还没译
Defined in: packages/ember-pacer/src/debouncer/useDebouncer.ts:87
Creates and retains the Debouncer for its Ember owner.
Waits for a quiet period, then executes the latest call. Each new call restarts the trailing timer. Configure leading and trailing edges for search, autosave, or resize handlers.
State and subscriptions
Pass a selector to track only the state consumed by the owner. The default selection is {}, so utility state changes do not update the owner unless it opts in. Selection uses shallow comparison. The raw store remains available for additional subscriptions. The selector is the second positional argument. Read utility.state from the template. The contextual utility.Subscribe helper selects state for a child template.
Available state fields:
canLeadingExecute: Whether the debouncer can execute on the leading edge of the timeoutexecutionCount: Number of function executions that have been completedisPending: Whether the debouncer is waiting for the timeout to trigger executionlastArgs: The arguments from the most recent call to maybeExecutemaybeExecuteCount: Number of times maybeExecute has been called (for reduction calculations)status: Current execution status - 'idle' when not active, 'pending' when waiting for timeout
Options and ownership
Tracked named arguments update options after rendering. createPacerScope supplies shared defaults through contextual helpers. Local named options override those defaults. Removing the helper invocation calls cancel(). onUnmount replaces default cleanup and receives the same adapter instance. A custom callback must perform all required cleanup. Use flush() where supported to finish pending work.
Example
import { on } from '@ember/modifier'
import { fn } from '@ember/helper'
import { useDebouncer } from '@tanstack/ember-pacer'
import type { DebouncerState } from '@tanstack/ember-pacer'
const select = (state: DebouncerState<(value: string) => void>) => ({ isPending: state.isPending })
<template>
{{#let (useDebouncer @process select wait=500) as |utility|}}
<button {{on "click" (fn utility.maybeExecute "item")}}>Schedule</button>
<span>{{utility.state.isPending}}</span>
{{/let}}
</template>Extends
default<{Args: {Named:EmberDebouncerOptions<TFn,TSelected>;Positional: [TFn] | [TFn, (state) =>TSelected]; };Return:EmberDebouncer<TFn,TSelected>; }>
Type Parameters
TFn
TFn extends AnyFunction
TSelected
TSelected = {
}
Constructors
Constructor
new UseDebouncer<TFn, TSelected>(owner?): UseDebouncer;Defined in: node_modules/.pnpm/ember-source@7.3.0_@glimmer+component@2.1.1_supports-color@7.2.0__supports-color@7.2.0/node_modules/ember-source/types/stable/@ember/object/index.d.ts:28
Parameters
owner?
Owner
Returns
UseDebouncer
Inherited from
Helper<{
Args: {
Positional:
[fn: TFn] | [fn: TFn, selector: (state: DebouncerState<TFn>) => TSelected]
Named: EmberDebouncerOptions<TFn, TSelected>
}
Return: EmberDebouncer<TFn, TSelected>
}>.constructorMethods
compute()
compute(positional, options): EmberDebouncer<TFn, TSelected>;Defined in: packages/ember-pacer/src/debouncer/useDebouncer.ts:103
Override this function when writing a class-based helper.
Parameters
positional
[TFn, (state) => TSelected]
The positional arguments to the helper
options
EmberDebouncerOptions<TFn, TSelected>
Returns
EmberDebouncer<TFn, TSelected>
Method
compute
Since
1.13.0
Overrides
Helper.compute