From 6464247d9c304e88ab8282d400a523c23adaf72c Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Sun, 25 Mar 2018 05:19:49 -0700 Subject: [PATCH] refactor --- gun.js | 95 +++++++++++++++++++++---------------------- gun.min.js | 2 +- lib/erase.js | 2 +- lib/forget.js | 22 ++++++++++ lib/set.js | 2 +- lib/wsp/server.js | 4 +- package.json | 2 +- src/adapters/mesh.js | 2 +- src/back.js | 11 +++-- src/chain.js | 54 ++++++++++++------------ src/get.js | 17 ++++---- src/on.js | 14 +++---- src/put.js | 28 ++++++------- src/root.js | 6 +-- src/set.js | 6 +-- test/common.js | 63 ++++++++++++++-------------- test/gun.html | 1 - test/panic/b2s2s2b.js | 4 +- 18 files changed, 177 insertions(+), 158 deletions(-) create mode 100644 lib/forget.js diff --git a/gun.js b/gun.js index 2ede8b80..7fa154d8 100644 --- a/gun.js +++ b/gun.js @@ -677,7 +677,7 @@ ;(function(){ Gun.create = function(at){ - at.root = at.root || at.gun; + at.root = at.root || at; at.graph = at.graph || {}; at.on = at.on || Gun.on; at.ask = at.ask || Gun.ask; @@ -882,10 +882,10 @@ Gun.chain.back = function(n, opt){ var tmp; n = n || 1; if(-1 === n || Infinity === n){ - return this._.root; + return this._.root.gun; } else if(1 === n){ - return this._.back || this; + return (this._.back || this._).gun; } var gun = this, at = gun._; if(typeof n === 'string'){ @@ -900,19 +900,18 @@ return opt? gun : tmp; } else if((tmp = at.back)){ - return tmp.back(n, opt); + return tmp.gun.back(n, opt); } return; } if(n instanceof Function){ - var yes, tmp = {back: gun}; + var yes, tmp = {back: at}; while((tmp = tmp.back) - && (tmp = tmp._) && !(yes = n(tmp, opt))){} return yes; } if(Gun.num.is(n)){ - return at.back.back(n - 1); + return (at.back || at).gun.back(n - 1); } return this; } @@ -927,8 +926,8 @@ Gun.chain.chain = function(){ var at = this._, chain = new this.constructor(this), cat = chain._, root; cat.root = root = at.root; - cat.id = ++root._.once; - cat.back = this; + cat.id = ++root.once; + cat.back = this._; cat.on = Gun.on; cat.on('in', input, cat); // For 'in' if I add my own listeners to each then I MUST do it before in gets called. If I listen globally for all incoming data instead though, regardless of individual listeners, I can transform the data there and then as well. cat.on('out', output, cat); // However for output, there isn't really the global option. I must listen by adding my own listener individually BEFORE this one is ever called. @@ -936,7 +935,7 @@ } function output(msg){ - var put, get, at = this.as, back = at.back._, root = at.root._; + var put, get, at = this.as, back = at.back, root = at.root; if(!msg.gun){ msg.gun = at.gun } this.to.next(msg); if(get = msg.get){ @@ -974,7 +973,7 @@ if(get['.']){ if(at.get){ msg = {get: {'.': at.get}, gun: at.gun}; - (back.ask || (back.ask = {}))[at.get] = msg.gun; // TODO: PERFORMANCE? More elegant way? + (back.ask || (back.ask = {}))[at.get] = msg.gun._; // TODO: PERFORMANCE? More elegant way? return back.on('out', msg); } msg = {get: {}, gun: at.gun}; @@ -984,7 +983,7 @@ if(at.get){ msg.gun = at.gun; get['.'] = at.get; - (back.ask || (back.ask = {}))[at.get] = msg.gun; // TODO: PERFORMANCE? More elegant way? + (back.ask || (back.ask = {}))[at.get] = msg.gun._; // TODO: PERFORMANCE? More elegant way? return back.on('out', msg); } } @@ -1042,7 +1041,7 @@ cat.put = at.put; }; if((rel = Gun.node.soul(change)) && at.has){ - at.put = (cat.root.get(rel)._).put; + at.put = (cat.root.gun.get(rel)._).put; } ev.to.next(msg); echo(cat, msg, ev); @@ -1057,7 +1056,7 @@ function relate(at, msg, from, rel){ if(!rel || node_ === at.get){ return } - var tmp = (at.root.get(rel)._); + var tmp = (at.root.gun.get(rel)._); if(at.has){ from = tmp; } else @@ -1070,8 +1069,8 @@ not(at, msg); } tmp = (at.map || (at.map = {}))[from.id] = at.map[from.id] || {at: from}; - var now = at.root._.now; - //now = now || at.root._.stop; + var now = at.root.now; + //now = now || at.root.stop; if(rel === tmp.rel){ // NOW is a hack to get synchronous replies to correctly call. // and STOP is a hack to get async behavior to correctly call. @@ -1079,7 +1078,7 @@ // but for now, this works for current tests. :/ if(!now){ return; - /*var stop = at.root._.stop; + /*var stop = at.root.stop; if(!stop){ return } if(stop[at.id] === rel){ return } stop[at.id] = rel;*/ @@ -1105,7 +1104,7 @@ if(!(at = next[key])){ return; } - //if(data && data[_soul] && (tmp = Gun.val.rel.is(data)) && (tmp = (cat.root.get(tmp)._)) && obj_has(tmp, 'put')){ + //if(data && data[_soul] && (tmp = Gun.val.rel.is(data)) && (tmp = (cat.root.gun.get(tmp)._)) && obj_has(tmp, 'put')){ // data = tmp.put; //} if(at.has){ @@ -1125,7 +1124,7 @@ } function not(at, msg){ if(!(at.has || at.soul)){ return } - var tmp = at.map, root = at.root._; + var tmp = at.map, root = at.root; at.map = null; if(!root.now || !root.now[at.id]){ if((!msg['@']) && null === tmp){ return } @@ -1148,7 +1147,7 @@ }); } function ask(at, soul){ - var tmp = (at.root.get(soul)._); + var tmp = (at.root.gun.get(soul)._); if(at.ack){ tmp.on('out', {get: {'#': soul}}); if(!at.ask){ return } // TODO: PERFORMANCE? More elegant way? @@ -1181,9 +1180,9 @@ } //if(/*!msg.gun &&*/ !get['.'] && get['#']){ at.ack = (at.ack + 1) || 1 } //msg = obj_to(msg); - msg.gun = at.root; + msg.gun = at.root.gun; //Gun.on('put', at); - Gun.on.put(msg, at.root); + Gun.on.put(msg, at.root.gun); } var empty = {}, u; var obj = Gun.obj, obj_has = obj.has, obj_put = obj.put, obj_del = obj.del, obj_to = obj.to, obj_map = obj.map; @@ -1205,7 +1204,7 @@ } else if(key instanceof Function){ gun = this; - var at = gun._, root = at.root._, tmp = root.now, ev; + var at = gun._, root = at.root, tmp = root.now, ev; as = cb || {}; as.use = key; as.out = as.out || {}; @@ -1235,7 +1234,7 @@ var cat = back._, next = cat.next, gun = back.chain(), at = gun._; if(!next){ next = cat.next = {} } next[at.get = key] = at; - if(back === cat.root){ + if(back === cat.root.gun){ at.soul = key; } else if(cat.soul || cat.has){ @@ -1247,7 +1246,7 @@ return at; } function use(msg){ - var ev = this, as = ev.as, gun = msg.gun, at = gun._, root = at.root._, data = msg.put, tmp; + var ev = this, as = ev.as, gun = msg.gun, at = gun._, root = at.root, data = msg.put, tmp; if((tmp = root.now) && ev !== tmp[as.now]){ return ev.to.next(msg); } @@ -1255,7 +1254,7 @@ data = at.put; } if((tmp = data) && tmp[rel._] && (tmp = rel.is(tmp))){ - tmp = (at.root.get(tmp)._); + tmp = (at.root.gun.get(tmp)._); if(u !== tmp.put){ msg = obj_to(msg, {put: tmp.put}); } @@ -1275,7 +1274,7 @@ // #soul.has=value>state // ~who#where.where=what>when@was // TODO: BUG! Put probably cannot handle plural chains! - var gun = this, at = (gun._), root = at.root, tmp; + var gun = this, at = (gun._), root = at.root.gun, tmp; as = as || {}; as.data = data; as.gun = as.gun || gun; @@ -1308,14 +1307,14 @@ } if(Gun.is(data)){ data.get('_').get(function(at, ev, tmp){ ev.off(); - if(!(tmp = at.gun) || !(tmp = tmp._.back) || !tmp._.soul){ + if(!(tmp = at.gun) || !(tmp = tmp._.back) || !tmp.soul){ return Gun.log("The reference you are saving is a", typeof at.put, '"'+ as.put +'", not a node (object)!'); } - gun.put(Gun.val.rel.ify(tmp._.soul), cb, as); + gun.put(Gun.val.rel.ify(tmp.soul), cb, as); }); return gun; } - as.ref = as.ref || (root === (tmp = at.back))? gun : tmp; + as.ref = as.ref || (root._ === (tmp = at.back))? gun : tmp.gun; if(as.ref._.soul && Gun.val.is(as.data) && at.get){ as.data = obj_put({}, at.get, as.data); as.ref.put(as.data, as.soul, as); @@ -1372,16 +1371,16 @@ // and STOP is a hack to get async behavior to correctly call. // neither of these are ideal, need to be fixed without hacks, // but for now, this works for current tests. :/ - var tmp = cat.root._.now; obj.del(cat.root._, 'now'); cat.root._.PUT = true; - var tmp2 = cat.root._.stop; + var tmp = cat.root.now; obj.del(cat.root, 'now'); cat.root.PUT = true; + var tmp2 = cat.root.stop; (as.ref._).now = true; (as.ref._).on('out', { gun: as.ref, put: as.out = as.env.graph, opt: as.opt, '#': ask }); obj.del((as.ref._), 'now'); - obj.del((cat.root._), 'PUT'); - cat.root._.now = tmp; - cat.root._.stop = tmp2; + obj.del((cat.root), 'PUT'); + cat.root.now = tmp; + cat.root.stop = tmp2; }, as); if(as.res){ as.res() } } function no(v,k){ if(v){ return true } } @@ -1422,7 +1421,7 @@ var at = msg.gun._, at_ = at; var _id = (msg.put||empty)['#']; ev.off(); - at = (msg.gun._.back._); // go up 1! + at = (msg.gun._.back); // go up 1! var id = id || Gun.node.soul(cat.obj) || Gun.node.soul(at.put) || Gun.val.rel.is(at.put) || _id || at_._id || (as.gun.back('opt.uuid') || Gun.text.random)(); // TODO: BUG!? Do we really want the soul of the object given to us? Could that be dangerous? if(!id){ // polyfill async uuid for SEA at.gun.back('opt.uuid')(function(err, id){ // TODO: improve perf without anonymous callback @@ -1448,7 +1447,7 @@ console.log("Please report this as an issue! Put.any.err"); return; } - var cat = (at.gun._.back._), data = cat.put, opt = as.opt||{}, root, tmp; + var cat = (at.gun._.back), data = cat.put, opt = as.opt||{}, root, tmp; if((tmp = as.ref) && tmp._.now){ return } ev.off(); if(as.ref !== as.gun){ @@ -1469,19 +1468,19 @@ }); } tmp = tmp || cat.get; - cat = (cat.root.get(tmp)._); + cat = (cat.root.gun.get(tmp)._); as.not = as.soul = tmp; data = as.data; } if(!as.not && !(as.soul = Gun.node.soul(data))){ if(as.path && obj_is(as.data)){ // Apparently necessary - as.soul = (opt.uuid || cat.root._.opt.uuid || Gun.text.random)(); + as.soul = (opt.uuid || cat.root.opt.uuid || Gun.text.random)(); } else { //as.data = obj_put({}, as.gun._.get, as.data); if(node_ == at.get){ as.soul = (at.put||empty)['#'] || at._id; } - as.soul = as.soul || at.soul || cat.soul || (opt.uuid || cat.root._.opt.uuid || Gun.text.random)(); + as.soul = as.soul || at.soul || cat.soul || (opt.uuid || cat.root.opt.uuid || Gun.text.random)(); } if(!as.soul){ // polyfill async uuid for SEA as.ref.back('opt.uuid')(function(err, soul){ // TODO: improve perf without anonymous callback @@ -1539,7 +1538,7 @@ return; } if(data && data[rel._] && (tmp = rel.is(data))){ - tmp = (cat.root.get(tmp)._); + tmp = (cat.root.gun.get(tmp)._); if(u === tmp.put){ return; } @@ -1596,7 +1595,7 @@ //if(coat.soul && !(0 < coat.ack)){ return } if(tmp = Gun.node.soul(data) || rel.is(data)){ //if(data && data[rel._] && (tmp = rel.is(data))){ - tmp = (cat.root.get(tmp)._); + tmp = (cat.root.gun.get(tmp)._); if(u === tmp.put){//} || !(0 < tmp.ack)){ return; } @@ -1622,7 +1621,7 @@ Gun.chain.off = function(){ // make off more aggressive. Warning, it might backfire! var gun = this, at = gun._, tmp; - var back = at.back || {}, cat = back._; + var cat = at.back; if(!cat){ return } if(tmp = cat.next){ if(tmp[at.get]){ @@ -1638,12 +1637,12 @@ obj_del(tmp, at.get); } if(tmp = at.soul){ - obj_del(cat.root._.graph, tmp); + obj_del(cat.root.graph, tmp); } if(tmp = at.map){ obj_map(tmp, function(at){ if(at.rel){ - cat.root.get(at.rel).off(); + cat.root.gun.get(at.rel).off(); } }); } @@ -1707,9 +1706,9 @@ opt = opt || {}; opt.item = opt.item || item; if(soul = Gun.node.soul(item)){ return gun.set(gun.back(-1).get(soul), cb, opt) } if(!Gun.is(item)){ - var id = gun._.root._.opt.uuid(); + var id = gun._.root.opt.uuid(); if(id && Gun.obj.is(item)){ - return gun.set(gun._.root.put(item, id), cb, opt); + return gun.set(gun._.root.gun.put(item, id), cb, opt); } return gun.get(id || (Gun.state.lex() + Gun.text.random(12))).put(item, cb, opt); } @@ -1717,7 +1716,7 @@ if(!at.gun || !at.gun._.back){ return } ev.off(); var soul = (at.put||{})['#']; - at = (at.gun._.back._); + at = (at.gun._.back); var put = {}, node = at.put; soul = at.soul || Gun.node.soul(node) || soul; if(!soul){ return cb.call(gun, {err: Gun.log('Only a node can be linked! Not "' + node + '"!')}) } diff --git a/gun.min.js b/gun.min.js index 15d72276..f1ef9d96 100644 --- a/gun.min.js +++ b/gun.min.js @@ -1 +1 @@ -!function(){function t(n){function o(t){return t.split("/").slice(-1).toString().replace(".js","")}return n.slice?t[o(n)]:function(e,i){n(e={exports:{}}),t[o(i)]=e.exports}}var n;"undefined"!=typeof window&&(n=window),"undefined"!=typeof global&&(n=global),n=n||{};var o=n.console||{log:function(){}};if("undefined"!=typeof module)var e=module;t(function(t){var n={};n.fns=n.fn={is:function(t){return!!t&&"function"==typeof t}},n.bi={is:function(t){return t instanceof Boolean||"boolean"==typeof t}},n.num={is:function(t){return!e(t)&&(t-parseFloat(t)+1>=0||1/0===t||-(1/0)===t)}},n.text={is:function(t){return"string"==typeof t}},n.text.ify=function(t){return n.text.is(t)?t:"undefined"!=typeof JSON?JSON.stringify(t):t&&t.toString?t.toString():t},n.text.random=function(t,n){var o="";for(t=t||24,n=n||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";t>0;)o+=n.charAt(Math.floor(Math.random()*n.length)),t--;return o},n.text.match=function(t,o){function e(t,n){for(var o,e=-1,i=0;o=n[i++];)if(!~(e=t.indexOf(o,e+1)))return!1;return!0}var i=!1;if(t=t||"",o=n.text.is(o)?{"=":o}:o||{},n.obj.has(o,"~")&&(t=t.toLowerCase(),o["="]=(o["="]||o["~"]).toLowerCase()),n.obj.has(o,"="))return t===o["="];if(n.obj.has(o,"*")){if(t.slice(0,o["*"].length)!==o["*"])return!1;i=!0,t=t.slice(o["*"].length)}if(n.obj.has(o,"!")){if(t.slice(-o["!"].length)!==o["!"])return!1;i=!0}if(n.obj.has(o,"+")&&n.list.map(n.list.is(o["+"])?o["+"]:[o["+"]],function(n){return t.indexOf(n)>=0?void(i=!0):!0}))return!1;if(n.obj.has(o,"-")&&n.list.map(n.list.is(o["-"])?o["-"]:[o["-"]],function(n){return t.indexOf(n)<0?void(i=!0):!0}))return!1;if(n.obj.has(o,">")){if(!(t>o[">"]))return!1;i=!0}if(n.obj.has(o,"<")){if(!(tn?-1:n>o?1:0):0}},n.list.map=function(t,n,o){return a(t,n,o)},n.list.index=1,n.obj={is:function(t){return t?t instanceof Object&&t.constructor===Object||"Object"===Object.prototype.toString.call(t).match(/^\[object (\w+)\]$/)[1]:!1}},n.obj.put=function(t,n,o){return(t||{})[n]=o,t},n.obj.has=function(t,n){return t&&Object.prototype.hasOwnProperty.call(t,n)},n.obj.del=function(t,n){return t?(t[n]=null,delete t[n],t):void 0},n.obj.as=function(t,n,o,e){return t[n]=t[n]||(e===o?{}:o)},n.obj.ify=function(t){if(r(t))return t;try{t=JSON.parse(t)}catch(n){t={}}return t},function(){function t(t,n){u(this,n)&&o!==this[n]||(this[n]=t)}var o;n.obj.to=function(n,o){return o=o||{},a(n,t,o),o}}(),n.obj.copy=function(t){return t?JSON.parse(JSON.stringify(t)):t},function(){function t(t,n){var o=this.n;if(!o||!(n===o||r(o)&&u(o,n)))return n?!0:void 0}n.obj.empty=function(n,o){return n&&a(n,t,{n:o})?!1:!0}}(),function(){function t(n,o){return 2===arguments.length?(t.r=t.r||{},void(t.r[n]=o)):(t.r=t.r||[],void t.r.push(n))}var i=Object.keys;n.obj.map=function(a,s,f){var c,l,p,h,d,g=0,v=o(s);if(t.r=null,i&&r(a)&&(h=i(a),d=!0),e(a)||h)for(l=(h||a).length;l>g;g++){var b=g+n.list.index;if(v){if(p=d?s.call(f||this,a[h[g]],h[g],t):s.call(f||this,a[g],b,t),p!==c)return p}else if(s===a[d?h[g]:g])return h?h[g]:b}else for(g in a)if(v){if(u(a,g)&&(p=f?s.call(f,a[g],g,t):s(a[g],g,t),p!==c))return p}else if(s===a[g])return g;return v?t.r:n.list.index?0:-1}}(),n.time={},n.time.is=function(t){return t?t instanceof Date:+(new Date).getTime()};var o=n.fn.is,e=n.list.is,i=n.obj,r=i.is,u=i.has,a=i.map;t.exports=n})(t,"./type"),t(function(t){t.exports=function n(t,o,e){if(!t)return{to:n};var t=(this.tag||(this.tag={}))[t]||(this.tag[t]={tag:t,to:n._={next:function(t){var n;(n=this.to)&&n.next(t)}}});if(o instanceof Function){var i={off:n.off||(n.off=function(){return this.next===n._.next?!0:(this===this.the.last&&(this.the.last=this.back),this.to.back=this.back,this.next=n._.next,this.back.to=this.to,void(this.the.last===this.the&&delete this.on.tag[this.the.tag]))}),to:n._,next:o,the:t,on:this,as:e};return(i.back=t.last||t).to=i,t.last=i}return(t=t.to).next(o),t}})(t,"./onto"),t(function(t){function n(t,n,e,i,r){if(n>t)return{defer:!0};if(e>n)return{historical:!0};if(n>e)return{converge:!0,incoming:!0};if(n===e){if(i=o(i)||"",r=o(r)||"",i===r)return{state:!0};if(r>i)return{converge:!0,current:!0};if(i>r)return{converge:!0,incoming:!0}}return{err:"Invalid CRDT Data: "+i+" to "+r+" at "+n+" to "+e+"!"}}if("undefined"==typeof JSON)throw new Error("JSON is not included in this browser. Please load it first: ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js");var o=JSON.stringify;t.exports=n})(t,"./HAM"),t(function(n){var o=t("./type"),e={};e.is=function(t){return t===i?!1:null===t?!0:t===1/0?!1:s(t)||u(t)||a(t)?!0:e.rel.is(t)||!1},e.rel={_:"#"},function(){function t(t,n){var o=this;return o.id?o.id=!1:n==r&&s(t)?void(o.id=t):o.id=!1}e.rel.is=function(n){if(n&&n[r]&&!n._&&c(n)){var o={};if(p(n,t,o),o.id)return o.id}return!1}}(),e.rel.ify=function(t){return l({},r,t)},o.obj.has._=".";var i,r=e.rel._,u=o.bi.is,a=o.num.is,s=o.text.is,f=o.obj,c=f.is,l=f.put,p=f.map;n.exports=e})(t,"./val"),t(function(n){var o=t("./type"),e=t("./val"),i={_:"_"};i.soul=function(t,n){return t&&t._&&t._[n||p]},i.soul.ify=function(t,n){return n="string"==typeof n?{soul:n}:n||{},t=t||{},t._=t._||{},t._[p]=n.soul||t._[p]||l(),t},i.soul._=e.rel._,function(){function t(t,n){return n!==i._?e.is(t)?void(this.cb&&this.cb.call(this.as,t,n,this.n,this.s)):!0:void 0}i.is=function(n,o,e){var r;return a(n)&&(r=i.soul(n))?!f(n,t,{as:e,cb:o,s:r,n:n}):!1}}(),function(){function t(t,n){var o,i,r=this.o;return r.map?(o=r.map.call(this.as,t,""+n,r.node),void(i===o?s(r.node,n):r.node&&(r.node[n]=o))):void(e.is(t)&&(r.node[n]=t))}i.ify=function(n,o,e){return o?"string"==typeof o?o={soul:o}:o instanceof Function&&(o={map:o}):o={},o.map&&(o.node=o.map.call(e,n,r,o.node||{})),(o.node=i.soul.ify(o.node||{},o))&&f(n,t,{o:o,as:e}),o.node}}();var r,u=o.obj,a=u.is,s=u.del,f=u.map,c=o.text,l=c.random,p=i.soul._;n.exports=i})(t,"./node"),t(function(n){function o(){var t;return t=f?c+f.now():r(),t>u?(a=0,u=t+o.drift):u=t+(a+=1)/s+o.drift}var e=t("./type"),i=t("./node"),r=e.time.is,u=-(1/0),a=0,s=1e3,f="undefined"!=typeof performance?performance.timing&&performance:!1,c=f&&f.timing&&f.timing.navigationStart||(f=!1);o._=">",o.drift=0,o.is=function(t,n,e){var i=n&&t&&t[x]&&t[x][o._]||e;if(i)return m(i=i[n])?i:-(1/0)},o.lex=function(){return o().toString(36).replace(".","")},o.ify=function(t,n,e,r,u){if(!t||!t[x]){if(!u)return;t=i.soul.ify(t,u)}var a=h(t[x],o._);return l!==n&&n!==x&&(m(e)&&(a[n]=e),l!==r&&(t[n]=r)),t},o.to=function(t,n,e){var r=t[n];return g(r)&&(r=b(r)),o.ify(e,n,o.is(t,n),r,i.soul(t))},function(){function t(t,n){x!==n&&o.ify(this.o,n,this.s)}o.map=function(n,e,i){var r,u=g(u=n||e)?u:null;return n=k(n=n||e)?n:null,u&&!n?(e=m(e)?e:o(),u[x]=u[x]||{},v(u,t,{o:u,s:e}),u):(i=i||g(e)?e:r,e=m(e)?e:o(),function(o,u,a,s){return n?(n.call(i||this||{},o,u,a,s),void(d(a,u)&&r===a[u]||t.call({o:a,s:e},o,u))):(t.call({o:a,s:e},o,u),o)})}}();var l,p=e.obj,h=p.as,d=p.has,g=p.is,v=p.map,b=p.copy,_=e.num,m=_.is,y=e.fn,k=y.is,x=i._;n.exports=o})(t,"./state"),t(function(n){var o=t("./type"),e=t("./val"),i=t("./node"),r={};!function(){function t(t,o){return t&&o===i.soul(t)&&i.is(t,this.fn,this.as)?void(this.cb&&(n.n=t,n.as=this.as,this.cb.call(n.as,t,o,n))):!0}function n(t){t&&i.is(n.n,t,n.as)}r.is=function(n,o,e,i){return n&&s(n)&&!l(n)?!h(n,t,{cb:o,fn:e,as:i}):!1}}(),function(){function t(t,o){var r;return(r=p(t,o))?r:(o.env=t,o.soul=a,i.ify(o.obj,n,o)&&(t.graph[e.rel.is(o.rel)]=o.node),o)}function n(n,o,r){var a,s,p=this,h=p.env;if(i._===o&&c(n,e.rel._))return r._;if(a=l(n,o,r,p,h)){if(o||(p.node=p.node||r||{},c(n,i._)&&(p.node._=d(n._)),p.node=i.soul.ify(p.node,e.rel.is(p.rel)),p.rel=p.rel||e.rel.ify(i.soul(p.node))),(s=h.map)&&(s.call(h.as||{},n,o,r,p),c(r,o))){if(n=r[o],u===n)return void f(r,o);if(!(a=l(n,o,r,p,h)))return}if(!o)return p.node;if(!0===a)return n;if(s=t(h,{obj:n,path:p.path.concat(o)}),s.node)return s.rel}}function a(t){var n=this,o=e.rel.is(n.rel),r=n.env.graph;n.rel=n.rel||e.rel.ify(t),n.rel[e.rel._]=t,n.node&&n.node[i._]&&(n.node[i._][e.rel._]=t),c(r,o)&&(r[t]=r[o],f(r,o))}function l(t,n,i,r,u){var a;return e.is(t)?!0:s(t)?1:(a=u.invalid)?(t=a.call(u.as||{},t,n,i),l(t,n,i,r,u)):(u.err="Invalid value at '"+r.path.concat(n).join(".")+"'!",void(o.list.is(t)&&(u.err+=" Use `.set(item)` instead of an Array.")))}function p(t,n){for(var o,e=t.seen,i=e.length;i--;)if(o=e[i],n.obj===o.obj)return o;e.push(n)}r.ify=function(n,o,i){var r={path:[],obj:n};return o?"string"==typeof o?o={soul:o}:o instanceof Function&&(o.map=o):o={},o.soul&&(r.rel=e.rel.ify(o.soul)),o.graph=o.graph||{},o.seen=o.seen||[],o.as=o.as||i,t(o,r),o.root=r.node,o.graph}}(),r.node=function(t){var n=i.soul(t);if(n)return p({},n,t)},function(){function t(t,n){var o,u;if(i._===n){if(l(t,e.rel._))return;return void(this.obj[n]=d(t))}return(o=e.rel.is(t))?(u=this.opt.seen[o])?void(this.obj[n]=u):void(this.obj[n]=this.opt.seen[o]=r.to(this.graph,o,this.opt)):void(this.obj[n]=t)}r.to=function(n,o,e){if(n){var i={};return e=e||{seen:{}},h(n[o],t,{obj:i,graph:n,opt:e}),i}}}();var u,a=(o.fn.is,o.obj),s=a.is,f=a.del,c=a.has,l=a.empty,p=a.put,h=a.map,d=a.copy;n.exports=r})(t,"./graph"),t(function(n){t("./onto"),n.exports=function(t,n){if(this.on){if(!(t instanceof Function)){if(!t||!n)return;var o=t["#"]||t,e=(this.tag||empty)[o];if(!e)return;return e=this.on(o,n),clearTimeout(e.err),!0}var o=n&&n["#"]||Math.random().toString(36).slice(2);if(!t)return o;var i=this.on(o,t,n);return i.err=i.err||setTimeout(function(){i.next({err:"Error: No ACK received yet."}),i.off()},(this.opt||{}).lack||9e3),o}}})(t,"./ask"),t(function(n){function o(t){var n={s:{}};return t=t||{max:1e3,age:9e3},n.check=function(t){var o;return(o=n.s[t])?o.pass?o.pass=!1:n.track(t):!1},n.track=function(o,r){var u=n.s[o]||(n.s[o]={});return u.was=i(),r&&(u.pass=!0),n.to||(n.to=setTimeout(function(){var o=i();e.obj.map(n.s,function(i,r){t.age>o-i.was||e.obj.del(n.s,r)}),n.to=null},t.age+9)),u},n}var e=t("./type"),i=e.time.is;n.exports=o})(t,"./dup"),t(function(n){function i(t){return t instanceof i?(this._={gun:this}).gun:this instanceof i?i.create(this._={gun:this,opt:t}):new i(t)}i.is=function(t){return t instanceof i},i.version=.9,i.chain=i.prototype,i.chain.toJSON=function(){};var r=t("./type");r.obj.to(r,i),i.HAM=t("./HAM"),i.val=t("./val"),i.node=t("./node"),i.state=t("./state"),i.graph=t("./graph"),i.on=t("./onto"),i.ask=t("./ask"),i.dup=t("./dup"),function(){function t(t){var n,o,e=this,r=e.as,u=r.gun;(o=t["#"])||(o=t["#"]=c(9)),(n=r.dup).check(o)||(n.track(o),r.ask(t["@"],t)||(t.get&&i.on.get(t,u),t.put&&i.on.put(t,u)),r.on("out",t))}i.create=function(n){n.root=n.root||n.gun,n.graph=n.graph||{},n.on=n.on||i.on,n.ask=n.ask||i.ask,n.dup=n.dup||i.dup();var o=n.gun.opt(n.opt);return n.once||(n.on("in",t,n),n.on("out",t,n)),n.once=1,o}}(),function(){function t(t,n,o,e){var r=this,u=i.state.is(o,n);if(!u)return r.err="Error: No state on '"+n+"' in node '"+e+"'!";var a=r.graph[e]||m,s=i.state.is(a,n,!0),f=a[n],c=i.HAM(r.machine,u,s,t,f);return c.incoming?(r.put[e]=i.state.to(o,n,r.put[e]),(r.diff||(r.diff={}))[e]=i.state.to(o,n,r.diff[e]),void(r.souls[e]=!0)):void(c.defer&&(r.defer=u<(r.defer||1/0)?u:r.defer))}function n(t,n){var i=this,u=i.gun._,a=(u.next||m)[n];if(!a)return void(i.souls[n]=!1);var s=i.map[n]={put:t,get:n,gun:a},f={ctx:i,msg:s};i.async=!!u.tag.node,i.ack&&(s["@"]=i.ack),g(t,o,f),i.async&&(i.and||u.on("node",function(t){this.to.next(t),t===i.map[t.get]&&(i.souls[t.get]=!1,g(t.put,e,t),g(i.souls,function(t){return t?t:void 0})||i.c||(i.c=1,this.off(),u.stop={},g(i.map,r,i)))}),i.and=!0,u.on("node",s))}function o(t,n){var o=this.ctx,e=o.graph,r=this.msg,u=r.get,a=r.put,s=r.gun._;e[u]=i.state.to(a,n,e[u]),o.async||(s.put=i.state.to(a,n,s.put))}function e(t,n){var o=this,e=o.put,r=o.gun._;r.put=i.state.to(e,n,r.put)}function r(t){t.gun&&t.gun._.on("in",t)}i.on.put=function(o,e){var a=e._,s={gun:e,graph:a.graph,put:{},map:{},souls:{},machine:i.state(),ack:o["@"]};return i.graph.is(o.put,null,t,s)||(s.err="Error: Invalid graph!"),s.err?a.on("in",{"@":o["#"],err:i.log(s.err)}):(g(s.put,n,s),s.async||(a.stop={},g(s.map,r,s)),u!==s.defer&&setTimeout(function(){i.on.put(o,e)},s.defer-s.machine),void(s.diff&&a.on("put",d(o,{put:s.diff}))))},i.on.get=function(t,n){var o=n._,e=t.get[b],r=o.graph[e],u=t.get[_],a=o.next||(o.next={}),s=(a[e]||m)._;if(!r||!s)return o.on("get",t);if(u){if(!h(r,u))return o.on("get",t);r=i.state.to(r,u)}else r=i.obj.copy(r);r=i.graph.node(r),o.on("in",{"@":t["#"],how:"mem",put:r,gun:n}),o.on("get",t)}}(),function(){i.chain.opt=function(t){t=t||{};var n=this,o=n._,e=t.peers||t;return p(t)||(t={}),p(o.opt)||(o.opt=t),f(e)&&(e=[e]),a(e)&&(e=g(e,function(t,n,o){o(t,{url:t})}),p(o.opt.peers)||(o.opt.peers={}),o.opt.peers=d(e,o.opt.peers)),o.opt.peers=o.opt.peers||{},d(t,o.opt),i.on("opt",o),o.opt.uuid=o.opt.uuid||function(){return v()+c(12)},n}}();var u,a=i.list.is,s=i.text,f=s.is,c=s.random,l=i.obj,p=l.is,h=l.has,d=l.to,g=l.map,v=(l.copy,i.state.lex),b=i.val.rel._,_=".",m=(i.node._,i.val.rel.is,{});o.debug=function(t,n){return o.debug.i&&t===o.debug.i&&o.debug.i++&&(o.log.apply(o,arguments)||n)},i.log=function(){return!i.log.off&&o.log.apply(o,arguments),[].slice.call(arguments).join(" ")},i.log.once=function(t,n,o){return(o=i.log.once)[t]=o[t]||0,o[t]++||i.log(n)},i.log.once("welcome","Hello wonderful person! :) Thanks for using GUN, feel free to ask for help on https://gitter.im/amark/gun and ask StackOverflow questions tagged with 'gun'!"),"undefined"!=typeof window&&(window.Gun=i);try{"undefined"!=typeof e&&(e.exports=i)}catch(y){}n.exports=i})(t,"./root"),t(function(){var n=t("./root");n.chain.back=function(t,i){var r;if(t=t||1,-1===t||1/0===t)return this._.root;if(1===t)return this._.back||this;var u=this,a=u._;if("string"==typeof t&&(t=t.split(".")),!(t instanceof Array)){if(t instanceof Function){for(var s,r={back:u};(r=r.back)&&(r=r._)&&!(s=t(r,i)););return s}return n.num.is(t)?a.back.back(t-1):this}var f=0,c=t.length,r=a;for(f;c>f;f++)r=(r||e)[t[f]];return o!==r?i?u:r:(r=a.back)?r.back(t,i):void 0};var o,e={}})(t,"./back"),t(function(){function n(t){var n,o=this.as,e=o.back._,i=o.root._;if(t.gun||(t.gun=o.gun),this.to.next(t),n=t.get){if(n["#"]||o.soul){if(n["#"]=n["#"]||o.soul,t["#"]||(t["#"]=_(9)),e=i.gun.get(n["#"])._,n=n["."]){if(d(e.put,n))return void e.on("in",{gun:e.gun,put:c.state.to(e.put,n),get:e.get})}else{if(d(e,"put")&&e.on("in",e),e.ack)return;t.gun=e.gun,e.ack=-1}return i.ask(f,t),i.on("in",t)}if(i.now&&(i.now[o.id]=i.now[o.id]||!0),n["."])return o.get?(t={get:{".":o.get},gun:o.gun},(e.ask||(e.ask={}))[o.get]=t.gun,e.on("out",t)):(t={get:{},gun:o.gun},e.on("out",t));if(o.ack=o.ack||-1,o.get)return t.gun=o.gun,n["."]=o.get,(e.ask||(e.ask={}))[o.get]=t.gun,e.on("out",t)}return e.on("out",t)}function o(t){var n,o=this,r=this.as,s=t.gun,f=s._,p=t.put;if(r.get&&t.get!==r.get&&(t=v(t,{get:r.get})),r.has&&f!==r&&(t=v(t,{gun:r.gun}),f.ack&&(r.ack=f.ack)),y===r.get&&p&&p["#"]&&(r._id=p["#"]),l===p){if(o.to.next(t),r.soul)return;return i(r,t,o),r.has&&a(r,t),g(f.echo,r.id),void g(r.map,f.id)}return r.soul?(o.to.next(t),i(r,t,o),void b(p,u,{at:t,cat:r})):(n=c.val.rel.is(p))?(e(r,t,f,n),o.to.next(t),void i(r,t,o)):c.val.is(p)?(r.has||r.soul?a(r,t):(f.has||f.soul)&&((f.echo||(f.echo={}))[r.id]=r,(r.map||(r.map={}))[f.id]=r.map[f.id]||{at:f}),o.to.next(t),void i(r,t,o)):(r.has&&f!==r&&d(f,"put")&&(r.put=f.put),(n=c.node.soul(p))&&f.has&&(f.put=r.root.get(n)._.put),o.to.next(t),i(r,t,o),e(r,t,f,n),void b(p,u,{at:t,cat:r}))}function e(t,n,o,i){if(i&&y!==t.get){var r=t.root.get(i)._;if(t.has?o=r:o.has&&e(o,n,o,i),o!==t){(o.echo||(o.echo={}))[t.id]=t,t.has&&!(t.map||p)[o.id]&&a(t,n),r=(t.map||(t.map={}))[o.id]=t.map[o.id]||{at:o};var u=t.root._.now;if(i===r.rel){if(!u)return;if(l===u[t.id])return;if((u._||(u._={}))[t.id]===i)return;u._[t.id]=i}s(t,r.rel=i)}}}function i(t,n,o){t.echo&&(t.has&&(n=v(n,{event:o})),b(t.echo,r,n))}function r(t){t.on("in",this)}function u(t,n){var o,e,i,r=this.cat,u=r.next||p,a=this.at;(y!==n||u[n])&&(o=u[n])&&(i=o._,i.has?(t&&t[m]&&c.val.rel.is(t)===c.node.soul(i.put)||(i.put=t),e=o):e=a.gun.get(n),i.on("in",{put:t,get:n,gun:e,via:a}))}function a(t,n){if(t.has||t.soul){var o=t.map,e=t.root._;t.map=null,(e.now&&e.now[t.id]||n["@"]||null!==o)&&(l===o&&c.val.rel.is(t.put)||(b(o,function(n){(n=n.at)&&g(n.echo,t.id)}),b(t.next,function(t,n){var o=t._;o.put=l,o.ack&&(o.ack=-1),o.on("in",{get:n,gun:t,put:l})})))}}function s(t,n){var o=t.root.get(n)._;(!t.ack||(o.on("out",{get:{"#":n}}),t.ask))&&(b(t.ask||t.next,function(t,o){t._.on("out",{get:{"#":n,".":o}})}),c.obj.del(t,"ask"))}function f(t){var n=this.as,o=n.get||p,e=n.gun._,i=(t.put||p)[o["#"]];if(e.ack&&(e.ack=e.ack+1||1),!t.put||o["."]&&!d(i,e.get)){if(e.put!==l)return;return void e.on("in",{get:e.get,put:e.put=l,gun:e.gun,"@":t["@"]})}return y==o["."]?void e.on("in",{get:e.get,put:i[e.get],gun:e.gun,"@":t["@"]}):(t.gun=e.root,void c.on.put(t,e.root))}var c=t("./root");c.chain.chain=function(){var t,e=this._,i=new this.constructor(this),r=i._;return r.root=t=e.root,r.id=++t._.once,r.back=this,r.on=c.on,r.on("in",o,r),r.on("out",n,r),i};var l,p={},h=c.obj,d=h.has,g=(h.put,h.del),v=h.to,b=h.map,_=c.text.random,m=c.val.rel._,y=c.node._})(t,"./chain"),t(function(){function n(t,n){var o=n._,e=o.next,i=n.chain(),r=i._;return e||(e=o.next={}),e[r.get=t]=i,o.root===n?r.soul=t:(o.soul||o.has)&&(r.has=t),i}function o(t){var n,o=this,e=o.as,r=t.gun,a=r._,f=a.root._,c=t.put;return(n=f.now)&&o!==n[e.now]?o.to.next(t):(i===c&&(c=a.put),(n=c)&&n[s._]&&(n=s.is(n))&&(n=a.root.get(n)._,i!==n.put&&(t=u(t,{put:n.put}))),e.use(t,t.event||o),void o.to.next(t))}var e=t("./root");e.chain.get=function(t,i,r){if("string"!=typeof t){if(t instanceof Function){var u,s=this,c=s._,l=c.root._,p=l.now;return r=i||{},r.use=t,r.out=r.out||{},r.out.get=r.out.get||{},u=c.on("in",o,r),(l.now={$:1})[r.now=c.id]=u,c.on("out",r.out),l.now=p,s}return a(t)?this.get(""+t,i,r):((r=this.chain())._.err={err:e.log("Invalid get request!",t)},i&&i.call(r,r._.err),r)}var s,p,h=this,d=h._,g=d.next||f;return(s=g[t])||(s=n(t,h)),(p=d.stun)&&(s._.stun=s._.stun||p),i&&i instanceof Function&&s.get(i,r),s};var i,r=e.obj,u=(r.has,e.obj.to),a=e.num.is,s=e.val.rel,f=(e.node._,{})})(t,"./get"),t(function(){function n(t){t.batch=i;var n=t.opt||{},o=t.env=c.state.map(u,n.state);return o.soul=t.soul,t.graph=c.graph.ify(t.data,o,t),o.err?((t.ack||b).call(t,t.out={err:c.log(o.err)}),void(t.res&&t.res())):void t.batch()}function e(t){return void(t&&t())}function i(){var t=this;t.graph&&!g(t.stun,r)&&(t.res=t.res||function(t){t&&t()},t.res(function(){var n=t.gun.back(-1)._,o=n.ask(function(n){this.off(),t.ack&&t.ack(n,this)},t.opt),e=n.root._.now;p.del(n.root._,"now"),n.root._.PUT=!0;var i=n.root._.stop;t.ref._.now=!0,t.ref._.on("out",{gun:t.ref,put:t.out=t.env.graph,opt:t.opt,"#":o}),p.del(t.ref._,"now"),p.del(n.root._,"PUT"),n.root._.now=e,n.root._.stop=i},t),t.res&&t.res())}function r(t){return t?!0:void 0}function u(t,n,o,e){var i=this;!n&&e.path.length&&(i.res||_)(function(){var t=e.path,n=i.ref,o=(i.opt,0),r=t.length;for(o;r>o;o++)n=n.get(t[o]);if(c.node.soul(e.obj)){var u=c.node.soul(e.obj)||(n.back("opt.uuid")||c.text.random)();return u?(n.back(-1).get(u),void e.soul(u)):((i.stun=i.stun||{})[t]=!0,void n.back("opt.uuid")(function(o,r){return o?c.log(o):(n.back(-1).get(r),e.soul(r),i.stun[t]=!1,void i.batch())}))}(i.stun=i.stun||{})[t]=!0,n.get("_").get(a,{as:{at:e,as:i}})},{as:i,at:e})}function a(t,n){var o=this.as,e=o.at;if(o=o.as,t.gun&&t.gun._.back){var i=t.gun._,r=i,u=(t.put||v)["#"];n.off(),i=t.gun._.back._;var a=a||c.node.soul(e.obj)||c.node.soul(i.put)||c.val.rel.is(i.put)||u||r._id||(o.gun.back("opt.uuid")||c.text.random)();return a?void s(i,r._id=r._id||a,e,o):void i.gun.back("opt.uuid")(function(t,n){return t?c.log(t):void s(i,r._id=r._id||n,e,o)})}}function s(t,n,o,e){t.gun.back(-1).get(n),o.soul(n),e.stun[o.path]=!1,e.batch()}function f(t,n){var e=this.as;if(t.gun&&t.gun._){if(t.err)return void o.log("Please report this as an issue! Put.any.err");var i,r=t.gun._.back._,u=r.put,a=e.opt||{};if(!(i=e.ref)||!i._.now){if(n.off(),e.ref!==e.gun){if(i=e.gun._.get||r.get,!i)return void o.log("Please report this as an issue! Put.no.get");e.data=d({},i,e.data),i=null}if(l===u){if(!r.get)return;r.soul||(i=r.gun.back(function(t){return t.soul?t.soul:void(e.data=d({},t.get,e.data))})),i=i||r.get,r=r.root.get(i)._,e.not=e.soul=i,u=e.data}return e.not||(e.soul=c.node.soul(u))||(e.path&&h(e.data)?e.soul=(a.uuid||r.root._.opt.uuid||c.text.random)():(m==t.get&&(e.soul=(t.put||v)["#"]||t._id),e.soul=e.soul||t.soul||r.soul||(a.uuid||r.root._.opt.uuid||c.text.random)()),e.soul)?void e.ref.put(e.data,e.soul,e):void e.ref.back("opt.uuid")(function(t,n){return t?c.log(t):void e.ref.put(e.data,e.soul=n,e)})}}}var c=t("./root");c.chain.put=function(t,o,i){var r,u=this,a=u._,s=a.root;return i=i||{},i.data=t,i.gun=i.gun||u,"string"==typeof o?i.soul=o:i.ack=o,a.soul&&(i.soul=a.soul),i.soul||s===u?h(i.data)?(i.soul=i.soul||(i.not=c.node.soul(i.data)||(s._.opt.uuid||c.text.random)()),i.soul?(i.gun=u=s.get(i.soul),i.ref=i.gun,n(i),u):(s._.opt.uuid(function(t,n){return t?c.log(t):void(i.ref||i.gun).put(i.data,i.soul=n,i)}),u)):((i.ack||b).call(i,i.out={err:c.log("Data saved to the root level of the graph must be a node (an object), not a",typeof i.data,'of "'+i.data+'"!')}),i.res&&i.res(),u):c.is(t)?(t.get("_").get(function(t,n,e){return n.off(),(e=t.gun)&&(e=e._.back)&&e._.soul?void u.put(c.val.rel.ify(e._.soul),o,i):c.log("The reference you are saving is a",typeof t.put,'"'+i.put+'", not a node (object)!')}),u):(i.ref=i.ref||s===(r=a.back)?u:r,i.ref._.soul&&c.val.is(i.data)&&a.get?(i.data=d({},a.get,i.data),i.ref.put(i.data,i.soul,i),u):(i.ref.get("_").get(f,{as:i}),i.out||(i.res=i.res||e,i.gun._.stun=i.ref._.stun),u))};var l,p=c.obj,h=p.is,d=p.put,g=p.map,v={},b=function(){},_=function(t,n){t.call(n||v)},m=c.node._})(t,"./put"),t(function(n){var o=t("./root");t("./chain"),t("./back"),t("./put"),t("./get"),n.exports=o})(t,"./index"),t(function(){function n(t,n){var o,r=this,u=t.gun,a=u._,f=a.put||t.put,o=r.last,c=a.id+t.get;if(i!==f){if(f&&f[s._]&&(o=s.is(f))){if(o=a.root.get(o)._,i===o.put)return;f=o.put}r.change&&(f=t.put),(o.put!==f||o.get!==c||e.node.soul(f))&&(o.put=f,o.get=c,a.last=f,r.as?r.ok.call(r.as,t,n):r.ok.call(u,f,t.get,t,n))}}function o(t,n,r){var u,a=this.as,f=a.cat,c=t.gun,l=c._,p=l.put||t.put;if(u=e.node.soul(p)||s.is(p)){if(u=f.root.get(u)._,i===u.put)return;p=u.put}if(n.wait&&clearTimeout(n.wait),!r)return void(n.wait=setTimeout(function(){o.call({as:a},t,n,n.wait||1)},a.wait||99));if(f.has||f.soul){if(n.off())return}else{if((a.seen=a.seen||{})[l.id])return;a.seen[l.id]=!0}a.ok.call(t.gun||a.gun,p,t.get)}var e=t("./index");e.chain.on=function(t,o,e,i){var r,u,a=this,s=a._;if("string"==typeof t)return o?(r=s.on(t,o,e||s,i),e&&e.gun&&(e.subs||(e.subs=[])).push(r),u=function(){r&&r.off&&r.off(),u.off()},u.off=a.off.bind(a)||f,a.off=u,a):s.on(t);var c=o;return c=!0===c?{change:!0}:c||{},c.ok=t,c.last={},a.get(n,c),a},e.chain.val=function(t,n){return e.log.once("onceval","Future Breaking API Change: .val -> .once, apologies unexpected."),this.once(t,n)},e.chain.once=function(t,n){var r=this,u=r._,a=u.put;if(0=(n.batch||1e3)?s():void(e||(e=setTimeout(s,n.wait||1)))}),t.on("get",function(o){this.to.next(o);var e,i,r,a=o.get;if(a&&(e=a["#"])){var s=a["."];i=u[e]||r,i&&s&&(i=Gun.state.to(i,s)),(i||Gun.obj.empty(n.peers))&&t.on("in",{"@":o["#"],put:Gun.graph.node(i),how:"lS"})}});var a=function(t,n,o,e){u[e]=Gun.state.to(o,n,u[e])},s=function(){var a;r=0,clearTimeout(e),e=!1;var s=i;i={};try{o.setItem(n.file,JSON.stringify(u))}catch(f){Gun.log(a=f||"localStorage failure")}(a||Gun.obj.empty(n.peers))&&Gun.obj.map(s,function(n,o){t.on("in",{"@":o,err:a,ok:0})})}}})}})(t,"./adapters/localStorage"),t(function(n){function o(t){var n=function(){};return n.out=function(o){var e;return this.to&&this.to.next(o),(e=o["@"])&&(e=t.dup.s[e])&&(e=e.it)&&e.mesh?(n.say(o,e.mesh.via),void(e["##"]=o["##"])):void n.say(o)},n.hear=function(o,i){if(o){var r,u,a=t.dup,s=o[0];try{o=JSON.parse(o)}catch(f){}if("{"===s){if(a.check(r=o["#"]))return;if(a.track(r,!0).it=o,(s=o["@"])&&o.put&&(u=o["##"]||(o["##"]=n.hash(o)),(s+=u)!=r)){if(a.check(s))return;(s=a.s)[u]=s[r]}return(o.mesh=function(){}).via=i,(s=o["><"])&&(o.mesh.to=e.obj.map(s.split(","),function(t,n,o){o(t,!0)})),void t.on("in",o)}if("["!==s);else for(var c,l=0;c=o[l++];)n.hear(c,i)}},function(){function o(t,n){var o=n.wire;try{o.send?o.readyState===o.OPEN?o.send(t):(n.queue=n.queue||[]).push(t):n.say&&n.say(t)}catch(e){(n.queue=n.queue||[]).push(t)}}n.say=function(i,u){if(!u)return void e.obj.map(t.opt.peers,function(t){n.say(i,t)});var a,s,f,c=u.wire||t.opt.wire&&t.opt.wire(u);if(c&&(s=i.mesh||r,u!==s.via&&((f=s.raw)||(f=n.raw(i)),!((a=i["@"])&&(a=t.dup.s[a])&&(a=a.it)&&a.get&&a["##"]&&a["##"]===i["##"]||(a=s.to)&&(a[u.url]||a[u.id]))))){if(u.batch)return void u.batch.push(f);u.batch=[],setTimeout(function(){var t=u.batch;t&&(u.batch=null,t.length&&o(JSON.stringify(t),u))},t.opt.wait||1),o(f,u)}}}(),function(){function r(t,n){var o;return n instanceof Object?(e.obj.map(Object.keys(n).sort(),u,{to:o={},on:n}),o):n}function u(t){this.to[t]=this.on[t]}n.raw=function(o){if(!o)return"";var u,f,c,l=t.dup,p=o.mesh||{};if(c=p.raw)return c;if("string"==typeof o)return o;o["@"]&&(c=o.put)&&((f=o["##"])||(u=a(c,r)||"",f=n.hash(o,u),o["##"]=f),(c=l.s)[f=o["@"]+f]=c[o["#"]],o["#"]=f,u&&((o=e.obj.to(o)).put=s));var h=0,d=[];e.obj.map(t.opt.peers,function(t){return d.push[t.url||t.id],++h>9?!0:void 0}),o["><"]=d.join();var g=a(o);return i!==u&&(g=g.replace('"'+s+'"',u)),p&&(p.raw=g),g},n.hash=function(t,n){return o.hash(n||a(t.put,r)||"")||t["#"]||e.text.random(9)};var a=JSON.stringify,s=":])([:"}(),n.hi=function(o){t.on("hi",o);var i=o.queue;o.queue=[],e.obj.map(i,function(t){n.say(t,o)})},n}var e=t("./type");o.hash=function(t){if("string"!=typeof t)return{err:1};var n=0;if(!t.length)return n;for(var o,e=0,i=t.length;i>e;++e)o=t.charCodeAt(e),n=(n<<5)-n+o,n|=0;return n};var i,r={};Object.keys=Object.keys||function(t){return map(t,function(t,n,o){o(n)})};try{n.exports=o}catch(u){}})(t,"./adapters/mesh"),t(function(){var n=t("../index");n.Mesh=t("./mesh"),n.on("opt",function(t){function o(n){if(n&&n.url){var o=n.url.replace("http","ws"),r=n.wire=new i.WebSocket(o);return r.onclose=function(){t.on("bye",n),e(n)},r.onerror=function(t){e(n),t&&"ECONNREFUSED"===t.code},r.onopen=function(){a.hi(n)},r.onmessage=function(t){t&&a.hear(t.data||t,n)},r}}function e(t){clearTimeout(t.defer),t.defer=setTimeout(function(){o(t)},2e3)}this.to.next(t);var i=t.opt;if(!t.once&&!1!==i.WebSocket){var r;"undefined"!=typeof window&&(r=window),"undefined"!=typeof global&&(r=global),r=r||{};var u=i.WebSocket||r.WebSocket||r.webkitWebSocket||r.mozWebSocket;if(u){i.WebSocket=u;var a=i.mesh=i.mesh||n.Mesh(t);t.on("out",a.out),i.wire=i.wire||o}}})})(t,"./adapters/websocket")}(); \ No newline at end of file +!function(){function t(n){function o(t){return t.split("/").slice(-1).toString().replace(".js","")}return n.slice?t[o(n)]:function(e,i){n(e={exports:{}}),t[o(i)]=e.exports}}var n;"undefined"!=typeof window&&(n=window),"undefined"!=typeof global&&(n=global),n=n||{};var o=n.console||{log:function(){}};if("undefined"!=typeof module)var e=module;t(function(t){var n={};n.fns=n.fn={is:function(t){return!!t&&"function"==typeof t}},n.bi={is:function(t){return t instanceof Boolean||"boolean"==typeof t}},n.num={is:function(t){return!e(t)&&(t-parseFloat(t)+1>=0||1/0===t||-(1/0)===t)}},n.text={is:function(t){return"string"==typeof t}},n.text.ify=function(t){return n.text.is(t)?t:"undefined"!=typeof JSON?JSON.stringify(t):t&&t.toString?t.toString():t},n.text.random=function(t,n){var o="";for(t=t||24,n=n||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";t>0;)o+=n.charAt(Math.floor(Math.random()*n.length)),t--;return o},n.text.match=function(t,o){function e(t,n){for(var o,e=-1,i=0;o=n[i++];)if(!~(e=t.indexOf(o,e+1)))return!1;return!0}var i=!1;if(t=t||"",o=n.text.is(o)?{"=":o}:o||{},n.obj.has(o,"~")&&(t=t.toLowerCase(),o["="]=(o["="]||o["~"]).toLowerCase()),n.obj.has(o,"="))return t===o["="];if(n.obj.has(o,"*")){if(t.slice(0,o["*"].length)!==o["*"])return!1;i=!0,t=t.slice(o["*"].length)}if(n.obj.has(o,"!")){if(t.slice(-o["!"].length)!==o["!"])return!1;i=!0}if(n.obj.has(o,"+")&&n.list.map(n.list.is(o["+"])?o["+"]:[o["+"]],function(n){return t.indexOf(n)>=0?void(i=!0):!0}))return!1;if(n.obj.has(o,"-")&&n.list.map(n.list.is(o["-"])?o["-"]:[o["-"]],function(n){return t.indexOf(n)<0?void(i=!0):!0}))return!1;if(n.obj.has(o,">")){if(!(t>o[">"]))return!1;i=!0}if(n.obj.has(o,"<")){if(!(tn?-1:n>o?1:0):0}},n.list.map=function(t,n,o){return a(t,n,o)},n.list.index=1,n.obj={is:function(t){return t?t instanceof Object&&t.constructor===Object||"Object"===Object.prototype.toString.call(t).match(/^\[object (\w+)\]$/)[1]:!1}},n.obj.put=function(t,n,o){return(t||{})[n]=o,t},n.obj.has=function(t,n){return t&&Object.prototype.hasOwnProperty.call(t,n)},n.obj.del=function(t,n){return t?(t[n]=null,delete t[n],t):void 0},n.obj.as=function(t,n,o,e){return t[n]=t[n]||(e===o?{}:o)},n.obj.ify=function(t){if(r(t))return t;try{t=JSON.parse(t)}catch(n){t={}}return t},function(){function t(t,n){u(this,n)&&o!==this[n]||(this[n]=t)}var o;n.obj.to=function(n,o){return o=o||{},a(n,t,o),o}}(),n.obj.copy=function(t){return t?JSON.parse(JSON.stringify(t)):t},function(){function t(t,n){var o=this.n;if(!o||!(n===o||r(o)&&u(o,n)))return n?!0:void 0}n.obj.empty=function(n,o){return n&&a(n,t,{n:o})?!1:!0}}(),function(){function t(n,o){return 2===arguments.length?(t.r=t.r||{},void(t.r[n]=o)):(t.r=t.r||[],void t.r.push(n))}var i=Object.keys;n.obj.map=function(a,s,f){var c,l,p,g,h,d=0,v=o(s);if(t.r=null,i&&r(a)&&(g=i(a),h=!0),e(a)||g)for(l=(g||a).length;l>d;d++){var b=d+n.list.index;if(v){if(p=h?s.call(f||this,a[g[d]],g[d],t):s.call(f||this,a[d],b,t),p!==c)return p}else if(s===a[h?g[d]:d])return g?g[d]:b}else for(d in a)if(v){if(u(a,d)&&(p=f?s.call(f,a[d],d,t):s(a[d],d,t),p!==c))return p}else if(s===a[d])return d;return v?t.r:n.list.index?0:-1}}(),n.time={},n.time.is=function(t){return t?t instanceof Date:+(new Date).getTime()};var o=n.fn.is,e=n.list.is,i=n.obj,r=i.is,u=i.has,a=i.map;t.exports=n})(t,"./type"),t(function(t){t.exports=function n(t,o,e){if(!t)return{to:n};var t=(this.tag||(this.tag={}))[t]||(this.tag[t]={tag:t,to:n._={next:function(t){var n;(n=this.to)&&n.next(t)}}});if(o instanceof Function){var i={off:n.off||(n.off=function(){return this.next===n._.next?!0:(this===this.the.last&&(this.the.last=this.back),this.to.back=this.back,this.next=n._.next,this.back.to=this.to,void(this.the.last===this.the&&delete this.on.tag[this.the.tag]))}),to:n._,next:o,the:t,on:this,as:e};return(i.back=t.last||t).to=i,t.last=i}return(t=t.to).next(o),t}})(t,"./onto"),t(function(t){function n(t,n,e,i,r){if(n>t)return{defer:!0};if(e>n)return{historical:!0};if(n>e)return{converge:!0,incoming:!0};if(n===e){if(i=o(i)||"",r=o(r)||"",i===r)return{state:!0};if(r>i)return{converge:!0,current:!0};if(i>r)return{converge:!0,incoming:!0}}return{err:"Invalid CRDT Data: "+i+" to "+r+" at "+n+" to "+e+"!"}}if("undefined"==typeof JSON)throw new Error("JSON is not included in this browser. Please load it first: ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js");var o=JSON.stringify;t.exports=n})(t,"./HAM"),t(function(n){var o=t("./type"),e={};e.is=function(t){return t===i?!1:null===t?!0:t===1/0?!1:s(t)||u(t)||a(t)?!0:e.rel.is(t)||!1},e.rel={_:"#"},function(){function t(t,n){var o=this;return o.id?o.id=!1:n==r&&s(t)?void(o.id=t):o.id=!1}e.rel.is=function(n){if(n&&n[r]&&!n._&&c(n)){var o={};if(p(n,t,o),o.id)return o.id}return!1}}(),e.rel.ify=function(t){return l({},r,t)},o.obj.has._=".";var i,r=e.rel._,u=o.bi.is,a=o.num.is,s=o.text.is,f=o.obj,c=f.is,l=f.put,p=f.map;n.exports=e})(t,"./val"),t(function(n){var o=t("./type"),e=t("./val"),i={_:"_"};i.soul=function(t,n){return t&&t._&&t._[n||p]},i.soul.ify=function(t,n){return n="string"==typeof n?{soul:n}:n||{},t=t||{},t._=t._||{},t._[p]=n.soul||t._[p]||l(),t},i.soul._=e.rel._,function(){function t(t,n){return n!==i._?e.is(t)?void(this.cb&&this.cb.call(this.as,t,n,this.n,this.s)):!0:void 0}i.is=function(n,o,e){var r;return a(n)&&(r=i.soul(n))?!f(n,t,{as:e,cb:o,s:r,n:n}):!1}}(),function(){function t(t,n){var o,i,r=this.o;return r.map?(o=r.map.call(this.as,t,""+n,r.node),void(i===o?s(r.node,n):r.node&&(r.node[n]=o))):void(e.is(t)&&(r.node[n]=t))}i.ify=function(n,o,e){return o?"string"==typeof o?o={soul:o}:o instanceof Function&&(o={map:o}):o={},o.map&&(o.node=o.map.call(e,n,r,o.node||{})),(o.node=i.soul.ify(o.node||{},o))&&f(n,t,{o:o,as:e}),o.node}}();var r,u=o.obj,a=u.is,s=u.del,f=u.map,c=o.text,l=c.random,p=i.soul._;n.exports=i})(t,"./node"),t(function(n){function o(){var t;return t=f?c+f.now():r(),t>u?(a=0,u=t+o.drift):u=t+(a+=1)/s+o.drift}var e=t("./type"),i=t("./node"),r=e.time.is,u=-(1/0),a=0,s=1e3,f="undefined"!=typeof performance?performance.timing&&performance:!1,c=f&&f.timing&&f.timing.navigationStart||(f=!1);o._=">",o.drift=0,o.is=function(t,n,e){var i=n&&t&&t[x]&&t[x][o._]||e;if(i)return _(i=i[n])?i:-(1/0)},o.lex=function(){return o().toString(36).replace(".","")},o.ify=function(t,n,e,r,u){if(!t||!t[x]){if(!u)return;t=i.soul.ify(t,u)}var a=g(t[x],o._);return l!==n&&n!==x&&(_(e)&&(a[n]=e),l!==r&&(t[n]=r)),t},o.to=function(t,n,e){var r=t[n];return d(r)&&(r=b(r)),o.ify(e,n,o.is(t,n),r,i.soul(t))},function(){function t(t,n){x!==n&&o.ify(this.o,n,this.s)}o.map=function(n,e,i){var r,u=d(u=n||e)?u:null;return n=k(n=n||e)?n:null,u&&!n?(e=_(e)?e:o(),u[x]=u[x]||{},v(u,t,{o:u,s:e}),u):(i=i||d(e)?e:r,e=_(e)?e:o(),function(o,u,a,s){return n?(n.call(i||this||{},o,u,a,s),void(h(a,u)&&r===a[u]||t.call({o:a,s:e},o,u))):(t.call({o:a,s:e},o,u),o)})}}();var l,p=e.obj,g=p.as,h=p.has,d=p.is,v=p.map,b=p.copy,m=e.num,_=m.is,y=e.fn,k=y.is,x=i._;n.exports=o})(t,"./state"),t(function(n){var o=t("./type"),e=t("./val"),i=t("./node"),r={};!function(){function t(t,o){return t&&o===i.soul(t)&&i.is(t,this.fn,this.as)?void(this.cb&&(n.n=t,n.as=this.as,this.cb.call(n.as,t,o,n))):!0}function n(t){t&&i.is(n.n,t,n.as)}r.is=function(n,o,e,i){return n&&s(n)&&!l(n)?!g(n,t,{cb:o,fn:e,as:i}):!1}}(),function(){function t(t,o){var r;return(r=p(t,o))?r:(o.env=t,o.soul=a,i.ify(o.obj,n,o)&&(t.graph[e.rel.is(o.rel)]=o.node),o)}function n(n,o,r){var a,s,p=this,g=p.env;if(i._===o&&c(n,e.rel._))return r._;if(a=l(n,o,r,p,g)){if(o||(p.node=p.node||r||{},c(n,i._)&&(p.node._=h(n._)),p.node=i.soul.ify(p.node,e.rel.is(p.rel)),p.rel=p.rel||e.rel.ify(i.soul(p.node))),(s=g.map)&&(s.call(g.as||{},n,o,r,p),c(r,o))){if(n=r[o],u===n)return void f(r,o);if(!(a=l(n,o,r,p,g)))return}if(!o)return p.node;if(!0===a)return n;if(s=t(g,{obj:n,path:p.path.concat(o)}),s.node)return s.rel}}function a(t){var n=this,o=e.rel.is(n.rel),r=n.env.graph;n.rel=n.rel||e.rel.ify(t),n.rel[e.rel._]=t,n.node&&n.node[i._]&&(n.node[i._][e.rel._]=t),c(r,o)&&(r[t]=r[o],f(r,o))}function l(t,n,i,r,u){var a;return e.is(t)?!0:s(t)?1:(a=u.invalid)?(t=a.call(u.as||{},t,n,i),l(t,n,i,r,u)):(u.err="Invalid value at '"+r.path.concat(n).join(".")+"'!",void(o.list.is(t)&&(u.err+=" Use `.set(item)` instead of an Array.")))}function p(t,n){for(var o,e=t.seen,i=e.length;i--;)if(o=e[i],n.obj===o.obj)return o;e.push(n)}r.ify=function(n,o,i){var r={path:[],obj:n};return o?"string"==typeof o?o={soul:o}:o instanceof Function&&(o.map=o):o={},o.soul&&(r.rel=e.rel.ify(o.soul)),o.graph=o.graph||{},o.seen=o.seen||[],o.as=o.as||i,t(o,r),o.root=r.node,o.graph}}(),r.node=function(t){var n=i.soul(t);if(n)return p({},n,t)},function(){function t(t,n){var o,u;if(i._===n){if(l(t,e.rel._))return;return void(this.obj[n]=h(t))}return(o=e.rel.is(t))?(u=this.opt.seen[o])?void(this.obj[n]=u):void(this.obj[n]=this.opt.seen[o]=r.to(this.graph,o,this.opt)):void(this.obj[n]=t)}r.to=function(n,o,e){if(n){var i={};return e=e||{seen:{}},g(n[o],t,{obj:i,graph:n,opt:e}),i}}}();var u,a=(o.fn.is,o.obj),s=a.is,f=a.del,c=a.has,l=a.empty,p=a.put,g=a.map,h=a.copy;n.exports=r})(t,"./graph"),t(function(n){t("./onto"),n.exports=function(t,n){if(this.on){if(!(t instanceof Function)){if(!t||!n)return;var o=t["#"]||t,e=(this.tag||empty)[o];if(!e)return;return e=this.on(o,n),clearTimeout(e.err),!0}var o=n&&n["#"]||Math.random().toString(36).slice(2);if(!t)return o;var i=this.on(o,t,n);return i.err=i.err||setTimeout(function(){i.next({err:"Error: No ACK received yet."}),i.off()},(this.opt||{}).lack||9e3),o}}})(t,"./ask"),t(function(n){function o(t){var n={s:{}};return t=t||{max:1e3,age:9e3},n.check=function(t){var o;return(o=n.s[t])?o.pass?o.pass=!1:n.track(t):!1},n.track=function(o,r){var u=n.s[o]||(n.s[o]={});return u.was=i(),r&&(u.pass=!0),n.to||(n.to=setTimeout(function(){var o=i();e.obj.map(n.s,function(i,r){t.age>o-i.was||e.obj.del(n.s,r)}),n.to=null},t.age+9)),u},n}var e=t("./type"),i=e.time.is;n.exports=o})(t,"./dup"),t(function(n){function i(t){return t instanceof i?(this._={gun:this}).gun:this instanceof i?i.create(this._={gun:this,opt:t}):new i(t)}i.is=function(t){return t instanceof i},i.version=.9,i.chain=i.prototype,i.chain.toJSON=function(){};var r=t("./type");r.obj.to(r,i),i.HAM=t("./HAM"),i.val=t("./val"),i.node=t("./node"),i.state=t("./state"),i.graph=t("./graph"),i.on=t("./onto"),i.ask=t("./ask"),i.dup=t("./dup"),function(){function t(t){var n,o,e=this,r=e.as,u=r.gun;(o=t["#"])||(o=t["#"]=c(9)),(n=r.dup).check(o)||(n.track(o),r.ask(t["@"],t)||(t.get&&i.on.get(t,u),t.put&&i.on.put(t,u)),r.on("out",t))}i.create=function(n){n.root=n.root||n,n.graph=n.graph||{},n.on=n.on||i.on,n.ask=n.ask||i.ask,n.dup=n.dup||i.dup();var o=n.gun.opt(n.opt);return n.once||(n.on("in",t,n),n.on("out",t,n)),n.once=1,o}}(),function(){function t(t,n,o,e){var r=this,u=i.state.is(o,n);if(!u)return r.err="Error: No state on '"+n+"' in node '"+e+"'!";var a=r.graph[e]||_,s=i.state.is(a,n,!0),f=a[n],c=i.HAM(r.machine,u,s,t,f);return c.incoming?(r.put[e]=i.state.to(o,n,r.put[e]),(r.diff||(r.diff={}))[e]=i.state.to(o,n,r.diff[e]),void(r.souls[e]=!0)):void(c.defer&&(r.defer=u<(r.defer||1/0)?u:r.defer))}function n(t,n){var i=this,u=i.gun._,a=(u.next||_)[n];if(!a)return void(i.souls[n]=!1);var s=i.map[n]={put:t,get:n,gun:a.gun},f={ctx:i,msg:s};i.async=!!u.tag.node,i.ack&&(s["@"]=i.ack),d(t,o,f),i.async&&(i.and||u.on("node",function(t){this.to.next(t),t===i.map[t.get]&&(i.souls[t.get]=!1,d(t.put,e,t),d(i.souls,function(t){return t?t:void 0})||i.c||(i.c=1,this.off(),u.stop={},d(i.map,r,i)))}),i.and=!0,u.on("node",s))}function o(t,n){var o=this.ctx,e=o.graph,r=this.msg,u=r.get,a=r.put,s=r.gun._;e[u]=i.state.to(a,n,e[u]),o.async||(s.put=i.state.to(a,n,s.put))}function e(t,n){var o=this,e=o.put,r=o.gun._;r.put=i.state.to(e,n,r.put)}function r(t){t.gun&&t.gun._.on("in",t)}i.on.put=function(o,e){var a=e._,s={gun:e,graph:a.graph,put:{},map:{},souls:{},machine:i.state(),ack:o["@"]};return i.graph.is(o.put,null,t,s)||(s.err="Error: Invalid graph!"),s.err?a.on("in",{"@":o["#"],err:i.log(s.err)}):(d(s.put,n,s),s.async||(a.stop={},d(s.map,r,s)),u!==s.defer&&setTimeout(function(){i.on.put(o,e)},s.defer-s.machine),void(s.diff&&a.on("put",h(o,{put:s.diff}))))},i.on.get=function(t,n){var o=n._,e=t.get[b],r=o.graph[e],u=t.get[m],a=o.next||(o.next={}),s=a[e];if(!r||!s)return o.on("get",t);if(u){if(!g(r,u))return o.on("get",t);r=i.state.to(r,u)}else r=i.obj.copy(r);r=i.graph.node(r),o.on("in",{"@":t["#"],how:"mem",put:r,gun:n}),o.on("get",t)}}(),function(){i.chain.opt=function(t){t=t||{};var n=this,o=n._,e=t.peers||t;return p(t)||(t={}),p(o.opt)||(o.opt=t),f(e)&&(e=[e]),a(e)&&(e=d(e,function(t,n,o){o(t,{url:t})}),p(o.opt.peers)||(o.opt.peers={}),o.opt.peers=h(e,o.opt.peers)),o.opt.peers=o.opt.peers||{},h(t,o.opt),i.on("opt",o),o.opt.uuid=o.opt.uuid||function(){return v()+c(12)},n}}();var u,a=i.list.is,s=i.text,f=s.is,c=s.random,l=i.obj,p=l.is,g=l.has,h=l.to,d=l.map,v=(l.copy,i.state.lex),b=i.val.rel._,m=".",_=(i.node._,i.val.rel.is,{});o.debug=function(t,n){return o.debug.i&&t===o.debug.i&&o.debug.i++&&(o.log.apply(o,arguments)||n)},i.log=function(){return!i.log.off&&o.log.apply(o,arguments),[].slice.call(arguments).join(" ")},i.log.once=function(t,n,o){return(o=i.log.once)[t]=o[t]||0,o[t]++||i.log(n)},i.log.once("welcome","Hello wonderful person! :) Thanks for using GUN, feel free to ask for help on https://gitter.im/amark/gun and ask StackOverflow questions tagged with 'gun'!"),"undefined"!=typeof window&&(window.Gun=i);try{"undefined"!=typeof e&&(e.exports=i)}catch(y){}n.exports=i})(t,"./root"),t(function(){var n=t("./root");n.chain.back=function(t,i){var r;if(t=t||1,-1===t||1/0===t)return this._.root.gun;if(1===t)return(this._.back||this._).gun;var u=this,a=u._;if("string"==typeof t&&(t=t.split(".")),!(t instanceof Array)){if(t instanceof Function){for(var s,r={back:a};(r=r.back)&&!(s=t(r,i)););return s}return n.num.is(t)?(a.back||a).gun.back(t-1):this}var f=0,c=t.length,r=a;for(f;c>f;f++)r=(r||e)[t[f]];return o!==r?i?u:r:(r=a.back)?r.gun.back(t,i):void 0};var o,e={}})(t,"./back"),t(function(){function n(t){var n,o=this.as,e=o.back,i=o.root;if(t.gun||(t.gun=o.gun),this.to.next(t),n=t.get){if(n["#"]||o.soul){if(n["#"]=n["#"]||o.soul,t["#"]||(t["#"]=m(9)),e=i.gun.get(n["#"])._,n=n["."]){if(h(e.put,n))return void e.on("in",{gun:e.gun,put:c.state.to(e.put,n),get:e.get})}else{if(h(e,"put")&&e.on("in",e),e.ack)return;t.gun=e.gun,e.ack=-1}return i.ask(f,t),i.on("in",t)}if(i.now&&(i.now[o.id]=i.now[o.id]||!0),n["."])return o.get?(t={get:{".":o.get},gun:o.gun},(e.ask||(e.ask={}))[o.get]=t.gun._,e.on("out",t)):(t={get:{},gun:o.gun},e.on("out",t));if(o.ack=o.ack||-1,o.get)return t.gun=o.gun,n["."]=o.get,(e.ask||(e.ask={}))[o.get]=t.gun._,e.on("out",t)}return e.on("out",t)}function o(t){var n,o=this,r=this.as,s=t.gun,f=s._,p=t.put;if(r.get&&t.get!==r.get&&(t=v(t,{get:r.get})),r.has&&f!==r&&(t=v(t,{gun:r.gun}),f.ack&&(r.ack=f.ack)),y===r.get&&p&&p["#"]&&(r._id=p["#"]),l===p){if(o.to.next(t),r.soul)return;return i(r,t,o),r.has&&a(r,t),d(f.echo,r.id),void d(r.map,f.id)}return r.soul?(o.to.next(t),i(r,t,o),void b(p,u,{at:t,cat:r})):(n=c.val.rel.is(p))?(e(r,t,f,n),o.to.next(t),void i(r,t,o)):c.val.is(p)?(r.has||r.soul?a(r,t):(f.has||f.soul)&&((f.echo||(f.echo={}))[r.id]=r,(r.map||(r.map={}))[f.id]=r.map[f.id]||{at:f}),o.to.next(t),void i(r,t,o)):(r.has&&f!==r&&h(f,"put")&&(r.put=f.put),(n=c.node.soul(p))&&f.has&&(f.put=r.root.gun.get(n)._.put),o.to.next(t),i(r,t,o),e(r,t,f,n),void b(p,u,{at:t,cat:r}))}function e(t,n,o,i){if(i&&y!==t.get){var r=t.root.gun.get(i)._;if(t.has?o=r:o.has&&e(o,n,o,i),o!==t){(o.echo||(o.echo={}))[t.id]=t,t.has&&!(t.map||p)[o.id]&&a(t,n),r=(t.map||(t.map={}))[o.id]=t.map[o.id]||{at:o};var u=t.root.now;if(i===r.rel){if(!u)return;if(l===u[t.id])return;if((u._||(u._={}))[t.id]===i)return;u._[t.id]=i}s(t,r.rel=i)}}}function i(t,n,o){t.echo&&(t.has&&(n=v(n,{event:o})),b(t.echo,r,n))}function r(t){t.on("in",this)}function u(t,n){var o,e,i=this.cat,r=i.next||p,u=this.at;(y!==n||r[n])&&(e=r[n])&&(e.has?(t&&t[_]&&c.val.rel.is(t)===c.node.soul(e.put)||(e.put=t),o=e.gun):o=u.gun.get(n),e.on("in",{put:t,get:n,gun:o,via:u}))}function a(t,n){if(t.has||t.soul){var o=t.map,e=t.root;t.map=null,(e.now&&e.now[t.id]||n["@"]||null!==o)&&(l===o&&c.val.rel.is(t.put)||(b(o,function(n){(n=n.at)&&d(n.echo,t.id)}),b(t.next,function(t,n){t.put=l,t.ack&&(t.ack=-1),t.on("in",{get:n,gun:t.gun,put:l})})))}}function s(t,n){var o=t.root.gun.get(n)._;(!t.ack||(o.on("out",{get:{"#":n}}),t.ask))&&(b(t.ask||t.next,function(t,o){t.on("out",{get:{"#":n,".":o}})}),c.obj.del(t,"ask"))}function f(t){var n=this.as,o=n.get||p,e=n.gun._,i=(t.put||p)[o["#"]];if(e.ack&&(e.ack=e.ack+1||1),!t.put||o["."]&&!h(i,e.get)){if(e.put!==l)return;return void e.on("in",{get:e.get,put:e.put=l,gun:e.gun,"@":t["@"]})}return y==o["."]?void e.on("in",{get:e.get,put:i[e.get],gun:e.gun,"@":t["@"]}):(t.gun=e.root.gun,void c.on.put(t,e.root.gun))}var c=t("./root");c.chain.chain=function(){var t,e=this._,i=new this.constructor(this),r=i._;return r.root=t=e.root,r.id=++t.once,r.back=this._,r.on=c.on,r.on("in",o,r),r.on("out",n,r),i};var l,p={},g=c.obj,h=g.has,d=(g.put,g.del),v=g.to,b=g.map,m=c.text.random,_=c.val.rel._,y=c.node._})(t,"./chain"),t(function(){function n(t,n){var o=n._,e=o.next,i=n.chain(),r=i._;return e||(e=o.next={}),e[r.get=t]=r,n===o.root.gun?r.soul=t:(o.soul||o.has)&&(r.has=t),r}function o(t){var n,o=this,e=o.as,r=t.gun,a=r._,f=a.root,c=t.put;return(n=f.now)&&o!==n[e.now]?o.to.next(t):(i===c&&(c=a.put),(n=c)&&n[s._]&&(n=s.is(n))&&(n=a.root.gun.get(n)._,i!==n.put&&(t=u(t,{put:n.put}))),e.use(t,t.event||o),void o.to.next(t))}var e=t("./root");e.chain.get=function(t,i,r){var u;if("string"!=typeof t){if(t instanceof Function){u=this;var s,c=u._,l=c.root,p=l.now;return r=i||{},r.use=t,r.out=r.out||{},r.out.get=r.out.get||{},s=c.on("in",o,r),(l.now={$:1})[r.now=c.id]=s,c.on("out",r.out),l.now=p,u}return a(t)?this.get(""+t,i,r):((r=this.chain())._.err={err:e.log("Invalid get request!",t)},i&&i.call(r,r._.err),r)}var p,g=this,h=g._,d=h.next||f;return(u=d[t])||(u=n(t,g)),u=u.gun,(p=h.stun)&&(u._.stun=u._.stun||p),i&&i instanceof Function&&u.get(i,r),u};var i,r=e.obj,u=(r.has,e.obj.to),a=e.num.is,s=e.val.rel,f=(e.node._,{})})(t,"./get"),t(function(){function n(t){t.batch=i;var n=t.opt||{},o=t.env=c.state.map(u,n.state);return o.soul=t.soul,t.graph=c.graph.ify(t.data,o,t),o.err?((t.ack||b).call(t,t.out={err:c.log(o.err)}),void(t.res&&t.res())):void t.batch()}function e(t){return void(t&&t())}function i(){var t=this;t.graph&&!d(t.stun,r)&&(t.res=t.res||function(t){t&&t()},t.res(function(){var n=t.gun.back(-1)._,o=n.ask(function(n){this.off(),t.ack&&t.ack(n,this)},t.opt),e=n.root.now;p.del(n.root,"now"),n.root.PUT=!0;var i=n.root.stop;t.ref._.now=!0,t.ref._.on("out",{gun:t.ref,put:t.out=t.env.graph,opt:t.opt,"#":o}),p.del(t.ref._,"now"),p.del(n.root,"PUT"),n.root.now=e,n.root.stop=i},t),t.res&&t.res())}function r(t){return t?!0:void 0}function u(t,n,o,e){var i=this;!n&&e.path.length&&(i.res||m)(function(){var t=e.path,n=i.ref,o=(i.opt,0),r=t.length;for(o;r>o;o++)n=n.get(t[o]);if(c.node.soul(e.obj)){var u=c.node.soul(e.obj)||(n.back("opt.uuid")||c.text.random)();return u?(n.back(-1).get(u),void e.soul(u)):((i.stun=i.stun||{})[t]=!0,void n.back("opt.uuid")(function(o,r){return o?c.log(o):(n.back(-1).get(r),e.soul(r),i.stun[t]=!1,void i.batch())}))}(i.stun=i.stun||{})[t]=!0,n.get("_").get(a,{as:{at:e,as:i}})},{as:i,at:e})}function a(t,n){var o=this.as,e=o.at;if(o=o.as,t.gun&&t.gun._.back){var i=t.gun._,r=i,u=(t.put||v)["#"];n.off(),i=t.gun._.back;var a=a||c.node.soul(e.obj)||c.node.soul(i.put)||c.val.rel.is(i.put)||u||r._id||(o.gun.back("opt.uuid")||c.text.random)();return a?void s(i,r._id=r._id||a,e,o):void i.gun.back("opt.uuid")(function(t,n){return t?c.log(t):void s(i,r._id=r._id||n,e,o)})}}function s(t,n,o,e){t.gun.back(-1).get(n),o.soul(n),e.stun[o.path]=!1,e.batch()}function f(t,n){var e=this.as;if(t.gun&&t.gun._){if(t.err)return void o.log("Please report this as an issue! Put.any.err");var i,r=t.gun._.back,u=r.put,a=e.opt||{};if(!(i=e.ref)||!i._.now){if(n.off(),e.ref!==e.gun){if(i=e.gun._.get||r.get,!i)return void o.log("Please report this as an issue! Put.no.get");e.data=h({},i,e.data),i=null}if(l===u){if(!r.get)return;r.soul||(i=r.gun.back(function(t){return t.soul?t.soul:void(e.data=h({},t.get,e.data))})),i=i||r.get,r=r.root.gun.get(i)._,e.not=e.soul=i,u=e.data}return e.not||(e.soul=c.node.soul(u))||(e.path&&g(e.data)?e.soul=(a.uuid||r.root.opt.uuid||c.text.random)():(_==t.get&&(e.soul=(t.put||v)["#"]||t._id),e.soul=e.soul||t.soul||r.soul||(a.uuid||r.root.opt.uuid||c.text.random)()),e.soul)?void e.ref.put(e.data,e.soul,e):void e.ref.back("opt.uuid")(function(t,n){return t?c.log(t):void e.ref.put(e.data,e.soul=n,e)})}}}var c=t("./root");c.chain.put=function(t,o,i){var r,u=this,a=u._,s=a.root.gun;return i=i||{},i.data=t,i.gun=i.gun||u,"string"==typeof o?i.soul=o:i.ack=o,a.soul&&(i.soul=a.soul),i.soul||s===u?g(i.data)?(i.soul=i.soul||(i.not=c.node.soul(i.data)||(s._.opt.uuid||c.text.random)()),i.soul?(i.gun=u=s.get(i.soul),i.ref=i.gun,n(i),u):(s._.opt.uuid(function(t,n){return t?c.log(t):void(i.ref||i.gun).put(i.data,i.soul=n,i)}),u)):((i.ack||b).call(i,i.out={err:c.log("Data saved to the root level of the graph must be a node (an object), not a",typeof i.data,'of "'+i.data+'"!')}),i.res&&i.res(),u):c.is(t)?(t.get("_").get(function(t,n,e){return n.off(),(e=t.gun)&&(e=e._.back)&&e.soul?void u.put(c.val.rel.ify(e.soul),o,i):c.log("The reference you are saving is a",typeof t.put,'"'+i.put+'", not a node (object)!')}),u):(i.ref=i.ref||s._===(r=a.back)?u:r.gun,i.ref._.soul&&c.val.is(i.data)&&a.get?(i.data=h({},a.get,i.data),i.ref.put(i.data,i.soul,i),u):(i.ref.get("_").get(f,{as:i}),i.out||(i.res=i.res||e,i.gun._.stun=i.ref._.stun),u))};var l,p=c.obj,g=p.is,h=p.put,d=p.map,v={},b=function(){},m=function(t,n){t.call(n||v)},_=c.node._})(t,"./put"),t(function(n){var o=t("./root");t("./chain"),t("./back"),t("./put"),t("./get"),n.exports=o})(t,"./index"),t(function(){function n(t,n){var o,r=this,u=t.gun,a=u._,f=a.put||t.put,o=r.last,c=a.id+t.get;if(i!==f){if(f&&f[s._]&&(o=s.is(f))){if(o=a.root.gun.get(o)._,i===o.put)return;f=o.put}r.change&&(f=t.put),(o.put!==f||o.get!==c||e.node.soul(f))&&(o.put=f,o.get=c,a.last=f,r.as?r.ok.call(r.as,t,n):r.ok.call(u,f,t.get,t,n))}}function o(t,n,r){var u,a=this.as,f=a.cat,c=t.gun,l=c._,p=l.put||t.put;if(u=e.node.soul(p)||s.is(p)){if(u=f.root.gun.get(u)._,i===u.put)return;p=u.put}if(n.wait&&clearTimeout(n.wait),!r)return void(n.wait=setTimeout(function(){o.call({as:a},t,n,n.wait||1)},a.wait||99));if(f.has||f.soul){if(n.off())return}else{if((a.seen=a.seen||{})[l.id])return;a.seen[l.id]=!0}a.ok.call(t.gun||a.gun,p,t.get)}var e=t("./index");e.chain.on=function(t,o,e,i){var r,u,a=this,s=a._;if("string"==typeof t)return o?(r=s.on(t,o,e||s,i),e&&e.gun&&(e.subs||(e.subs=[])).push(r),u=function(){r&&r.off&&r.off(),u.off()},u.off=a.off.bind(a)||f,a.off=u,a):s.on(t);var c=o;return c=!0===c?{change:!0}:c||{},c.ok=t,c.last={},a.get(n,c),a},e.chain.val=function(t,n){return e.log.once("onceval","Future Breaking API Change: .val -> .once, apologies unexpected."),this.once(t,n)},e.chain.once=function(t,n){var r=this,u=r._,a=u.put;if(0=(n.batch||1e3)?s():void(e||(e=setTimeout(s,n.wait||1)))}),t.on("get",function(o){this.to.next(o);var e,i,r,a=o.get;if(a&&(e=a["#"])){var s=a["."];i=u[e]||r,i&&s&&(i=Gun.state.to(i,s)),(i||Gun.obj.empty(n.peers))&&t.on("in",{"@":o["#"],put:Gun.graph.node(i),how:"lS"})}});var a=function(t,n,o,e){u[e]=Gun.state.to(o,n,u[e])},s=function(){var a;r=0,clearTimeout(e),e=!1;var s=i;i={};try{o.setItem(n.file,JSON.stringify(u))}catch(f){Gun.log(a=f||"localStorage failure")}(a||Gun.obj.empty(n.peers))&&Gun.obj.map(s,function(n,o){t.on("in",{"@":o,err:a,ok:0})})}}})}})(t,"./adapters/localStorage"),t(function(n){function o(t){var n=function(){};return n.out=function(o){var e;return this.to&&this.to.next(o),(e=o["@"])&&(e=t.dup.s[e])&&(e=e.it)&&e.mesh?(n.say(o,e.mesh.via),void(e["##"]=o["##"])):void n.say(o)},n.hear=function(o,i){if(o){var r,u,a=t.dup,s=o[0];try{o=JSON.parse(o)}catch(f){}if("{"===s){if(a.check(r=o["#"]))return;if(a.track(r,!0).it=o,(s=o["@"])&&o.put&&(u=o["##"]||(o["##"]=n.hash(o)),(s+=u)!=r)){if(a.check(s))return;(s=a.s)[u]=s[r]}return(o.mesh=function(){}).via=i,(s=o["><"])&&(o.mesh.to=e.obj.map(s.split(","),function(t,n,o){o(t,!0)})),void t.on("in",o)}if("["!==s);else for(var c,l=0;c=o[l++];)n.hear(c,i)}},function(){function o(t,n){var o=n.wire;try{o.send?o.readyState===o.OPEN?o.send(t):(n.queue=n.queue||[]).push(t):n.say&&n.say(t)}catch(e){(n.queue=n.queue||[]).push(t)}}n.say=function(i,u){if(!u)return void e.obj.map(t.opt.peers,function(t){n.say(i,t)});var a,s,f,c=u.wire||t.opt.wire&&t.opt.wire(u);if(c&&(s=i.mesh||r,u!==s.via&&((f=s.raw)||(f=n.raw(i)),!((a=i["@"])&&(a=t.dup.s[a])&&(a=a.it)&&a.get&&a["##"]&&a["##"]===i["##"]||(a=s.to)&&(a[u.url]||a[u.id]))))){if(u.batch)return void u.batch.push(f);u.batch=[],setTimeout(function(){var t=u.batch;t&&(u.batch=null,t.length&&o(JSON.stringify(t),u))},t.opt.wait||1),o(f,u)}}}(),function(){function r(t,n){var o;return n instanceof Object?(e.obj.map(Object.keys(n).sort(),u,{to:o={},on:n}),o):n}function u(t){this.to[t]=this.on[t]}n.raw=function(o){if(!o)return"";var u,f,c,l=t.dup,p=o.mesh||{};if(c=p.raw)return c;if("string"==typeof o)return o;o["@"]&&(c=o.put)&&((f=o["##"])||(u=a(c,r)||"",f=n.hash(o,u),o["##"]=f),(c=l.s)[f=o["@"]+f]=c[o["#"]],o["#"]=f,u&&((o=e.obj.to(o)).put=s));var g=0,h=[];e.obj.map(t.opt.peers,function(t){return h.push(t.url||t.id),++g>9?!0:void 0}),o["><"]=h.join();var d=a(o);return i!==u&&(d=d.replace('"'+s+'"',u)),p&&(p.raw=d),d},n.hash=function(t,n){return o.hash(n||a(t.put,r)||"")||t["#"]||e.text.random(9)};var a=JSON.stringify,s=":])([:"}(),n.hi=function(o){t.on("hi",o);var i=o.queue;o.queue=[],e.obj.map(i,function(t){n.say(t,o)})},n}var e=t("./type");o.hash=function(t){if("string"!=typeof t)return{err:1};var n=0;if(!t.length)return n;for(var o,e=0,i=t.length;i>e;++e)o=t.charCodeAt(e),n=(n<<5)-n+o,n|=0;return n};var i,r={};Object.keys=Object.keys||function(t){return map(t,function(t,n,o){o(n)})};try{n.exports=o}catch(u){}})(t,"./adapters/mesh"),t(function(){var n=t("../index");n.Mesh=t("./mesh"),n.on("opt",function(t){function o(n){if(n&&n.url){var o=n.url.replace("http","ws"),r=n.wire=new i.WebSocket(o);return r.onclose=function(){t.on("bye",n),e(n)},r.onerror=function(t){e(n),t&&"ECONNREFUSED"===t.code},r.onopen=function(){a.hi(n)},r.onmessage=function(t){t&&a.hear(t.data||t,n)},r}}function e(t){clearTimeout(t.defer),t.defer=setTimeout(function(){o(t)},2e3)}this.to.next(t);var i=t.opt;if(!t.once&&!1!==i.WebSocket){var r;"undefined"!=typeof window&&(r=window),"undefined"!=typeof global&&(r=global),r=r||{};var u=i.WebSocket||r.WebSocket||r.webkitWebSocket||r.mozWebSocket;if(u){i.WebSocket=u;var a=i.mesh=i.mesh||n.Mesh(t);t.on("out",a.out),i.wire=i.wire||o}}})})(t,"./adapters/websocket")}(); \ No newline at end of file diff --git a/lib/erase.js b/lib/erase.js index 7f4d1a77..9fdf7222 100644 --- a/lib/erase.js +++ b/lib/erase.js @@ -1,4 +1,4 @@ -var Gun = Gun || require('gun'); +var Gun = Gun || require('../gun'); Gun.on('opt', function(ctx){ this.to.next(ctx); diff --git a/lib/forget.js b/lib/forget.js new file mode 100644 index 00000000..effd74db --- /dev/null +++ b/lib/forget.js @@ -0,0 +1,22 @@ +;(function(){ + + var Gun = (this||{}).Gun || require('../gun'); + + Gun.on('opt', function(ctx){ + once(ctx); + this.to.next(ctx); + }); + + function once(ctx){ + if(ctx.once){ return } + var forget = ctx.opt.forget = ctx.opt.forget || {}; + ctx.on('put', function(msg){ + Gun.graph.is(msg.put, function(node, soul){ + if(!Gun.obj.has(forget, soul)){ return } + delete msg.put[soul]; + }); + this.to.next(msg); + }); + } + +}()); \ No newline at end of file diff --git a/lib/set.js b/lib/set.js index 6c2596b3..47b0653c 100644 --- a/lib/set.js +++ b/lib/set.js @@ -23,7 +23,7 @@ Gun.chain.set = function(val, cb, opt){ cb = cb || function(){}; opt = opt || {}; - if(!gun.back){ gun = gun.put({}) } + if(!gun._.back){ gun = gun.put({}) } gun = gun.not(function(next, key){ return key? this.put({}).key(key) : this.put({}); }); diff --git a/lib/wsp/server.js b/lib/wsp/server.js index 6ef38671..c7fb528c 100644 --- a/lib/wsp/server.js +++ b/lib/wsp/server.js @@ -13,7 +13,7 @@ require('./client.js'); Gun.on('opt', function (at) { this.to.next(at); var gun = at.gun, opt = at.opt; - gun.__ = at.root._; + gun.__ = at.root; gun.__.opt.ws = opt.ws = gun.__.opt.ws || opt.ws || {}; gun.__.opt.ws.path = gun.__.opt.ws.path || '/gun'; @@ -181,7 +181,7 @@ Gun.on('opt', function (at) { headers: { 'Content-Type': tran.json }, }; - var graph = gun.Back(Infinity)._.graph; + var graph = gun.back(Infinity)._.graph; var node = graph[lex['#']]; var result = Gun.graph.ify(node); diff --git a/package.json b/package.json index 888c63e4..6c44e6cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gun", - "version": "0.9.98", + "version": "0.9.99", "description": "A realtime, decentralized, offline-first, graph data synchronization engine.", "main": "index.js", "browser": "gun.min.js", diff --git a/src/adapters/mesh.js b/src/adapters/mesh.js index 5c578482..49898c2f 100644 --- a/src/adapters/mesh.js +++ b/src/adapters/mesh.js @@ -131,7 +131,7 @@ function Mesh(ctx){ if(put){ (msg = Type.obj.to(msg)).put = _ } } var i = 0, to = []; Type.obj.map(ctx.opt.peers, function(p){ - to.push[p.url || p.id]; if(++i > 9){ return true } // limit server, fast fix, improve later! + to.push(p.url || p.id); if(++i > 9){ return true } // limit server, fast fix, improve later! }); msg['><'] = to.join(); var raw = $(msg); if(u !== put){ diff --git a/src/back.js b/src/back.js index 7e29c16c..8990a46d 100644 --- a/src/back.js +++ b/src/back.js @@ -3,10 +3,10 @@ var Gun = require('./root'); Gun.chain.back = function(n, opt){ var tmp; n = n || 1; if(-1 === n || Infinity === n){ - return this._.root; + return this._.root.gun; } else if(1 === n){ - return this._.back || this; + return (this._.back || this._).gun; } var gun = this, at = gun._; if(typeof n === 'string'){ @@ -21,19 +21,18 @@ Gun.chain.back = function(n, opt){ var tmp; return opt? gun : tmp; } else if((tmp = at.back)){ - return tmp.back(n, opt); + return tmp.gun.back(n, opt); } return; } if(n instanceof Function){ - var yes, tmp = {back: gun}; + var yes, tmp = {back: at}; while((tmp = tmp.back) - && (tmp = tmp._) && !(yes = n(tmp, opt))){} return yes; } if(Gun.num.is(n)){ - return at.back.back(n - 1); + return (at.back || at).gun.back(n - 1); } return this; } diff --git a/src/chain.js b/src/chain.js index 45019f4a..f28a297b 100644 --- a/src/chain.js +++ b/src/chain.js @@ -6,8 +6,8 @@ var Gun = require('./root'); Gun.chain.chain = function(){ var at = this._, chain = new this.constructor(this), cat = chain._, root; cat.root = root = at.root; - cat.id = ++root._.once; - cat.back = this; + cat.id = ++root.once; + cat.back = this._; cat.on = Gun.on; cat.on('in', input, cat); // For 'in' if I add my own listeners to each then I MUST do it before in gets called. If I listen globally for all incoming data instead though, regardless of individual listeners, I can transform the data there and then as well. cat.on('out', output, cat); // However for output, there isn't really the global option. I must listen by adding my own listener individually BEFORE this one is ever called. @@ -15,7 +15,7 @@ Gun.chain.chain = function(){ } function output(msg){ - var put, get, at = this.as, back = at.back._, root = at.root._; + var put, get, at = this.as, back = at.back, root = at.root; if(!msg.gun){ msg.gun = at.gun } this.to.next(msg); if(get = msg.get){ @@ -53,7 +53,7 @@ function output(msg){ if(get['.']){ if(at.get){ msg = {get: {'.': at.get}, gun: at.gun}; - (back.ask || (back.ask = {}))[at.get] = msg.gun; // TODO: PERFORMANCE? More elegant way? + (back.ask || (back.ask = {}))[at.get] = msg.gun._; // TODO: PERFORMANCE? More elegant way? return back.on('out', msg); } msg = {get: {}, gun: at.gun}; @@ -63,7 +63,7 @@ function output(msg){ if(at.get){ msg.gun = at.gun; get['.'] = at.get; - (back.ask || (back.ask = {}))[at.get] = msg.gun; // TODO: PERFORMANCE? More elegant way? + (back.ask || (back.ask = {}))[at.get] = msg.gun._; // TODO: PERFORMANCE? More elegant way? return back.on('out', msg); } } @@ -121,7 +121,7 @@ function input(msg){ cat.put = at.put; }; if((rel = Gun.node.soul(change)) && at.has){ - at.put = (cat.root.get(rel)._).put; + at.put = (cat.root.gun.get(rel)._).put; } ev.to.next(msg); echo(cat, msg, ev); @@ -136,7 +136,7 @@ function input(msg){ function relate(at, msg, from, rel){ if(!rel || node_ === at.get){ return } - var tmp = (at.root.get(rel)._); + var tmp = (at.root.gun.get(rel)._); if(at.has){ from = tmp; } else @@ -149,8 +149,8 @@ function relate(at, msg, from, rel){ not(at, msg); } tmp = (at.map || (at.map = {}))[from.id] = at.map[from.id] || {at: from}; - var now = at.root._.now; - //now = now || at.root._.stop; + var now = at.root.now; + //now = now || at.root.stop; if(rel === tmp.rel){ // NOW is a hack to get synchronous replies to correctly call. // and STOP is a hack to get async behavior to correctly call. @@ -158,7 +158,7 @@ function relate(at, msg, from, rel){ // but for now, this works for current tests. :/ if(!now){ return; - /*var stop = at.root._.stop; + /*var stop = at.root.stop; if(!stop){ return } if(stop[at.id] === rel){ return } stop[at.id] = rel;*/ @@ -179,20 +179,19 @@ function reverb(to){ to.on('in', this); } function map(data, key){ // Map over only the changes on every update. - var cat = this.cat, next = cat.next || empty, via = this.at, gun, chain, at, tmp; + var cat = this.cat, next = cat.next || empty, via = this.at, chain, at, tmp; if(node_ === key && !next[key]){ return } - if(!(gun = next[key])){ + if(!(at = next[key])){ return; } - at = (gun._); - //if(data && data[_soul] && (tmp = Gun.val.rel.is(data)) && (tmp = (cat.root.get(tmp)._)) && obj_has(tmp, 'put')){ + //if(data && data[_soul] && (tmp = Gun.val.rel.is(data)) && (tmp = (cat.root.gun.get(tmp)._)) && obj_has(tmp, 'put')){ // data = tmp.put; //} if(at.has){ if(!(data && data[_soul] && Gun.val.rel.is(data) === Gun.node.soul(at.put))){ at.put = data; } - chain = gun; + chain = at.gun; } else { chain = via.gun.get(key); } @@ -205,7 +204,7 @@ function map(data, key){ // Map over only the changes on every update. } function not(at, msg){ if(!(at.has || at.soul)){ return } - var tmp = at.map, root = at.root._; + var tmp = at.map, root = at.root; at.map = null; if(!root.now || !root.now[at.id]){ if((!msg['@']) && null === tmp){ return } @@ -215,29 +214,28 @@ function not(at, msg){ if(!(proxy = proxy.at)){ return } obj_del(proxy.echo, at.id); }); - obj_map(at.next, function(gun, key){ - var coat = (gun._); - coat.put = u; - if(coat.ack){ - coat.ack = -1; + obj_map(at.next, function(neat, key){ + neat.put = u; + if(neat.ack){ + neat.ack = -1; } - coat.on('in', { + neat.on('in', { get: key, - gun: gun, + gun: neat.gun, put: u }); }); } function ask(at, soul){ - var tmp = (at.root.get(soul)._); + var tmp = (at.root.gun.get(soul)._); if(at.ack){ tmp.on('out', {get: {'#': soul}}); if(!at.ask){ return } // TODO: PERFORMANCE? More elegant way? } - obj_map(at.ask || at.next, function(gun, key){ + obj_map(at.ask || at.next, function(neat, key){ //(tmp.gun.get(key)._).on('out', {get: {'#': soul, '.': key}}); //tmp.on('out', {get: {'#': soul, '.': key}}); - (gun._).on('out', {get: {'#': soul, '.': key}}); + neat.on('out', {get: {'#': soul, '.': key}}); //at.on('out', {get: {'#': soul, '.': key}}); }); Gun.obj.del(at, 'ask'); // TODO: PERFORMANCE? More elegant way? @@ -262,9 +260,9 @@ function ack(msg, ev){ } //if(/*!msg.gun &&*/ !get['.'] && get['#']){ at.ack = (at.ack + 1) || 1 } //msg = obj_to(msg); - msg.gun = at.root; + msg.gun = at.root.gun; //Gun.on('put', at); - Gun.on.put(msg, at.root); + Gun.on.put(msg, at.root.gun); } var empty = {}, u; var obj = Gun.obj, obj_has = obj.has, obj_put = obj.put, obj_del = obj.del, obj_to = obj.to, obj_map = obj.map; diff --git a/src/get.js b/src/get.js index 69c73a91..a002c987 100644 --- a/src/get.js +++ b/src/get.js @@ -1,15 +1,18 @@ var Gun = require('./root'); Gun.chain.get = function(key, cb, as){ + var gun; if(typeof key === 'string'){ - var gun, back = this, cat = back._; + var back = this, cat = back._; var next = cat.next || empty, tmp; if(!(gun = next[key])){ gun = cache(key, back); } + gun = gun.gun; } else if(key instanceof Function){ - var gun = this, at = gun._, root = at.root._, tmp = root.now, ev; + gun = this; + var at = gun._, root = at.root, tmp = root.now, ev; as = cb || {}; as.use = key; as.out = as.out || {}; @@ -38,8 +41,8 @@ Gun.chain.get = function(key, cb, as){ function cache(key, back){ var cat = back._, next = cat.next, gun = back.chain(), at = gun._; if(!next){ next = cat.next = {} } - next[at.get = key] = gun; - if(cat.root === back){ + next[at.get = key] = at; + if(back === cat.root.gun){ at.soul = key; } else if(cat.soul || cat.has){ @@ -48,10 +51,10 @@ function cache(key, back){ //at.put = cat.put[key]; //} } - return gun; + return at; } function use(msg){ - var ev = this, as = ev.as, gun = msg.gun, at = gun._, root = at.root._, data = msg.put, tmp; + var ev = this, as = ev.as, gun = msg.gun, at = gun._, root = at.root, data = msg.put, tmp; if((tmp = root.now) && ev !== tmp[as.now]){ return ev.to.next(msg); } @@ -59,7 +62,7 @@ function use(msg){ data = at.put; } if((tmp = data) && tmp[rel._] && (tmp = rel.is(tmp))){ - tmp = (at.root.get(tmp)._); + tmp = (at.root.gun.get(tmp)._); if(u !== tmp.put){ msg = obj_to(msg, {put: tmp.put}); } diff --git a/src/on.js b/src/on.js index 4b76dbbc..d153bfb5 100644 --- a/src/on.js +++ b/src/on.js @@ -30,7 +30,7 @@ function ok(at, ev){ var opt = this; return; } if(data && data[rel._] && (tmp = rel.is(data))){ - tmp = (cat.root.get(tmp)._); + tmp = (cat.root.gun.get(tmp)._); if(u === tmp.put){ return; } @@ -87,7 +87,7 @@ function val(msg, ev, to){ //if(coat.soul && !(0 < coat.ack)){ return } if(tmp = Gun.node.soul(data) || rel.is(data)){ //if(data && data[rel._] && (tmp = rel.is(data))){ - tmp = (cat.root.get(tmp)._); + tmp = (cat.root.gun.get(tmp)._); if(u === tmp.put){//} || !(0 < tmp.ack)){ return; } @@ -113,7 +113,7 @@ function val(msg, ev, to){ Gun.chain.off = function(){ // make off more aggressive. Warning, it might backfire! var gun = this, at = gun._, tmp; - var back = at.back || {}, cat = back._; + var cat = at.back; if(!cat){ return } if(tmp = cat.next){ if(tmp[at.get]){ @@ -129,18 +129,18 @@ Gun.chain.off = function(){ obj_del(tmp, at.get); } if(tmp = at.soul){ - obj_del(cat.root._.graph, tmp); + obj_del(cat.root.graph, tmp); } if(tmp = at.map){ obj_map(tmp, function(at){ if(at.rel){ - cat.root.get(at.rel).off(); + cat.root.gun.get(at.rel).off(); } }); } if(tmp = at.next){ - obj_map(tmp, function(ref){ - ref.off(); + obj_map(tmp, function(neat){ + neat.gun.off(); }); } at.on('off', {}); diff --git a/src/put.js b/src/put.js index b90bec76..a541aeb8 100644 --- a/src/put.js +++ b/src/put.js @@ -4,7 +4,7 @@ Gun.chain.put = function(data, cb, as){ // #soul.has=value>state // ~who#where.where=what>when@was // TODO: BUG! Put probably cannot handle plural chains! - var gun = this, at = (gun._), root = at.root, tmp; + var gun = this, at = (gun._), root = at.root.gun, tmp; as = as || {}; as.data = data; as.gun = as.gun || gun; @@ -37,14 +37,14 @@ Gun.chain.put = function(data, cb, as){ } if(Gun.is(data)){ data.get('_').get(function(at, ev, tmp){ ev.off(); - if(!(tmp = at.gun) || !(tmp = tmp._.back) || !tmp._.soul){ + if(!(tmp = at.gun) || !(tmp = tmp._.back) || !tmp.soul){ return Gun.log("The reference you are saving is a", typeof at.put, '"'+ as.put +'", not a node (object)!'); } - gun.put(Gun.val.rel.ify(tmp._.soul), cb, as); + gun.put(Gun.val.rel.ify(tmp.soul), cb, as); }); return gun; } - as.ref = as.ref || (root === (tmp = at.back))? gun : tmp; + as.ref = as.ref || (root._ === (tmp = at.back))? gun : tmp.gun; if(as.ref._.soul && Gun.val.is(as.data) && at.get){ as.data = obj_put({}, at.get, as.data); as.ref.put(as.data, as.soul, as); @@ -101,16 +101,16 @@ function batch(){ var as = this; // and STOP is a hack to get async behavior to correctly call. // neither of these are ideal, need to be fixed without hacks, // but for now, this works for current tests. :/ - var tmp = cat.root._.now; obj.del(cat.root._, 'now'); cat.root._.PUT = true; - var tmp2 = cat.root._.stop; + var tmp = cat.root.now; obj.del(cat.root, 'now'); cat.root.PUT = true; + var tmp2 = cat.root.stop; (as.ref._).now = true; (as.ref._).on('out', { gun: as.ref, put: as.out = as.env.graph, opt: as.opt, '#': ask }); obj.del((as.ref._), 'now'); - obj.del((cat.root._), 'PUT'); - cat.root._.now = tmp; - cat.root._.stop = tmp2; + obj.del((cat.root), 'PUT'); + cat.root.now = tmp; + cat.root.stop = tmp2; }, as); if(as.res){ as.res() } } function no(v,k){ if(v){ return true } } @@ -151,7 +151,7 @@ function soul(msg, ev){ var as = this.as, cat = as.at; as = as.as; var at = msg.gun._, at_ = at; var _id = (msg.put||empty)['#']; ev.off(); - at = (msg.gun._.back._); // go up 1! + at = (msg.gun._.back); // go up 1! var id = id || Gun.node.soul(cat.obj) || Gun.node.soul(at.put) || Gun.val.rel.is(at.put) || _id || at_._id || (as.gun.back('opt.uuid') || Gun.text.random)(); // TODO: BUG!? Do we really want the soul of the object given to us? Could that be dangerous? if(!id){ // polyfill async uuid for SEA at.gun.back('opt.uuid')(function(err, id){ // TODO: improve perf without anonymous callback @@ -177,7 +177,7 @@ function any(at, ev){ console.log("Please report this as an issue! Put.any.err"); return; } - var cat = (at.gun._.back._), data = cat.put, opt = as.opt||{}, root, tmp; + var cat = (at.gun._.back), data = cat.put, opt = as.opt||{}, root, tmp; if((tmp = as.ref) && tmp._.now){ return } ev.off(); if(as.ref !== as.gun){ @@ -198,19 +198,19 @@ function any(at, ev){ }); } tmp = tmp || cat.get; - cat = (cat.root.get(tmp)._); + cat = (cat.root.gun.get(tmp)._); as.not = as.soul = tmp; data = as.data; } if(!as.not && !(as.soul = Gun.node.soul(data))){ if(as.path && obj_is(as.data)){ // Apparently necessary - as.soul = (opt.uuid || cat.root._.opt.uuid || Gun.text.random)(); + as.soul = (opt.uuid || cat.root.opt.uuid || Gun.text.random)(); } else { //as.data = obj_put({}, as.gun._.get, as.data); if(node_ == at.get){ as.soul = (at.put||empty)['#'] || at._id; } - as.soul = as.soul || at.soul || cat.soul || (opt.uuid || cat.root._.opt.uuid || Gun.text.random)(); + as.soul = as.soul || at.soul || cat.soul || (opt.uuid || cat.root.opt.uuid || Gun.text.random)(); } if(!as.soul){ // polyfill async uuid for SEA as.ref.back('opt.uuid')(function(err, soul){ // TODO: improve perf without anonymous callback diff --git a/src/root.js b/src/root.js index ef1eea78..5e0201d9 100644 --- a/src/root.js +++ b/src/root.js @@ -26,7 +26,7 @@ Gun.dup = require('./dup'); ;(function(){ Gun.create = function(at){ - at.root = at.root || at.gun; + at.root = at.root || at; at.graph = at.graph || {}; at.on = at.on || Gun.on; at.ask = at.ask || Gun.ask; @@ -103,7 +103,7 @@ Gun.dup = require('./dup'); var msg = ctx.map[soul] = { put: node, get: soul, - gun: at + gun: at.gun }, as = {ctx: ctx, msg: msg}; ctx.async = !!cat.tag.node; if(ctx.ack){ msg['@'] = ctx.ack } @@ -144,7 +144,7 @@ Gun.dup = require('./dup'); Gun.on.get = function(msg, gun){ var root = gun._, soul = msg.get[_soul], node = root.graph[soul], has = msg.get[_has], tmp; - var next = root.next || (root.next = {}), at = ((next[soul] || empty)._); + var next = root.next || (root.next = {}), at = next[soul]; if(!node || !at){ return root.on('get', msg) } if(has){ if(!obj_has(node, has)){ return root.on('get', msg) } diff --git a/src/set.js b/src/set.js index aaa5e5e6..995202bc 100644 --- a/src/set.js +++ b/src/set.js @@ -6,9 +6,9 @@ Gun.chain.set = function(item, cb, opt){ opt = opt || {}; opt.item = opt.item || item; if(soul = Gun.node.soul(item)){ return gun.set(gun.back(-1).get(soul), cb, opt) } if(!Gun.is(item)){ - var id = gun._.root._.opt.uuid(); + var id = gun._.root.opt.uuid(); if(id && Gun.obj.is(item)){ - return gun.set(gun._.root.put(item, id), cb, opt); + return gun.set(gun._.root.gun.put(item, id), cb, opt); } return gun.get(id || (Gun.state.lex() + Gun.text.random(12))).put(item, cb, opt); } @@ -16,7 +16,7 @@ Gun.chain.set = function(item, cb, opt){ if(!at.gun || !at.gun._.back){ return } ev.off(); var soul = (at.put||{})['#']; - at = (at.gun._.back._); + at = (at.gun._.back); var put = {}, node = at.put; soul = at.soul || Gun.node.soul(node) || soul; if(!soul){ return cb.call(gun, {err: Gun.log('Only a node can be linked! Not "' + node + '"!')}) } diff --git a/test/common.js b/test/common.js index 72345f97..971bd745 100644 --- a/test/common.js +++ b/test/common.js @@ -3136,7 +3136,6 @@ describe('Gun', function(){ //return; setTimeout(function(){ gun.get(function(at){ - //console.log('*', at.put); done.app = done.app || at.put.alias; }); gun.back(-1).get('pub').get(function(at){ @@ -3611,7 +3610,7 @@ describe('Gun', function(){ }); gun.get('ds/safe').val(function(data){ - expect(gun._.root._.graph['ds/safe'].b).to.not.be.ok(); + expect(gun.back(-1)._.graph['ds/safe'].b).to.not.be.ok(); if(done.c){ return } done.c = 1; done(); }); @@ -3695,7 +3694,7 @@ describe('Gun', function(){ }); it('users map map who said map on', function(done){ - this.timeout(1000 * 60 * 5); + this.timeout(1000 * 9); var gun = Gun(); gun.get('users').put({ @@ -4607,7 +4606,7 @@ describe('Gun', function(){ gun.get('hello/earth').key('hello/galaxy', function(err, ok){ expect(err).to.not.be.ok(); }); - var node = gun.Back(-1)._.graph['hello/earth'] || {}; // TODO: IS THIS CORRECT? + var node = gun.back(-1)._.graph['hello/earth'] || {}; // TODO: IS THIS CORRECT? expect(node['hello/galaxy']).to.not.be.ok(); gun.get('hello/earth', function(err, pseudo){ expect(pseudo.hello).to.be('world'); @@ -4615,7 +4614,7 @@ describe('Gun', function(){ expect(pseudo.place).to.be('asia'); expect(pseudo.north).to.not.be.ok(); }); - var galaxy = gun.Back(-1)._.graph['hello/galaxy'] || {}; // TODO: IS THIS CORRECT? + var galaxy = gun.back(-1)._.graph['hello/galaxy'] || {}; // TODO: IS THIS CORRECT? expect(galaxy['hello/earth']).to.not.be.ok(); gun.get('hello/galaxy', function(err, pseudo){ if(done.c || !pseudo.hello || !pseudo.south || !pseudo.place || !pseudo.continent || !pseudo.north){ return } @@ -4635,9 +4634,9 @@ describe('Gun', function(){ kn = Gun.obj.copy(kn); delete kn._; expect(Gun.obj.empty(kn, '##')).to.be.ok(); - kn = gun.Back(-1)._.graph[Gun.val.rel.is(kn['##'])]; + kn = gun.back(-1)._.graph[Gun.val.rel.is(kn['##'])]; Gun.node.is(kn, function(node, s){ - var n = gun.Back(-1)._.graph[s]; + var n = gun.back(-1)._.graph[s]; if(Gun.obj.has(n, '##')){ soulnode(gun, n, r); return; @@ -4655,11 +4654,11 @@ describe('Gun', function(){ done.soul = Gun.node.soul(node); }).put({hi: 'you'}, function(err, ok){ expect(err).to.not.be.ok(); - var keynode = gun.Back(-1)._.graph[done.soul], soul; + var keynode = gun.back(-1)._.graph[done.soul], soul; expect(keynode.hi).to.not.be.ok(); var c = soulnode(gun, keynode), soul = c[0]; expect(c.length).to.be(1); - var node = gun.Back(-1)._.graph[soul]; + var node = gun.back(-1)._.graph[soul]; expect(node.hello).to.be('key'); expect(node.hi).to.be('you'); }).on(function(node){ @@ -4713,10 +4712,10 @@ describe('Gun', function(){ }).put({hi: 'overwritten'}, function(err, ok){ if(done.c){ return } expect(err).to.not.be.ok(); - var keynode = gun.Back(-1)._.graph[done.soul], soul; + var keynode = gun.back(-1)._.graph[done.soul], soul; var c = soulnode(gun, keynode), soul = c[0]; expect(c.length).to.be(1); - var node = gun.Back(-1)._.graph[soul]; + var node = gun.back(-1)._.graph[soul]; expect(node.hello).to.be('key'); expect(node.hi).to.be('overwritten'); done.w = 1; if(done.r){ done(); done.c = 1 }; @@ -4804,10 +4803,10 @@ describe('Gun', function(){ }).path('hi').put('again', function(err, ok){ if(done.c){ return } expect(err).to.not.be.ok(); - var keynode = gun.Back(-1)._.graph[done.soul], soul; + var keynode = gun.back(-1)._.graph[done.soul], soul; var c = soulnode(gun, keynode), soul = c[0]; expect(c.length).to.be(1); - var node = gun.Back(-1)._.graph[done.sub = soul]; + var node = gun.back(-1)._.graph[done.sub = soul]; expect(node.hello).to.be('key'); expect(node.hi).to.be('again'); done.w = 1; if(done.r){ done(); done.c = 1 }; @@ -4829,15 +4828,15 @@ describe('Gun', function(){ }).path('hi').put({yay: "value"}, function(err, ok){ if(done.c){ return } expect(err).to.not.be.ok(); - var keynode = gun.Back(-1)._.graph[done.soul], soul; + var keynode = gun.back(-1)._.graph[done.soul], soul; var c = soulnode(gun, keynode), soul = c[0]; expect(c.length).to.be(1); - var root = gun.Back(-1)._.graph[soul]; + var root = gun.back(-1)._.graph[soul]; expect(root.hello).to.be('key'); expect(root.yay).to.not.be.ok(); expect(Gun.val.rel.is(root.hi)).to.be.ok(); expect(Gun.val.rel.is(root.hi)).to.not.be(soul); - var node = gun.Back(-1)._.graph[Gun.val.rel.is(root.hi)]; + var node = gun.back(-1)._.graph[Gun.val.rel.is(root.hi)]; expect(node.yay).to.be('value'); if(done.sub){ expect(done.sub).to.be(Gun.val.rel.is(root.hi)) } else { done.sub = Gun.val.rel.is(root.hi) } @@ -5103,11 +5102,11 @@ describe('Gun', function(){ g.path('hi').put({happy: "faces"}, function(err, ok){ if(done.c){ return } expect(err).to.not.be.ok(); - var keynode = gun.Back(-1)._.graph[done.soul], soul; + var keynode = gun.back(-1)._.graph[done.soul], soul; var c = soulnode(gun, keynode), soul = c[0]; expect(c.length).to.be(1); - var root = gun.Back(-1)._.graph[soul]; - var sub = gun.Back(-1)._.graph[done.ref]; + var root = gun.back(-1)._.graph[soul]; + var sub = gun.back(-1)._.graph[done.ref]; expect(root.hello).to.be('key'); expect(root.yay).to.not.be.ok(); expect(Gun.node.soul(sub)).to.be(done.ref); @@ -5136,11 +5135,11 @@ describe('Gun', function(){ }).path('hi').put('crushed', function(err, ok){ if(done.c){ return } expect(err).to.not.be.ok(); - var keynode = gun.Back(-1)._.graph[done.soul], soul; + var keynode = gun.back(-1)._.graph[done.soul], soul; var c = soulnode(gun, keynode), soul = c[0]; expect(c.length).to.be(1); - var root = gun.Back(-1)._.graph[soul]; - var sub = gun.Back(-1)._.graph[done.ref]; + var root = gun.back(-1)._.graph[soul]; + var sub = gun.back(-1)._.graph[done.ref]; expect(root.hello).to.be('key'); expect(root.yay).to.not.be.ok(); expect(Gun.node.soul(sub)).to.be(done.ref); @@ -5465,8 +5464,8 @@ describe('Gun', function(){ expect(err).to.not.be.ok(); }).val(function(val){ setTimeout(function(){ // TODO: Is this cheating? I don't think so cause we are using things outside of the API! - var a = gun.Back(-1)._.graph[Gun.val.rel.is(val.a)]; - var b = gun.Back(-1)._.graph[Gun.val.rel.is(val.b)]; + var a = gun.back(-1)._.graph[Gun.val.rel.is(val.a)]; + var b = gun.back(-1)._.graph[Gun.val.rel.is(val.b)]; expect(Gun.val.rel.is(val.a)).to.be(Gun.node.soul(a)); expect(Gun.val.rel.is(val.b)).to.be(Gun.node.soul(b)); expect(Gun.val.rel.is(a.kid)).to.be(Gun.node.soul(b)); @@ -5577,7 +5576,7 @@ describe('Gun', function(){ }).path('wife.pet.name').val(function(val){ //console.debug(1, "*****************", val); expect(val).to.be('Hobbes'); - }).back.path('pet.master').val(function(val){ + }).back().path('pet.master').val(function(val){ //console.log("*****************", val); expect(val.name).to.be("Amber Nadal"); expect(val.phd).to.be.ok(); @@ -5750,7 +5749,7 @@ describe('Gun', function(){ //expect(a['_']['key']).to.be.ok(); gun.get('user/beth').put({friend: a}, function(err, ok){ // b - friend_of -> a expect(err).to.not.be.ok(); - var keynode = gun.Back(-1)._.graph['user/alfred']; + var keynode = gun.back(-1)._.graph['user/alfred']; var c = soulnode(gun, keynode), soul = c[0]; expect(c.length).to.be(1); }); @@ -5796,7 +5795,7 @@ describe('Gun', function(){ var gun = Gun(); gun.key('me', function(err, ok){ expect(err).to.not.be.ok(); - var keynode = gun.Back(-1)._.graph['me']; + var keynode = gun.back(-1)._.graph['me']; var c = soulnode(gun, keynode), soul = c[0]; expect(c.length).to.be(1); @@ -6984,7 +6983,7 @@ describe('Gun', function(){ passengers.map().path('direction.lol').val(function(val){ this.path('just').val(function(val){ expect(val).to.be('kidding'); - }).back.path('dude').val(function(val){ + }).back().path('dude').val(function(val){ expect(val).to.be('!'); done(); }); @@ -7125,7 +7124,7 @@ describe('Gun', function(){ gun .path('history') .put(null) - .back + .back() .path('taken') .put(false) @@ -7322,7 +7321,7 @@ describe('Gun', function(){ cb(at, at.soul); //first = performance.now() - start;(first > .05) && console.log('here'); }; - ($.empty && !$.field)? path() : chain.back.path(at.path || [], path, {once: true, end: true}); // TODO: clean this up. + ($.empty && !$.field)? path() : chain.back().path(at.path || [], path, {once: true, end: true}); // TODO: clean this up. } //var diff1 = (first - start), diff2 = (second - first), diff3 = (third - second); //(diff1 || diff2 || diff3) && console.log(diff1, ' ', diff2, ' ', diff3); @@ -7785,9 +7784,9 @@ describe('Gun', function(){ users.set(carl); users.set(dave); - alice.path('friends').set(bob).back.set(carl); + alice.path('friends').set(bob).back().set(carl); bob.path('friends').set(alice); - dave.path('friends').set(alice).back.set(carl); + dave.path('friends').set(alice).back().set(carl); var team = gun.get('team/lions').put({name: "Lions"}); team.path('members').set(alice); diff --git a/test/gun.html b/test/gun.html index c0b4a08f..47f6f986 100644 --- a/test/gun.html +++ b/test/gun.html @@ -1,7 +1,6 @@ - \ No newline at end of file diff --git a/test/panic/b2s2s2b.js b/test/panic/b2s2s2b.js index 457a6855..4f9b0778 100644 --- a/test/panic/b2s2s2b.js +++ b/test/panic/b2s2s2b.js @@ -3,8 +3,8 @@ var config = { port: 8080, servers: 2, browsers: 2, - each: 10000, - burst: 100, + each: 12000, + burst: 1000, wait: 1, route: { '/': __dirname + '/index.html',