UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

33 lines (32 loc) 780 B
/** * A Memory-based undo manager. */ export class MemoryUndo { /** Undo stack. */ uStack = []; /** Redo stack. */ rStack = []; // /** ------------------------------------------------------ {@link UndoRedo} */ push(undo) { this.rStack = []; this.uStack.push(undo); } undo() { const undo = this.uStack.pop(); if (undo) { const redo = undo[1](undo[0]); this.rStack.push(redo); } } redo() { const redo = this.rStack.pop(); if (redo) { const undo = redo[1](redo[0]); this.uStack.push(undo); } } /** -------------------------------------------------- {@link UiLifeCycles} */ start() { return () => { }; } }