useDebouncedHistory
A hook that tracks Observable change history with debounce. A thin wrapper around useDataHistory with debounceFilter applied — it only records history after typing has stopped. Ideal for text inputs or search fields where you want to snapshot only when a burst of changes has "settled".
Settling editor
Commit after 600ms
Type quickly, pause, then inspect how only the settled value lands in history.
Snapshots: 1
Debounced timeline
Newest snapshot is pinned at the top.
#1
""
import { import useDebouncedHistory
useDebouncedHistory, import useObservable
useObservable } from "@usels/web";
function function Component(): JSX.Element
Component() { const const search$: any
search$ = import useObservable
useObservable(""); // Record a snapshot 500ms after the user stops typing const { const undo: any
undo, const redo: any
redo, const canUndo$: any
canUndo$ } = import useDebouncedHistory
useDebouncedHistory(const search$: any
search$, { debounce: number
debounce: 500 });
return <JSX.IntrinsicElements.input: DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>
input InputHTMLAttributes<HTMLInputElement>.value?: string | number | {} | undefined
value={const search$: any
search$.any
get()} InputHTMLAttributes<HTMLInputElement>.onChange?: ChangeEventHandler<HTMLInputElement, HTMLInputElement> | undefined
onChange={(e: ChangeEvent<HTMLInputElement, HTMLInputElement>
e) => const search$: any
search$.any
set(e: ChangeEvent<HTMLInputElement, HTMLInputElement>
e.ChangeEvent<HTMLInputElement, HTMLInputElement>.target: EventTarget & HTMLInputElement
target.any
value)} />;}import { createDebouncedHistory, observable } from "@usels/web";
function Component() { "use scope" const search$ = observable(""); const { undo, redo, canUndo$ } = createDebouncedHistory(search$, { debounce: 500 });
return <input value={search$.get()} onChange={(e) => search$.set(e.target.value)} />;}maxWait — force commit after maximum delay
Section titled “maxWait — force commit after maximum delay”Even if the user keeps typing, a snapshot is forced after maxWait ms.
import { useDebouncedHistory, useObservable } from "@usels/web";
function Component() { const text$ = useObservable(""); // Commit after 500ms idle, or every 2s at most even if still typing const { undo, redo } = useDebouncedHistory(text$, { debounce: 500, maxWait: 2000, });}import { createDebouncedHistory, observable } from "@usels/web";
function Component() { "use scope" const text$ = observable(""); const { undo, redo } = createDebouncedHistory(text$, { debounce: 500, maxWait: 2000, });}Combined with capacity
Section titled “Combined with capacity”import { useDebouncedHistory, useObservable } from "@usels/web";
function Component() { const note$ = useObservable(""); const { undo, redo } = useDebouncedHistory(note$, { debounce: 800, capacity: 30, });}import { createDebouncedHistory, observable } from "@usels/web";
function Component() { "use scope" const note$ = observable(""); const { undo, redo } = createDebouncedHistory(note$, { debounce: 800, capacity: 30, });}Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
source$ | Observable<Raw> | - The Observable to track. |
options | DebouncedHistoryOptions<Raw, Serialized> (optional) | - Debounce timing and history configuration. |
DebouncedHistoryOptions
Section titled “DebouncedHistoryOptions”Returns
Section titled “Returns”DataHistoryReturn<Raw, Serialized>
| Name | Type | Description |
|---|---|---|
isTracking$ | ReadonlyObservable<boolean> | Whether auto-tracking is currently active. |
pause | Fn | Stop auto-committing. |
resume | (commitCurrent?: boolean | undefined) => void | Restart auto-committing. If commitCurrent is true, immediately commit current value. |
transaction | (fn: (cancel: Fn) => void) => void | Group multiple mutations into a single history record. Call cancel() inside fn to abort. |
canUndo$ | ReadonlyObservable<boolean> | Whether undo is possible (undoStack is non-empty). |
canRedo$ | ReadonlyObservable<boolean> | Whether redo is possible (redoStack is non-empty). |
history$ | ReadonlyObservable<UseHistoryRecord<Serialized>[]> | Full history array, newest first: [current, previous, ...]. |
last$ | ReadonlyObservable<UseHistoryRecord<Serialized>> | The most recent (current) history record. |
commit | Fn | Record the current source value as a new history point. Clears redo stack. |
undo | Fn | Restore the previous committed value. |
redo | Fn | Re-apply the next value after an undo. |
clear | Fn | Wipe all history and create a fresh initial record from current source. |
reset | Fn | Restore source to the last committed value without modifying stacks. |