History-json
Implement undo/redo by Accumulating json
Installation
Via npm
$ npm install history-json --save
var HistoryJson= ;console; //function
Via bower
$ bower install history-json --save
Usage
var history= ; history;history;history; historycurrent;// { state: 'three' }history;// { state: 'two' }history;// { state: 'one' }history;// undefined historycurrent;// { state: 'one' }history;// { state: 'two' }history;// { state: 'three' }history;// undefined var exported= JSON;// save to file or localStorage var imported= exported;importedcurrent;// { state: 'three' }imported;// { state: 'two' }imported;// { state: 'one' }imported;// undefined
API
.add(history,options)
Return index
of added history
But, Doesn't add if duplicate of previous history.
var history= ;history;// 0history;// 1history;// 2 history;// 2
.undo(override=false)
Return history
via Change index
to previous
var history= ;history;history;history;history;// { state: 'two' }
.redo(override=false)
Return history
via Change index
to following
var history= ;history;history;history;history;// { state: 'two' }history;// { state: 'three' }
.current(override=false)
Return history
by current index
var history= ;history;history;history;historycurrent;// { state: 'three' }
.first(override=false)
Return history
via Change index to first
var history= ;history;history;history;history;// { state: 'one' }
.last(override=false)
Return history
via Change index to last
var history= ;history;history;history;history;// { state: 'three' }
.count()
Return number
of histories
var history= ;history;history;history;history// 3
.get(index)
Return history
by index
var history= ;history;history;history;history// { state: 'one' }
.destroy()
Delete all histories
var history= ;history;history;history;history;// 3 history;history;// 0
.canUndo()
Return true
if can undo.
var history= ;history;history;history;// true history;// { state: 'one' }history;// false
.canRedo()
Return true
if can redo.
var history= ;history;history;history;// false history;// { state: 'one' }history;// true
Override option
Override self properties by history if set true
: -> super @use 'Hammer'power:20 : @add tool:@tooloptions:@options tool= tooluse 'Drill'power:50consolelogtool# tool:'Drill',options:{power:50} toolundotrueconsolelogtool# tool:'Hammer',options:{power:20}