fn
useManualRefHistory
v0.0.15testeddemoManually-committed undo/redo history for a ref. Records snapshots only when `commit()` is called, with optional cloning, serialization, and a bounded capacity.
Examples
ts
const count = ref(0);
const { history, commit, undo, redo, canUndo } = useManualRefHistory(count);
count.value = 1;
commit();
undo(); // count.value === 0ts
const state = ref({ items: [] });
const { commit, undo } = useManualRefHistory(state, { clone: true, capacity: 10 });Demo
Loading demo…
Signature
ts
export function useManualRefHistory<Raw, Serialized = Raw>(
source: Ref<Raw>,
options: UseManualRefHistoryOptions<Raw, Serialized> ={ ... }Type Parameters
RawSerialized= RawParameters
| Parameter | Type | Description |
|---|---|---|
source | Ref<Raw, Raw> | The ref whose value changes are tracked |
options? | UseManualRefHistoryOptions<Raw, Serialized> | Options: `capacity`, `clone`, `dump`, `parse`, `setSource` |
Returns
UseManualRefHistoryReturn<Raw, Serialized>History state plus `commit`, `undo`, `redo`, `clear`, and `reset`