Download This Plugin Back To CSSScript.Com
A JavaScript library that adds advanced undo and redo functionalities to your applications.
// Create an instance of Oops
const undoManager = new Oops();
// Define a simple command
class AddNumberCommand {
constructor(number) {
this.number = number;
this.previousTotal = 0;
}
execute() {
this.previousTotal = total;
total += this.number;
}
undo() {
total = this.previousTotal;
}
}
// Use the undo manager
let total = 0;
undoManager.execute(new AddNumberCommand(5));
console.log(total); // Output: 5
undoManager.execute(new AddNumberCommand(3));
console.log(total); // Output: 8
undoManager.undo();
console.log(total); // Output: 5
undoManager.redo();
console.log(total); // Output: 8