diff --git a/examples/basic/paste.html b/examples/basic/paste.html index a4f2bff1..2a6b80e2 100644 --- a/examples/basic/paste.html +++ b/examples/basic/paste.html @@ -3,15 +3,15 @@ - + \ No newline at end of file diff --git a/gun.js b/gun.js index ea8757ee..54f3db66 100644 --- a/gun.js +++ b/gun.js @@ -359,7 +359,7 @@ } if(state < was){ /*old;*/ if(!ctx.miss){ return } } // but some chains have a cache miss that need to re-fire. // TODO: Improve in future. // for AXE this would reduce rebroadcast, but GUN does it on message forwarding. if(!ctx.faith){ // TODO: BUG? Can this be used for cache miss as well? // Yes this was a bug, need to check cache miss for RAD tests, but should we care about the faith check now? Probably not. - if(state === was && (val === known || L(val) <= L(known))){ /*console.log("same");*/ /*same;*/ if(!ctx.miss){ return } } // same + if(state === was && (val === known || L(val) <= L(known))){ /*console.log("same");*/ /*same;*/ if(true || !ctx.miss){ return } } // same } ctx.stun++; // TODO: 'forget' feature in SEA tied to this, bad approach, but hacked in for now. Any changes here must update there. var aid = msg['#']+ctx.all++, id = {toString: function(){ return aid }, _: ctx}; // this *trick* makes it compatible between old & new versions. @@ -774,7 +774,7 @@ }; Gun.on.unlink = unlink; function ack(msg, ev){ - if(!msg['%'] && (this||'').off){ this.off() } // do NOT memory leak, turn off listeners! + //if(!msg['%'] && (this||'').off){ this.off() } // do NOT memory leak, turn off listeners! // manhattan: var as = this.as, at = as.$._, root = at.root, get = as.get||'', tmp = (msg.put||'')[get['#']]||''; if(!msg.put || ('string' == typeof get['.'] && u === tmp[get['.']])){ @@ -1273,7 +1273,8 @@ var opt = root.opt || {}; opt.log = opt.log || console.log; opt.gap = opt.gap || opt.wait || 0; - opt.pack = opt.pack || 9 * 1000;//(opt.memory? (opt.memory * 999 * 999) : 300000000) * 0.3; + opt.max = opt.max || (opt.memory? (opt.memory * 999 * 999) : 300000000) * 0.3; + opt.pack = opt.pack || (opt.max * 0.01 * 0.01); opt.puff = opt.puff || 9; // IDEA: do a start/end benchmark, divide ops/result. var puff = setTimeout.turn || setTimeout; var parse = JSON.parseAsync || function(t,cb,r){ var u; try{ cb(u, JSON.parse(t,r)) }catch(e){ cb(e) } } @@ -1285,7 +1286,7 @@ var hear = mesh.hear = function(raw, peer){ if(!raw){ return } - if(opt.pack <= raw.length){ return mesh.say({dam: '!', err: "Message too big!"}, peer) } + if(opt.max <= raw.length){ return mesh.say({dam: '!', err: "Message too big!"}, peer) } if(mesh === this){ /*if('string' == typeof raw){ try{ var stat = console.STAT || {}; diff --git a/lib/doll.js b/lib/doll.js deleted file mode 100644 index c8358550..00000000 --- a/lib/doll.js +++ /dev/null @@ -1,55 +0,0 @@ -;(function(){ // jQuery shim - if(window.$){ return } - (($ = window.$ = function(q, tag){ - if(!(this instanceof $)){ return new $(q, tag) } - this.tags = (q && q.tags) || (('string' != typeof q)? - (q?[q]:[]) : (tag||document).querySelectorAll(q)); - return this; - }).fn = $.prototype).each = function(cb){ return $.each(this.tags, cb), this } - $.each = function(o, cb){ Object.keys(o).forEach(function(k){ cb(k, o[k]) }) } - $.fn.get = function(i, l, u){ return l = this.tags, (i === u)? l : l[i] } - $.fn.on = function(eve, cb){ return this.each(function(i, tag){ tag.addEventListener(eve, cb) })} - $.fn.is = function(q, b){ return this.each(function(i, tag){ b = b || tag.matches(q) }), b } - $.fn.css = function(obj){ return this.each(function(i, tag){ $.each(obj, function(k,v){ tag.style[k] = v }) })} - $.fn.text = function(text, key, f, u){ - text = (text === u)? '' : (f = 1) && text; - key = key || 'textContent'; - this.each(function(i, tag){ - if(f){ tag[key] = text } - else { text += (tag[key]||'') } - }); - return f? this : text; - } - $.fn.html = function(html){ return this.text(html, 'innerHTML') } - $.fn.find = function(q){ - var I = $(), l = I.tags; - this.each(function(i, tag){ - $(q, tag).each(function(i, tag){ - if(0 > l.indexOf(tag)){ l.push(tag) } - }); - }); - return I; - } - $.fn.add = function(html, div){ - (div = document.createElement('div')).innerHTML = html; - this.tags = [].slice.call(this.tags).concat([].slice.call(div.childNodes)); - return this; - } - $.fn.append = function(html, op, f){ return this.each(function(i, tag){ - (('<' === html[0])? $().add(html) : $(html)).each(function(i, node){ - (f? node : tag)[op || 'appendChild'](f? tag : node); - }) - })} - $.fn.appendTo = function(html){ return this.append(html, 0, 1) } - $.fn.parents = function(q, c){ - var I = $(), l = I.tags, p = 'parentElement'; - this.each(function(i, tag){ - if(c){ (c = {})[p] = tag ; tag = c } - while(tag){ if((tag = tag[p]) && $(tag).is(q)){ - l.push(tag); if(c){ return } - }} - }); - return I; - } - $.fn.closest = function(q, c){ return this.parents(q, 1) } -}()); \ No newline at end of file diff --git a/lib/dom.js b/lib/dom.js new file mode 100644 index 00000000..f0ed045f --- /dev/null +++ b/lib/dom.js @@ -0,0 +1,71 @@ +;(function(){ // jQuery shim + // u = undefined, n = null, b = boolean = true/false, n = number, t = text, l = list = array, o = object, cb = callback = function, q = CSS query, k = key, eve = event. + if(window.$){ return } + (($ = window.$ = function(q, tag){ + if(q instanceof $){ return q } + if(!(this instanceof $)){ return new $(q, tag) } + this.tags = ((q && q.tags) + || (('string' != typeof q)? (q?[q]:[]) + : (tag||document).querySelectorAll(q))); + return this; + }).fn = $.prototype).each = function(cb){ return $.each(this.tags, cb), this } + $.each = function(o, cb){ Object.keys(o).forEach(function(k){ cb(k, o[k]) }) } + $.isPlainObject = function(o){ + return (o? (o instanceof Object && o.constructor === Object) + || 'Object' === Object.prototype.toString.call(o).match(/^\[object (\w+)\]$/)[1] + : false); + } + $.fn.get = function(i, l, u){ return l = this.tags, (i === u)? l : l[i] } + $.fn.is = function(q, b){ return this.each(function(i, tag){ b = b || tag.matches(q) }), b } + $.fn.css = function(o){ return this.each(function(i, tag){ $.each(o, function(k,v){ tag.style[k] = v }) })} + $.fn.on = function(t, cb){ return this.each(function(i, tag){ + t.split(" ").forEach(function(t){ tag.addEventListener(t, cb) }); + })} + $.fn.val = function(t, k, f, u){ + t = (t === u)? '' : (f = 1) && t; + k = k || 'value'; + this.each(function(i, tag){ + if(f){ tag[k] = t } + else { t += (tag[k]||'') } + }); + return f? this : t; + } + $.fn.text = function(t){ return this.val(t, 'textContent') } + $.fn.html = function(html){ return this.val(html, 'innerHTML') } + $.fn.find = function(q){ + var I = $(), l = I.tags; + this.each(function(i, tag){ + $(q, tag).each(function(i, tag){ + if(0 > l.indexOf(tag)){ l.push(tag) } + }); + }); + return I; + } + $.fn.add = function(add, tmp){ + if(!add){ return this } + if('<' === (tmp = add)[0]){ (add = document.createElement('div')).innerHTML = tmp } + return this.tags = [].slice.call(this.tags).concat([].slice.call($(add).tags)), this; + } + $.fn.place = function(where, on, f, op){ return this.each(function(i, tag){ $(on).each(function(i, node){ + (f? tag : node)[op||'insertAdjacentElement'](({ + '-1':'beforebegin', '-0.1': 'afterbegin', '0.1':'beforeend', '1': 'afterend' + })[where], (f? node : tag)); + })})} + $.fn.append = function(html){ return $().add(html).place(0.1, this), this } + $.fn.appendTo = function(html){ return this.place(0.1, $().add(html)) } + function rev(o){ var I = $(); I.tags = [].slice.call(o.tags).reverse(); return I } + $.fn.prependTo = function(html){ return rev(this).place(-0.1, $().add(html)), this } + $.fn.prepend = function(html){ return rev($().add(html)).place(-0.1, this), this } + $.fn.parents = function(q, c){ + var I = $(), l = I.tags, p = 'parentElement'; + this.each(function(i, tag){ + if(c){ (c = {})[p] = tag ; tag = c } + while(tag){ if((tag = tag[p]) && $(tag).is(q)){ + l.push(tag); if(c){ return } + }} + }); + return I; + } + $.fn.closest = function(q, c){ return this.parents(q, 1) } + $.fn.clone = function(b){ I = $(), l = I.tags, this.each(function(i, tag){ l.push(tag.cloneNode(true)) }), I } +}()); \ No newline at end of file diff --git a/lib/radisk.js b/lib/radisk.js index db3db69c..3e36a4d5 100644 --- a/lib/radisk.js +++ b/lib/radisk.js @@ -8,7 +8,7 @@ var has = (Radisk.has || (Radisk.has = {}))[opt.file]; if(has){ return has } - opt.pack = opt.pack || (opt.memory? (opt.memory * 999 * 999) : 300000000) * 0.3; + opt.max = opt.max || (opt.memory? (opt.memory * 999 * 999) : 300000000) * 0.3; opt.until = opt.until || opt.wait || 250; opt.batch = opt.batch || (10 * 1000); opt.chunk = opt.chunk || (1024 * 1024 * 1); // 1MB @@ -216,7 +216,7 @@ } f.each = function(val, key, k, pre){ if(u !== val){ f.count++ } - if(opt.pack <= (val||'').length){ return cb("Data too big!"), true } + if(opt.max <= (val||'').length){ return cb("Data too big!"), true } var enc = Radisk.encode(pre.length) +'#'+ Radisk.encode(k) + (u === val? '' : ':'+ Radisk.encode(val)) +'\n'; if((opt.chunk < f.text.length + enc.length) && (1 < f.count) && !o.force){ return f.split(); @@ -363,7 +363,7 @@ } if('string' !== typeof data){ try{ - if(opt.pack <= data.length){ + if(opt.max <= data.length){ p.err = "Chunk too big!"; } else { data = data.toString(); // If it crashes, it crashes here. How!?? We check size first! diff --git a/test/rad/rad.js b/test/rad/rad.js index 068a1ad5..c3e8973d 100644 --- a/test/rad/rad.js +++ b/test/rad/rad.js @@ -321,6 +321,11 @@ var names = ["Adalard","Adora","Aia","Albertina","Alfie","Allyn","Amabil","Ammam describe('RAD + GUN', function(){ this.timeout(1000 * 5); var ochunk = 1000; + Gun.on('opt', function(root){ + root.opt.localStorage = false; + Gun.window && console.log("RAD disabling localStorage during tests."); + this.to.next(root); + }) var gun = Gun({chunk: ochunk}); /*it('deleting old tests (may take long time)', function(done){ diff --git a/test/sea/sea.js b/test/sea/sea.js index 0d5308f8..9b4e60fd 100755 --- a/test/sea/sea.js +++ b/test/sea/sea.js @@ -316,7 +316,7 @@ describe('SEA', function(){ }) it('register users', function(done){ - user.create('carl', 'test123', function(ack){ + user.create('carl', 'testing123', function(ack){ pub = '~'+ack.pub; expect(ack.err).to.not.be.ok(); done(); @@ -324,7 +324,7 @@ describe('SEA', function(){ }); it('login users', function(done){ - user.auth('carl', 'test123', function(ack){ + user.auth('carl', 'testing123', function(ack){ expect(ack.err).to.not.be.ok(); done() }) @@ -377,7 +377,7 @@ describe('SEA', function(){ setTimeout(function(){ gun = Gun(); user = gun.user(); - user.auth('carl', 'test123', function(ack){ + user.auth('carl', 'testing123', function(ack){ expect(ack.err).to.not.be.ok(); done() })