undo static method
void
undo()
Reverts the most recent mutation (or batch of mutations) across all Undoable stores.
If a store's Undoable.restore override throws, that's surfaced as
a normal failed mutation (recorded in Orbit.changeLog /
Orbit.observe with label 'undo', same as any other throwing
mutate() call) and rethrown to the caller.
Implementation
static void undo() {
if (_undoStack.isEmpty) return;
final item = _undoStack.removeLast();
final isDisposed = item is OrbitUndoEntry
? item.store._disposed
: (item as OrbitUndoGroup).entries.every((e) => e.store._disposed);
if (isDisposed) return;
_isRestoring = true;
try {
Orbit.batch(() {
if (item is OrbitUndoEntry) {
if (!item.store._disposed) {
item.store.mutate(
() => (item.store as Undoable).restore(item.before),
label: 'undo',
);
}
} else if (item is OrbitUndoGroup) {
for (final entry in item.entries.reversed) {
if (!entry.store._disposed) {
entry.store.mutate(
() => (entry.store as Undoable).restore(entry.before),
label: 'undo',
);
}
}
}
}, label: item is OrbitUndoGroup ? (item.label ?? 'undo') : 'undo');
_redoStack.add(item);
} finally {
_isRestoring = false;
}
}