R
fn

useDebouncedRefHistory

v0.0.15testeddemo

Track the change history of a ref, debouncing commits so that rapid bursts of changes collapse into a single history record. A shorthand for {@link useRefHistory} pre-wired with a debounce {@link EventFilter}.

Examples

ts
const count = ref(0);
const { history, undo, redo } = useDebouncedRefHistory(count, { debounce: 200 });

// Rapid changes within 200ms collapse into a single commit
count.value = 1;
count.value = 2;
count.value = 3;
// after 200ms idle -> history has one new record with snapshot 3
ts
// Bound the maximum deferral under sustained input
const text = ref('');
const { history } = useDebouncedRefHistory(text, { debounce: 300, maxWait: 1000 });

Demo

Loading demo…

Signature

ts
export function useDebouncedRefHistory<Raw, Serialized = Raw>(
  source: Ref<Raw>,
  options: UseDebouncedRefHistoryOptions<Raw, Serialized> ={ ... }

Type Parameters

Raw
Serialized= Raw

Parameters

ParameterTypeDescription
sourceRef<Raw, Raw>The ref whose changes are tracked
options?UseDebouncedRefHistoryOptions<Raw, Serialized>Tracking options (`debounce`, `maxWait`, plus all `useRefHistory` options except `eventFilter`)

Returns

UseRefHistoryReturn<Raw, Serialized>History records plus `undo`/`redo`/`commit`/`reset`/`clear`/`pause`/`resume`/`batch`/`dispose`