fn
useManualRefHistory
v0.0.14testeddemoManually-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> | 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| Property | Type | Description |
|---|---|---|
source | Ref<Raw> | The tracked source ref. |
history | ComputedRef<Array<UseRefHistoryRecord<Serialized>>> | All records, most recent first (the current last followed by the undo stack). |
last | Ref<UseRefHistoryRecord<Serialized>> | The most recently committed record. |
undoStack | Ref<Array<UseRefHistoryRecord<Serialized>>> | Records available to undo to, most recent first. |
redoStack | Ref<Array<UseRefHistoryRecord<Serialized>>> | Records available to redo to, most recent first. |
canUndo | ComputedRef<boolean> | Whether there is at least one record to undo to. |
canRedo | ComputedRef<boolean> | Whether there is at least one record to redo to. |
commit | () => void | Capture the current source value as a new history record. |
clear | () => void | Drop every record from both stacks (keeps the current last). |
undo | () => void | Restore the previous record, moving the current one onto the redo stack. |
redo | () => void | Reapply the most recently undone record. |
reset | () => void | Restore the source to the value of the current last record. |