npm install undoo
npm install undoo --save
`
$3
#### Local
`html
`
#### CDN unpkg
`html
`
Example
`javascript
const Undoo = require('undoo');
const myHistory = new Undoo();
myHistory
.save('one')
.save('two')
.save('three')
.save('four');
myHistory.undo((item)=>{
console.log(item); //=> three
});
myHistory.current(); //=> three
myHistory.redo((item)=>{
console.log(item); //=> four
});
`
Use provider
`javascript
const Undoo = require('undoo');
const myHistory = new Undoo({
provider: () => document.getElementById('myTextArea').value
});
myHistory.save();
`
API
Undoo
Kind: global class * Undoo
* [new Undoo([opts])](#new_Undoo_new)
* _instance_
* .canUndo() ⇒ boolean
* .canRedo() ⇒ boolean
* .import(history) ⇒ Undoo
* .history() ⇒ Array
* [.save([item])](#Undoo+save) ⇒ Undoo
* [.suspendSave([state])](#Undoo+suspendSave) ⇒ Undoo
* .allowedSave() ⇒ boolean
* .clear() ⇒ Undoo
* [.undo([callback])](#Undoo+undo) ⇒ Undoo
* [.redo([callback])](#Undoo+redo) ⇒ Undoo
.current() ⇒ \
number\UndooUndooUndoofunctionfunctionfunctionfunctionfunction| 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 |
Kind: instance method of Undoo
Undoo Kind: instance method of Undoo
| Param | Type |
|---|---|
| history | Array |
Kind: instance method of Undoo
Kind: instance method of Undoo
| Param | Type |
|---|---|
| [item] | * |
Kind: instance method of Undoo
| Param | Type | Default |
|---|---|---|
| [state] | boolean | true |
Kind: instance method of Undoo
Kind: instance method of Undoo
Kind: instance method of Undoo
| Param | Type | Description |
|---|---|---|
| [callback] | undoCallback | callback function |
Kind: instance method of Undoo
| Param | Type | Description |
|---|---|---|
| [callback] | redoCallback | callback function |
Kind: instance method of Undoo
Kind: instance method of Undoo
Kind: instance method of Undoo
Kind: instance method of Undoo
| Param | Type | Description |
|---|---|---|
| callback | updateCallback | callback function |
Kind: instance method of Undoo
| Param | Type | Description |
|---|---|---|
| callback | maxLengthCallback | callback function |
Kind: instance method of Undoo
| Param | Type | Description |
|---|---|---|
| callback | beforeSaveCallback | callback function |
Example
`jsfalse
// If callback returns the save command will not be executed
myHistory.onBeforeSave(()=>false)
// You can overwrite item before save
myHistory.onBeforeSave((item)=>{
return item.toUpperCase();
})``
Kind: inner typedef of Undoo
| Param | Type | Description |
|---|---|---|
| item | * | current history item |
Kind: inner typedef of Undoo
| Param | Type | Description |
|---|---|---|
| item | * | current history item |
Kind: inner typedef of Undoo
| Param | Type | Description |
|---|---|---|
| item | * | current history item |
| action | string | action that has called update event. Can be: redo, undo, save, clear |
| history | Array | history array |
| istance | Undoo |
Kind: inner typedef of Undoo
| Param | Type | Description |
|---|---|---|
| item | * | current history item |
| history | Array | history array |
| istance | Undoo |
Kind: inner typedef of Undoo
| Param | Type | Description |
|---|---|---|
| item | * | current history item |
| istance | Undoo |