mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
fix pack/max, update dom
This commit is contained in:
parent
6d44f82997
commit
1532016224
@ -3,15 +3,15 @@
|
||||
<style>html, body, textarea { width: 100%; height: 100%; padding: 0; margin: 0; }</style>
|
||||
<textarea placeholder="paste here!"></textarea>
|
||||
|
||||
<script src="../jquery.js"></script>
|
||||
<script src="../../../gun/gun.js"></script>
|
||||
<script src="../../../gun/lib/dom.js"></script>
|
||||
|
||||
<script>
|
||||
var gun = Gun(location.origin + '/gun');
|
||||
gun = GUN(location.origin + '/gun');
|
||||
|
||||
$('textarea').on('input change blur keyup mouseup touchend', function(){
|
||||
$('textarea').on('input change blur keyup mouseup touchend', () => {
|
||||
gun.get('test').get('paste').put($('textarea').val())
|
||||
});
|
||||
|
||||
gun.get('test').get('paste').on(data => $('textarea').val(data))
|
||||
gun.get('test').get('paste').on(data => $('textarea').val(data));
|
||||
</script>
|
9
gun.js
9
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 || {};
|
||||
|
55
lib/doll.js
55
lib/doll.js
@ -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) }
|
||||
}());
|
71
lib/dom.js
Normal file
71
lib/dom.js
Normal file
@ -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 }
|
||||
}());
|
@ -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!
|
||||
|
@ -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){
|
||||
|
@ -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()
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user