make off more aggressive.

This commit is contained in:
Mark Nadal 2017-11-07 14:42:58 -08:00
parent ab196bc42f
commit b5bb379693
5 changed files with 45 additions and 61 deletions

46
gun.js
View File

@ -1512,30 +1512,7 @@
}
Gun.chain.off = function(){
var gun = this, at = gun._, tmp;
var back = at.back || {}, cat = back._;
if(!cat){ return }
if(tmp = cat.next){
if(tmp[at.get]){
obj_del(tmp, at.get);
} else {
obj_map(tmp, function(path, key){
if(gun !== path){ return }
obj_del(tmp, key);
});
}
}
if((tmp = gun.back(-1)) === back){
obj_del(tmp.graph, at.get);
}
if(at.ons && (tmp = at.ons['@$'])){
obj_map(tmp.s, function(ev){
ev.off();
});
}
return gun;
}
Gun.chain.off = function(){
// make off more aggressive. Warning, it might backfire!
var gun = this, at = gun._, tmp;
var back = at.back || {}, cat = back._;
if(!cat){ return }
@ -1546,12 +1523,31 @@
}
}
if(tmp = cat.ask){
obj_del(tmp, at.get);
}
if(tmp = cat.put){
obj_del(tmp, at.get);
}
if(tmp = at.soul){
obj_del(cat.root._.graph, tmp);
}
if(tmp = at.map){
obj_map(tmp, function(at){
if(at.rel){
cat.root.get(at.rel).off();
}
});
}
if(tmp = at.next){
obj_map(tmp, function(ref){
ref.off();
});
}
at.on('off', {});
return gun;
}
var obj = Gun.obj, obj_has = obj.has, obj_del = obj.del, obj_to = obj.to;
var obj = Gun.obj, obj_map = obj.map, obj_has = obj.has, obj_del = obj.del, obj_to = obj.to;
var rel = Gun.val.rel;
var empty = {}, noop = function(){}, u;
})(require, './on');

2
gun.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -35,7 +35,6 @@ function Radisk(opt){
if(val instanceof Function){
cb = val;
val = r.batch(key);
console.debug(3, 'batch', val);
if(u !== val){
return cb(u, val);
}
@ -179,7 +178,6 @@ function Radisk(opt){
// TODO: BUG!!! If a node spans multiple file chunks, it won't return all!
// TODO: BUG!!! If a node spans multiple file chunks, it won't return all!
var id = Gun.text.random(3);
console.debug(4, 'read', key, !!RAD, id);
if(RAD){ // cache
var val = RAD(key);
if(u !== val){
@ -200,14 +198,13 @@ function Radisk(opt){
g.file = file;
}
g.it = function(err, disk){
console.debug(5, 'readit', id);
if(g.err = err){ Gun.log(err) }
if(disk){
RAD = disk;
g.val = disk(key);
}
Gun.obj.map(q[g.file], g.ack);
Gun.obj.del(q[g.file]);
disk = q[g.file]; Gun.obj.del(q, g.file);
Gun.obj.map(disk, g.ack);
}
g.ack = function(ack){
ack(g.err, g.val);

View File

@ -34,16 +34,11 @@ Gun.on('opt', function(ctx){
ctx.on('get', function(at){
this.to.next(at);
var id = at['#'], soul = at.get['#'], key = at.get['.']||'', tmp = soul+'.'+key, node;
console.debug(2,"store GET", tmp);
console.debug(1,"store GET", tmp);
rad(tmp, function(err, val){
console.debug(7,"store GOT", val);
if(val){
Radix.map(val, each);
if(!node){ each(val, key) }
}
console.debug(8,"store GOT", node);
console.debug(6,"store GOT", node);
ctx.on('in', {'@': id, put: Gun.graph.node(node), err: err? err : u});
});
function each(val, key){

View File

@ -107,30 +107,7 @@ function val(msg, ev, to){
}
Gun.chain.off = function(){
var gun = this, at = gun._, tmp;
var back = at.back || {}, cat = back._;
if(!cat){ return }
if(tmp = cat.next){
if(tmp[at.get]){
obj_del(tmp, at.get);
} else {
obj_map(tmp, function(path, key){
if(gun !== path){ return }
obj_del(tmp, key);
});
}
}
if((tmp = gun.back(-1)) === back){
obj_del(tmp.graph, at.get);
}
if(at.ons && (tmp = at.ons['@$'])){
obj_map(tmp.s, function(ev){
ev.off();
});
}
return gun;
}
Gun.chain.off = function(){
// make off more aggressive. Warning, it might backfire!
var gun = this, at = gun._, tmp;
var back = at.back || {}, cat = back._;
if(!cat){ return }
@ -141,12 +118,31 @@ Gun.chain.off = function(){
}
}
if(tmp = cat.ask){
obj_del(tmp, at.get);
}
if(tmp = cat.put){
obj_del(tmp, at.get);
}
if(tmp = at.soul){
obj_del(cat.root._.graph, tmp);
}
if(tmp = at.map){
obj_map(tmp, function(at){
if(at.rel){
cat.root.get(at.rel).off();
}
});
}
if(tmp = at.next){
obj_map(tmp, function(ref){
ref.off();
});
}
at.on('off', {});
return gun;
}
var obj = Gun.obj, obj_has = obj.has, obj_del = obj.del, obj_to = obj.to;
var obj = Gun.obj, obj_map = obj.map, obj_has = obj.has, obj_del = obj.del, obj_to = obj.to;
var rel = Gun.val.rel;
var empty = {}, noop = function(){}, u;