Undoo
Undo/redo manager

Installation
Node.js
npm install undoo --save
Browser
Local
<script src="node_modules/undoo/dist/undoo.min.js"></script>
CDN unpkg
<script src="https://unpkg.com/undoo/dist/undoo.min.js"></script>
Example
const Undoo = require('undoo');
const myHistory = new Undoo();
myHistory.save('one');
myHistory.save('two');
myHistory.save('three');
myHistory.save('four');
myHistory.undo((item)=>{
console.log(item);
});
myHistory.current();
myHistory.redo((item)=>{
console.log(item);
});
Use provider
const Undoo = require('undoo');
const myHistory = new Undoo({
provider: () => document.getElementById('myTextArea').value
});
myHistory.save();
API
Undoo
Kind: global class
new Undoo([opts])
Create instance
Param | Type | Default | Description |
---|
[opts] | Object | | configuration object
|
[opts.provider] | function |
| optional function called on save that returns new state for history
|
[opts.maxLength] | number | 20 | max length history
|
undoo.save([item]) ⇒ Undoo
Save history
Kind: instance method of Undoo
undoo.clear() ⇒ Undoo
Clear history
Kind: instance method of Undoo
undoo.undo(callback) ⇒ Undoo
Undo
Kind: instance method of Undoo
undoo.redo(callback) ⇒ Undoo
Redo
Kind: instance method of Undoo
undoo.current() ⇒ *
Get current item in history
Kind: instance method of Undoo
undoo.count() ⇒ number
Count history items
Kind: instance method of Undoo
undoo.onUpdate(callback)
Triggered when history is updated
Kind: instance method of Undoo
Changelog
You can view the changelog here
License
Undoo is open-sourced software licensed under the MIT license
Author
Fabio Ricali