mirror of
https://github.com/amark/gun.git
synced 2025-06-22 14:02:33 +00:00
call sub chains on clear/empty WIP
This commit is contained in:
parent
dcd6fc55fa
commit
e16f982ee8
24
gun.js
24
gun.js
@ -687,19 +687,33 @@
|
||||
sat.on('in', {get: get, put: u, $: sat.$}); // TODO: BUG? Add recursive seen check?
|
||||
},0,99);
|
||||
return;
|
||||
} if(cat.ask && at.has && !msg.$$ && (('string' != typeof (tmp = valid(change))) || (cat.link && cat.link != tmp))){ // whenever we are not a link, nor the same link as before, (for our layer) we need to clear out subchains, and...
|
||||
if(cat.link !== null || (root.pass||'')[cat.id]){
|
||||
cat.link = null; // ideally only once, don't forget pass logic, see linking logic for why.
|
||||
}
|
||||
if(!cat.soul && !msg.$$){
|
||||
if(
|
||||
(cat.link !== null || (root.pass||'')[cat.id]) &&
|
||||
//cat.link !== u && // TODO: BUG? actually this should be if link as a property exists or not.
|
||||
(('string' != typeof (tmp = valid(change))) || (cat.link && tmp != cat.link)) // any time there is a change in value that is different from the previous link in any way, we need to fire a clear/empty event on chains below. // However! Do this only when unique, and make sure to do it with performance in mind.
|
||||
){
|
||||
cat.link = null;
|
||||
cat.next && setTimeout.each(Object.keys(cat.ask||''), function(get, sat){ // TODO: Bug? If we're a map do we want to clear out everything, wouldn't it just be the one item's subchains, not all?
|
||||
if(!(sat = cat.next[get])){ return } // only if next, even if asked. (right?)
|
||||
sat.on('in', {get: get, put: u, $: sat.$});
|
||||
},0,99);
|
||||
}
|
||||
} // this was an absurd amount of code to handle a tiny edge case :/ maybe don't support it in future?
|
||||
}
|
||||
/*if(cat.ask && ((at.has && !msg.$$) || (!at.has && msg.$$)) && (('string' != typeof (tmp = valid(change))) || (cat.link && cat.link != tmp))){ // whenever we are not a link, nor the same link as before, (for our layer) we need to clear out subchains, and... // this code is so ugly & heavy, is there something easier?
|
||||
if(cat.link !== null || (root.pass||'')[cat.id]){ cat.link = null; // ideally only once, don't forget pass logic, see linking logic for why. // TODO: What about async loaded?
|
||||
console.log("ugggggh", msg, cat);
|
||||
cat.next && setTimeout.each(Object.keys(cat.ask||''), function(get, sat){ // TODO: Bug? If we're a map do we want to clear out everything, wouldn't it just be the one item's subchains, not all?
|
||||
if(!(sat = cat.next[get])){ return } // only if next, even if asked. (right?)
|
||||
sat.on('in', {get: get, put: u, $: sat.$});
|
||||
},0,99);
|
||||
}
|
||||
} // this was an absurd amount of code to handle a tiny edge case :/ maybe don't support it in future? */
|
||||
|
||||
if(((msg.$$||'')._||at).soul){ // comments are linear, but this line of code is non-linear, so if I were to comment what it does, you'd have to read 42 other comments first... but you can't read any of those comments until you first read this comment. What!? // shouldn't this match link's check?
|
||||
// is there cases where it is a $$ that we do NOT want to do the following?
|
||||
if((sat = cat.next) && (sat = sat[key])){ // TODO: possible trick? Maybe have `ionmap` code set a sat?
|
||||
if((sat = cat.next) && (sat = sat[key])){ // TODO: possible trick? Maybe have `ionmap` code set a sat? // TODO: Maybe we should do `cat.ask` instead? I guess does not matter.
|
||||
tmp = {}; Object.keys(msg).forEach(function(k){ tmp[k] = msg[k] });
|
||||
tmp.$ = (msg.$$||msg.$).get(tmp.get = key); delete tmp.$$; delete tmp.$$$;
|
||||
sat.on('in', tmp);
|
||||
|
@ -2964,7 +2964,7 @@ describe('Gun', function(){
|
||||
}, 'parallel/later', function(){
|
||||
gun.get('parallel/later').get('bob').get('age').get(function(at, ev){
|
||||
var err = at.err, data = at.put, field = at.get;
|
||||
//console.log("***** age", data, field, at); return;
|
||||
//console.log("*****", field, data); return;
|
||||
expect(data).to.be(29);
|
||||
expect(field).to.be('age');
|
||||
done.age = true;
|
||||
@ -2972,7 +2972,7 @@ describe('Gun', function(){
|
||||
setTimeout(function(){
|
||||
gun.get('parallel/later').get('bob').get('name').get(function(at, ev){
|
||||
var err = at.err, data = at.put, field = at.get;
|
||||
//console.log("*********** name", data, field); return;
|
||||
//console.log("***********", field, data); return;
|
||||
expect(data).to.be('Bob!');
|
||||
expect(field).to.be('name');
|
||||
done.name = true;
|
||||
@ -3511,7 +3511,7 @@ describe('Gun', function(){
|
||||
}, {v2020:1});
|
||||
|
||||
setTimeout(function(){ // adding more rigorous test!
|
||||
|
||||
//console.log("------------");
|
||||
app.get('a').get('b').get(function(d){
|
||||
d = (d.$$||d.$)._.put;
|
||||
//console.log('****::::', d);
|
||||
@ -3536,25 +3536,28 @@ describe('Gun', function(){
|
||||
var app = gun.get('nl/app').get('bar');
|
||||
|
||||
app.get(function(d){
|
||||
//console.log("!!", d.put);
|
||||
//d = (d.$$||d.$)._.put;
|
||||
if(!d || !d.put || !d.put.wat){ return }
|
||||
console.log('should be called: {wat:1}=', d.put);
|
||||
expect(d.put.wat).to.be(1);
|
||||
done.a = 1;
|
||||
if(!done.u){ return }
|
||||
expect(done.u).to.be.ok();
|
||||
if(done.c){ return } done.c = 1;
|
||||
done();
|
||||
});
|
||||
});//, {v2020:1});
|
||||
|
||||
console.log("----------");
|
||||
app.get('a').get('b').get(function(d){
|
||||
//console.log("????", d.put);
|
||||
console.log("empty/clear: undefined=", d.put);
|
||||
//d = (d.$$||d.$)._.put;
|
||||
expect(d.put).to.be(u);
|
||||
done.u = true;
|
||||
if(!done.a){ return }
|
||||
expect(done.a).to.be.ok();
|
||||
if(done.c){ return } done.c = 1;
|
||||
done();
|
||||
});
|
||||
}, {v2020:1});
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user