mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
into unlink. Clean/refactor later.
This commit is contained in:
parent
cc1a03e6d2
commit
5a05ada9ae
41
gun.js
41
gun.js
@ -688,29 +688,7 @@
|
||||
},0,99);
|
||||
return;
|
||||
}
|
||||
if(!cat.soul && !msg.$$){
|
||||
if(
|
||||
(cat.link !== null || (root.pass||'')[cat.id]) &&
|
||||
(((root.pass||'')[cat.id] && cat.link !== u && cat.ask['']) || // fire again if we have a pass but be careful not to fire if we do not have the node fully loaded yet.
|
||||
(('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);
|
||||
}
|
||||
}
|
||||
/*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? */
|
||||
unlink(msg, cat);
|
||||
|
||||
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?
|
||||
@ -754,6 +732,23 @@
|
||||
}
|
||||
}; Gun.on.link = link;
|
||||
|
||||
function unlink(msg, cat){ // ugh, so much code for barely used behavior.
|
||||
if(cat.soul || msg.$$){ return }
|
||||
var put = msg.put||'', change = put['=']||put[':']
|
||||
if( // TODO: refactor this to be a return rather than a nested if.
|
||||
(cat.link !== null || (cat.root.pass||'')[cat.id]) &&
|
||||
(((cat.root.pass||'')[cat.id] && cat.link !== u && cat.ask['']) || // fire again if we have a pass but be careful not to fire if we do not have the node fully loaded yet. // TODO: Bug? What about async load needing to pass?
|
||||
(('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 (not at init, or unnecessary duplications, etc.), 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);
|
||||
}
|
||||
}; Gun.on.unlink = unlink;
|
||||
|
||||
function ack(msg, ev){
|
||||
// manhattan:
|
||||
var as = this.as, at = as.$._, get = as.get||'', tmp = (msg.put||'')[get['#']]||'';
|
||||
|
Loading…
x
Reference in New Issue
Block a user