easy-undo
A simple JavaScript undo/redo interface; for easy management of 'state' histories in an application.
This is a modern JS rewrite of the awesome simple-undo project.
Installation
$ npm install --save easy-undo
Example
; // Let's assume there's an object whose history needs to be trackedconst sampleAppState = {}; // The maximum number of states to be trackedconst maxLength = 10; // We need a function which provides the required object in its "current" form// to the EasyUndo instance, whenever required, via a callback function:const provider = ; // Let's instantiate EasyUndoconst history = maxLength provider ; // The stringified version of the `sampleAppState` is saved, and managed by EasyUndo// when the `save` method is called on the EasyUndo instance (see `provider`)sampleAppStatesecret = "foo";history; sampleAppStatesecret = 42;history; // We need to specify the corresponding callback functions for the undo/redo// operations on the EasyUndo instance.const undoCb = { sampleAppState = JSON;};const redoCb = { sampleAppState = JSON;};// As you can see, these functions have access to the corresponding states. history;// sampleAppState -> { secret: "foo" } history;// sampleAppState -> { secret: 42 } // That's it! It's Easy! Have fun! :-)
License
MIT © Sai Kishore Komanduri