A 'drop in' history handler with automatic undo/redo functionality for nested javascript objects, using ES6 Object.observe() or Polymer shim.
Best for small editor tools.
ES6 Object.observe() is only supported in Chrome 36+ and Nodejs 11.13+ yet, but LJUR is also usable with polymer(observe-js)
Demo
Install
bower install --save LazyJsonUndoRedo
npm install --save lazy-json-undo-redo
Unit tests
Usage
Init var o = {} ljur = o; oa = 1; ljur; console; // undefined ljur; console; // 1 Flagging o = {} ljur = o; //the changes between the start- end endFlag calls will be treated as one step //in the history var endFlagId = ljur; oc = {} ocb = 1 oce = 2 of = 4; ljur; ljur; console; //{} ljur; console; //{c: {b: 1, e: 2}, f: 4} //or wrap a function between flags: var changerFn = ljur; ;//all changes are reversible with one undo() call Force save //fast changes can be merged by the api (specially if you're using shim) o = {} ljur = o; og = {}; ogh = 1; ljur; console; //{} //to avoid this, you can force the history save with ljur.rec() oi = {}; ljur; oij = 2; ljur; console; // {i: {}} Use whitelists //if you want to specify witch properties should be listened on an object, // you can use whitelists: o = {}; ljur = ; ljur; ljur;//you have to set the whitelist before start to observe the object oa = 7; //will be undoable oc = 8; //won't be undoable, because 'c' is not on the whitelist ljur; console; // {c: 8} ljur; //['a', 'b'] ljur;//whitelists are removable Use blacklists //works the same as whitelists ljur; ljur; Use global black- and whitelist //you can use this two list for all of the objects added to ljur ljur; ljur; ljur; ljur; Listen to more objects ljur; ljur; Check support LazyJsonUndoRedo;//true is native Object.observe() or Polymer is present ljurusingShim;//true if it's usin Polymer shim