LazyJsonUndoRedo ![Build Status](https://travis-ci.org/azazdeaz/LazyJsonUndoRedo.svg?branch=master)
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
edit json
edit maze
####Install
bower install --save LazyJsonUndoRedo
npm install --save lazy-json-undo-redo
####Unit tests
native
with polymer shim
Usage
Init
var o = {}, ljur = new LazyJsonUndoRedo(o);
o.a = 1;
ljur.undo();
console.log(o.a);
ljur.redo();
console.log(o.a);
Flagging
o = {}, ljur = new LazyJsonUndoRedo(o);
var endFlagId = ljur.startFlag();
o.c = {}
o.c.b = 1
o.c.e = 2
o.f = 4;
ljur.endFlag(endFlagId);
ljur.undo();
console.log(o);
ljur.redo();
console.log(o);
var changerFn = ljur.wrap(function () {});
changerFn();
Force save
o = {}, ljur = new LazyJsonUndoRedo(o);
o.g = {};
o.g.h = 1;
ljur.undo();
console.log(o);
o.i = {};
ljur.rec();
o.i.j = 2;
ljur.undo();
console.log(o);
Use whitelists
o = {};
ljur = new LazyJsonUndoRedo();
ljur.setWhiteList(o, ['a', 'b']);
ljur.observeTree(o);
o.a = 7;
o.c = 8;
ljur.undo();
console.log(o);
ljur.getWhitelist(o);
ljur.removeWhiteList(o);
Use blacklists
ljur.setBlacklist(object, blacklistedKeys);
ljur.removeBlacklist(object);
Use global black- and whitelist
ljur.addToGlobalWhitelist('a', 'b', 'x', 'd', 'e');
ljur.removeFromGlobalWhitelist('e', 'x');
ljur.addToGlobalBlacklist('a', 'b', 'x', 'd', 'e');
ljur.removeFromGlobalBlacklist('e', 'x');
Listen to more objects
ljur.observeTree(o2);
ljur.observeTree(o3);
Check support
LazyJsonUndoRedo.checkSupport();
ljur.usingShim;