Spaces:
Running
Running
File size: 623 Bytes
e6b949c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import { Action } from "./Action";
class UndoManager {
private static _instance: UndoManager;
private static _actionStack: Action[] = [];
public static get instance(): UndoManager {
if (!UndoManager._instance) {
UndoManager._instance = new UndoManager();
}
return UndoManager._instance;
}
public static do(action: Action) {
action.execute();
this._actionStack.push(action);
}
public static undo() {
const action = this._actionStack.pop();
if (action) {
action.undo();
}
}
}
export { UndoManager };
|