A straightforward undo/redo stack library.
You can install this package from the public npm repository:
npm install uredo
yarn add uredo
const CommandExecutor = require("uredo")
import CommandExecutor from "uredo
Class that implements an undo/redo stack. To use, pass an object to the do function that has at least two paramaterless functions, do() and undo(). If the object have a member variable includeWithPrevious set to true, the undo and redo stack will treat command as an incremental command that should be done/redone with the previous command.
Execute a command and place it on the undo stack. Also clears the redo stack()
command
object An object with two parameterless functions, do() and undo()
Pop the last item on the undo stack, call its undo function, and push it on the redo stack. Throws an error if there is no undo stack. If the last object was the includeWithPrevious flag set, it will undo the previous command until the undo stack is empty or a command is found without the includeWithPrevious or a command with that flag set to false.
Pop the last item off the redo stack, call its do() functions, and push it on the undo stack. Throws an error if there is no redo stack. If the following object(s) have the includeWithPrevious flag set, it will redo the following commands until the redo stack is empty or a command is found with the includeWithPrevious flag or a command with that flag set to false.
Check to see if the undo stack has at least one object.
Check to see if the redo stack has at least one object.
This project is licensed under the MIT License - see the LICENSE file for details
- PurpleBooth for the template of this page.