mirror of
https://github.com/amark/gun.git
synced 2025-07-09 14:22:33 +00:00
make off more aggressive.
This commit is contained in:
parent
ab196bc42f
commit
b5bb379693
46
gun.js
46
gun.js
@ -1512,30 +1512,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
Gun.chain.off = function(){
|
Gun.chain.off = function(){
|
||||||
var gun = this, at = gun._, tmp;
|
// make off more aggressive. Warning, it might backfire!
|
||||||
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(){
|
|
||||||
var gun = this, at = gun._, tmp;
|
var gun = this, at = gun._, tmp;
|
||||||
var back = at.back || {}, cat = back._;
|
var back = at.back || {}, cat = back._;
|
||||||
if(!cat){ return }
|
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){
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if(tmp = at.next){
|
||||||
|
obj_map(tmp, function(ref){
|
||||||
|
ref.off();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
at.on('off', {});
|
||||||
return gun;
|
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 rel = Gun.val.rel;
|
||||||
var empty = {}, noop = function(){}, u;
|
var empty = {}, noop = function(){}, u;
|
||||||
})(require, './on');
|
})(require, './on');
|
||||||
|
2
gun.min.js
vendored
2
gun.min.js
vendored
File diff suppressed because one or more lines are too long
@ -35,7 +35,6 @@ function Radisk(opt){
|
|||||||
if(val instanceof Function){
|
if(val instanceof Function){
|
||||||
cb = val;
|
cb = val;
|
||||||
val = r.batch(key);
|
val = r.batch(key);
|
||||||
console.debug(3, 'batch', val);
|
|
||||||
if(u !== val){
|
if(u !== val){
|
||||||
return cb(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!
|
||||||
// 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);
|
var id = Gun.text.random(3);
|
||||||
console.debug(4, 'read', key, !!RAD, id);
|
|
||||||
if(RAD){ // cache
|
if(RAD){ // cache
|
||||||
var val = RAD(key);
|
var val = RAD(key);
|
||||||
if(u !== val){
|
if(u !== val){
|
||||||
@ -200,14 +198,13 @@ function Radisk(opt){
|
|||||||
g.file = file;
|
g.file = file;
|
||||||
}
|
}
|
||||||
g.it = function(err, disk){
|
g.it = function(err, disk){
|
||||||
console.debug(5, 'readit', id);
|
|
||||||
if(g.err = err){ Gun.log(err) }
|
if(g.err = err){ Gun.log(err) }
|
||||||
if(disk){
|
if(disk){
|
||||||
RAD = disk;
|
RAD = disk;
|
||||||
g.val = disk(key);
|
g.val = disk(key);
|
||||||
}
|
}
|
||||||
Gun.obj.map(q[g.file], g.ack);
|
disk = q[g.file]; Gun.obj.del(q, g.file);
|
||||||
Gun.obj.del(q[g.file]);
|
Gun.obj.map(disk, g.ack);
|
||||||
}
|
}
|
||||||
g.ack = function(ack){
|
g.ack = function(ack){
|
||||||
ack(g.err, g.val);
|
ack(g.err, g.val);
|
||||||
|
@ -34,16 +34,11 @@ Gun.on('opt', function(ctx){
|
|||||||
ctx.on('get', function(at){
|
ctx.on('get', function(at){
|
||||||
this.to.next(at);
|
this.to.next(at);
|
||||||
var id = at['#'], soul = at.get['#'], key = at.get['.']||'', tmp = soul+'.'+key, node;
|
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){
|
rad(tmp, function(err, val){
|
||||||
console.debug(7,"store GOT", val);
|
|
||||||
if(val){
|
if(val){
|
||||||
Radix.map(val, each);
|
Radix.map(val, each);
|
||||||
if(!node){ each(val, key) }
|
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});
|
ctx.on('in', {'@': id, put: Gun.graph.node(node), err: err? err : u});
|
||||||
});
|
});
|
||||||
function each(val, key){
|
function each(val, key){
|
||||||
|
46
src/on.js
46
src/on.js
@ -107,30 +107,7 @@ function val(msg, ev, to){
|
|||||||
}
|
}
|
||||||
|
|
||||||
Gun.chain.off = function(){
|
Gun.chain.off = function(){
|
||||||
var gun = this, at = gun._, tmp;
|
// make off more aggressive. Warning, it might backfire!
|
||||||
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(){
|
|
||||||
var gun = this, at = gun._, tmp;
|
var gun = this, at = gun._, tmp;
|
||||||
var back = at.back || {}, cat = back._;
|
var back = at.back || {}, cat = back._;
|
||||||
if(!cat){ return }
|
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){
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if(tmp = at.next){
|
||||||
|
obj_map(tmp, function(ref){
|
||||||
|
ref.off();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
at.on('off', {});
|
||||||
return gun;
|
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 rel = Gun.val.rel;
|
||||||
var empty = {}, noop = function(){}, u;
|
var empty = {}, noop = function(){}, u;
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user