Creates either a writable signal whose values are debounced, or a signal who returns debounced values of another signal.

  • Creates a signal which emits the debounced changes from another signal. See the other overload if you want to create a writable signal that is debounced.

    Type Parameters

    • T

    Parameters

    • source: ReactiveSource<T>

      The signal like object whose values are debounced.

    • debounceTime: ValueSource<number>

      The time from last change before the value is emitted. Can be signal like.

    • Optionaloptions: DebounceSignalOptions & Pick<CreateSignalOptions<T>, "debugName">

      Options for the signal.

    Returns Signal<T>

    const original = signal('unchanged');
    const debounced = debounceSignal(original, 500);

    original.set('changed');
    console.log(original(), debounced()) // changed, unchanged

    setTimeout(() => console.log(original(), debounced()), 500) // changed, changed.
  • Creates a signal whose changes are debounced after a period of time from when the signal was updated.

    Type Parameters

    • T

    Parameters

    • initialValue: T

      The initial value like a regular signal.

    • debounceTime: ValueSource<number>

      The time from last change before the value is emitted. Can be signal like.

    • Optionaloptions: DebounceSignalOptions & CreateSignalOptions<T>

      Options for the signal. *

    Returns DebouncedSignal<T>

    const debounced = debounceSignal('unchanged', 500);

    debounced.set('changed');
    console.log(debounced()) // unchanged

    setTimeout(() => console.log(debounced()), 500) // changed