debounce

Delays emission until a specified duration has passed without new signals. Emits only the last signal after activity stops.

Signature

function debounce<T extends Signal>(ms: number): Operator<T, T>

Example

import { keyboard } from "cereb";
import { debounce } from "cereb/operators";
keyboard(window)
.pipe(debounce(300))
.on((signal) => {
// Fires 300ms after last keypress
search(signal.value.key);
});

Comparison with Throttle

OperatorBehaviorUse Case
debounceWait for silenceAfter activity stops
throttleEmit first, ignore restReal-time feedback
throttleLastCollect, emit lastFinal state matters

Use Cases

Search Input

// Wait for user to stop typing
keyboard(searchInput)
.pipe(debounce(300))
.on(() => performSearch());

Resize Handler

// Handle resize only after user stops resizing
domEvent(window, "resize")
.pipe(debounce(200))
.on(recalculateLayout);

Save Draft

// Auto-save 1 second after last edit
keyboard(editor)
.pipe(debounce(1000))
.on(saveDraft);