unadon
simple stack for undo/redo
Installaion
$ npm install unadon
Usage
var stack = ; stack { console;}; stack { console;}; stack { console;}; var i = 0; // stack and execute // undostack; // redostack;
Here is a little bit more practical example, fetching the new value from remote, keeping it into closure for undo/redo.
{ var old = datasheep; ;} ;
Methods
stack(redo, undo)
Register a pair of functions consists of function you would like to execute (which is the same as redo function) and it's opposite undo function.
stack.undo()
Put out and call the function at the top of the undo stack, then move it to the redo stack.
stack.redo()
Put out and call the function at the top of the redo stack, then move it to the undo stack.
stack.clear()
Clear all the stacked undo/redo functions. This function will be often called when something is saved.
stack.onStack
function called when a function is stacked (default: noop)
stack.onUndo
function called when undo function is called (default: noop)
stack.onRedo
function called when redo function is called (default: noop)
License
MIT