mirror of
https://github.com/amark/gun.git
synced 2025-06-08 15:16:42 +00:00
all nighter, huge hustle
This commit is contained in:
parent
5ea9b0d2d6
commit
7b7f77be4d
119
gun.js
119
gun.js
@ -797,7 +797,6 @@
|
|||||||
function map(msg, soul){
|
function map(msg, soul){
|
||||||
if(!msg.$){ return }
|
if(!msg.$){ return }
|
||||||
this.cat.stop = this.stop; // temporary fix till a better solution?
|
this.cat.stop = this.stop; // temporary fix till a better solution?
|
||||||
//console.log("MAP |||-->", soul);
|
|
||||||
(msg.$._).on('in', msg);
|
(msg.$._).on('in', msg);
|
||||||
this.cat.stop = null; // temporary fix till a better solution?
|
this.cat.stop = null; // temporary fix till a better solution?
|
||||||
}
|
}
|
||||||
@ -999,7 +998,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function input(msg){
|
function input(msg){
|
||||||
var ev = this, cat = ev.as, gun = msg.$, at = (gun||empty)._ || empty, change = msg.put, rel, tmp;
|
var ev = this, cat = ev.as, root = cat.root, gun = msg.$, at = (gun||empty)._ || empty, change = msg.put, rel, tmp;
|
||||||
if(cat.get && msg.get !== cat.get){
|
if(cat.get && msg.get !== cat.get){
|
||||||
msg = obj_to(msg, {get: cat.get});
|
msg = obj_to(msg, {get: cat.get});
|
||||||
}
|
}
|
||||||
@ -1051,13 +1050,31 @@
|
|||||||
if((rel = Gun.node.soul(change)) && at.has){
|
if((rel = Gun.node.soul(change)) && at.has){
|
||||||
at.put = (cat.root.$.get(rel)._).put;
|
at.put = (cat.root.$.get(rel)._).put;
|
||||||
}
|
}
|
||||||
|
tmp = (root.stop || {})[at.id];
|
||||||
|
if(!tmp){
|
||||||
ev.to.next(msg);
|
ev.to.next(msg);
|
||||||
|
} else
|
||||||
|
if(tmp[cat.id]){
|
||||||
|
} else {
|
||||||
|
ev.to.next(msg);
|
||||||
|
}
|
||||||
echo(cat, msg, ev);
|
echo(cat, msg, ev);
|
||||||
relate(cat, msg, at, rel);
|
relate(cat, msg, at, rel);
|
||||||
if(cat.next){ obj_map(change, map, {msg: msg, cat: cat}) }
|
if(cat.next){ obj_map(change, map, {msg: msg, cat: cat}) }
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var was = root.stop;
|
||||||
|
tmp = root.stop || {};
|
||||||
|
tmp = tmp[at.id] || (tmp[at.id] = {});
|
||||||
|
if(tmp[cat.id]){ return }
|
||||||
|
tmp.is = tmp.is || at.put;
|
||||||
|
tmp[cat.id] = at.put || true;
|
||||||
|
//'z' === cat.get && was && (console.debug.i=console.debug.i||1) && console.debug(1, 'IN:', cat.get, change, cat.ack, cat.ask, at.ack, at.ask, was, tmp[cat.id], at.put);
|
||||||
relate(cat, msg, at, rel);
|
relate(cat, msg, at, rel);
|
||||||
|
//console.log(8, '=========', cat.get, change, at.put, tmp[cat.id], root.stop);
|
||||||
|
//if(was){ ev.to.next(msg) }
|
||||||
|
if(root.stop){ ev.to.next(msg) }
|
||||||
|
//if(was && tmp === at.put){ ev.to.next(msg) }
|
||||||
echo(cat, msg, ev);
|
echo(cat, msg, ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1077,29 +1094,10 @@
|
|||||||
not(at, msg);
|
not(at, msg);
|
||||||
}
|
}
|
||||||
tmp = from.id? ((at.map || (at.map = {}))[from.id] = at.map[from.id] || {at: from}) : {};
|
tmp = from.id? ((at.map || (at.map = {}))[from.id] = at.map[from.id] || {at: from}) : {};
|
||||||
//console.log("!!!", at.id, at.get, at.ask, rel, tmp, 'pass?', at.pass, tmp.pass);
|
|
||||||
if(rel === tmp.link){
|
if(rel === tmp.link){
|
||||||
if(!(tmp.pass || at.pass)){
|
if(!(tmp.pass || at.pass)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*if(from.ack){ return } //return; // if at.has
|
|
||||||
// NOW is a hack to get synchronous replies to correctly call.
|
|
||||||
// and STOP is a hack to get async behavior to correctly call.
|
|
||||||
// neither of these are ideal, need to be fixed without hacks,
|
|
||||||
// but for now, this works for current tests. :/
|
|
||||||
if(!now){
|
|
||||||
return;
|
|
||||||
var stop = at.root.stop;
|
|
||||||
if(!stop){ return }
|
|
||||||
if(stop[at.id] === rel){ return }
|
|
||||||
stop[at.id] = rel;
|
|
||||||
} else {
|
|
||||||
// move back to here to get rid of bugs
|
|
||||||
if(u === now[at.id]){ return }
|
|
||||||
if((now._ || (now._ = {}))[at.id] === rel){ return }
|
|
||||||
now._[at.id] = rel;
|
|
||||||
}
|
|
||||||
//return; // delete this*/
|
|
||||||
}
|
}
|
||||||
if(at.pass){
|
if(at.pass){
|
||||||
Gun.obj.map(at.map, function(tmp){ tmp.pass = true })
|
Gun.obj.map(at.map, function(tmp){ tmp.pass = true })
|
||||||
@ -1196,10 +1194,7 @@
|
|||||||
at.on('in', {get: at.get, put: Gun.val.link.ify(get['#']), $: at.$, '@': msg['@']});
|
at.on('in', {get: at.get, put: Gun.val.link.ify(get['#']), $: at.$, '@': msg['@']});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//if(/*!msg.$ &&*/ !get['.'] && get['#']){ at.ack = (at.ack + 1) || 1 }
|
|
||||||
//msg = obj_to(msg);
|
|
||||||
msg.$ = at.root.$;
|
msg.$ = at.root.$;
|
||||||
//Gun.on('put', at);
|
|
||||||
Gun.on.put(msg, at.root.$);
|
Gun.on.put(msg, at.root.$);
|
||||||
}
|
}
|
||||||
var empty = {}, u;
|
var empty = {}, u;
|
||||||
@ -1268,11 +1263,22 @@
|
|||||||
return at;
|
return at;
|
||||||
}
|
}
|
||||||
function use(msg){
|
function use(msg){
|
||||||
var ev = this, as = ev.as, cat = as.at, root = cat.root, gun = msg.$, at = (gun||{})._ || {}, data = msg.put, tmp;
|
var eve = this, as = eve.as, cat = as.at, root = cat.root, gun = msg.$, at = (gun||{})._ || {}, data = msg.put, tmp;
|
||||||
if((tmp = root.stop)){ if(tmp[at.id]){ return } tmp[at.id] = msg.root; } // temporary fix till a better solution?
|
//console.log("USE:", cat.soul, cat.has, cat.get, data);
|
||||||
if((tmp = root.now) && ev !== tmp[as.now]){
|
if((tmp = root.now) && eve !== tmp[as.now]){ return eve.to.next(msg) }
|
||||||
return ev.to.next(msg);
|
//console.log('USE?', cat.id, at.id, (root.stop && root.stop.ID), msg.put, /*root.stop,*/ at.async, cat.async, at.ack, cat.ack, msg, at.put);
|
||||||
}
|
//console.log('^^^^^', msg, at, cat.async, at.async);
|
||||||
|
//if(at.async && msg.root){ return }
|
||||||
|
//if(at.async === 1 && cat.async !== true){ return }
|
||||||
|
//if(root.stop && root.stop[at.id]){ return } root.stop && (root.stop[at.id] = true);
|
||||||
|
//if(!at.async && !cat.async && at.put && msg.put === at.put){ return }
|
||||||
|
//else if(!cat.async && msg.put !== at.put && root.stop && root.stop[at.id]){ return } root.stop && (root.stop[at.id] = true);
|
||||||
|
|
||||||
|
|
||||||
|
//root.stop && (root.stop.ID = root.stop.ID || Gun.text.random(2));
|
||||||
|
//if((tmp = root.stop) && (tmp = tmp[at.id] || (tmp[at.id] = {})) && tmp[cat.id]){ return } tmp && (tmp[cat.id] = true);
|
||||||
|
if(eve.seen && eve.seen[at.id]){ return eve.to.next(msg) }
|
||||||
|
//if((tmp = root.stop)){ if(tmp[at.id]){ return } tmp[at.id] = msg.root; } // temporary fix till a better solution?
|
||||||
if(u === data){
|
if(u === data){
|
||||||
data = at.put;
|
data = at.put;
|
||||||
}
|
}
|
||||||
@ -1282,18 +1288,21 @@
|
|||||||
msg = obj_to(msg, {put: tmp.put});
|
msg = obj_to(msg, {put: tmp.put});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
as.use(msg, msg.event || ev);
|
as.use(msg, eve);
|
||||||
ev.to.next(msg);
|
eve.to.next(msg);
|
||||||
}
|
}
|
||||||
function rid(at){
|
function rid(at){
|
||||||
var cat = this.on;
|
var cat = this.on;
|
||||||
if(!at || cat.soul || cat.has){ return this.off() }
|
if(!at || cat.soul || cat.has){ return this.off() }
|
||||||
if(!(at = (at = (at = at.$ || at)._ || at).id)){ return }
|
if(!(at = (at = (at = at.$ || at)._ || at).id)){ return }
|
||||||
var map = cat.map, tmp;
|
var map = cat.map, tmp, seen;
|
||||||
if(!map || !(tmp = map[at]) || !(tmp = tmp.at)){ return }
|
//if(!map || !(tmp = map[at]) || !(tmp = tmp.at)){ return }
|
||||||
tmp.echo[cat.id] = {}; // TODO: Warning: This unsubscribes ALL of this chain's listeners from this link, not just the one callback event.
|
if(tmp = (seen = this.seen || (this.seen = {}))[at]){ return true }
|
||||||
|
seen[at] = true;
|
||||||
|
return;
|
||||||
|
//tmp.echo[cat.id] = {}; // TODO: Warning: This unsubscribes ALL of this chain's listeners from this link, not just the one callback event.
|
||||||
//obj.del(map, at); // TODO: Warning: This unsubscribes ALL of this chain's listeners from this link, not just the one callback event.
|
//obj.del(map, at); // TODO: Warning: This unsubscribes ALL of this chain's listeners from this link, not just the one callback event.
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
var obj = Gun.obj, obj_has = obj.has, obj_to = Gun.obj.to;
|
var obj = Gun.obj, obj_has = obj.has, obj_to = Gun.obj.to;
|
||||||
var num_is = Gun.num.is;
|
var num_is = Gun.num.is;
|
||||||
@ -1599,7 +1608,7 @@
|
|||||||
}
|
}
|
||||||
if(cb){
|
if(cb){
|
||||||
(opt = opt || {}).ok = cb;
|
(opt = opt || {}).ok = cb;
|
||||||
opt.cat = at;
|
opt.at = at;
|
||||||
opt.out = {'#': Gun.text.random(9)};
|
opt.out = {'#': Gun.text.random(9)};
|
||||||
gun.get(val, {as: opt});
|
gun.get(val, {as: opt});
|
||||||
opt.async = true; //opt.async = at.stun? 1 : true;
|
opt.async = true; //opt.async = at.stun? 1 : true;
|
||||||
@ -1614,35 +1623,24 @@
|
|||||||
return gun;
|
return gun;
|
||||||
}
|
}
|
||||||
|
|
||||||
function val(msg, ev, to){
|
function val(msg, eve, to){
|
||||||
var opt = this.as, cat = opt.cat, gun = msg.$, coat = gun._, data = coat.put || msg.put, tmp;
|
var opt = this.as, cat = opt.at, gun = msg.$, at = gun._, data = at.put || msg.put, tmp;
|
||||||
if(u === data){
|
if(at.link){
|
||||||
//return;
|
tmp = (cat.root.$.get(at.link)._);
|
||||||
}
|
|
||||||
//if(coat.soul && !(0 < coat.ack)){ return }
|
|
||||||
if(tmp = Gun.node.soul(data) || rel.is(data)){
|
|
||||||
//if(data && data[rel._] && (tmp = rel.is(data))){
|
|
||||||
tmp = (cat.root.$.get(tmp)._);
|
|
||||||
if(u === tmp.put){//} || !(0 < tmp.ack)){
|
if(u === tmp.put){//} || !(0 < tmp.ack)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
data = tmp.put;
|
data = tmp.put;
|
||||||
}
|
}
|
||||||
if(ev.wait){ clearTimeout(ev.wait) }
|
if((tmp = eve.wait) && (tmp = tmp[at.id])){ clearTimeout(tmp) }
|
||||||
//if(!to && (!(0 < coat.ack) || ((true === opt.async) && 0 !== opt.wait))){
|
if(!to && (at.soul || at.link)){
|
||||||
if(!to){
|
tmp = (eve.wait = {})[at.id] = setTimeout(function(){
|
||||||
ev.wait = setTimeout(function(){
|
val.call({as:opt}, msg, eve, tmp || 1);
|
||||||
val.call({as:opt}, msg, ev, ev.wait || 1);
|
|
||||||
}, opt.wait || 99);
|
}, opt.wait || 99);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(cat.has || cat.soul){
|
eve.rid(msg);
|
||||||
if(ev.off()){ return } // if it is already off, don't call again!
|
opt.ok.call(gun || opt.$, data, msg.get);
|
||||||
} else {
|
|
||||||
if((opt.seen = opt.seen || {})[coat.id]){ return }
|
|
||||||
opt.seen[coat.id] = true;
|
|
||||||
}
|
|
||||||
opt.ok.call(msg.$ || opt.$, data, msg.get);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Gun.chain.off = function(){
|
Gun.chain.off = function(){
|
||||||
@ -1682,7 +1680,7 @@
|
|||||||
return gun;
|
return gun;
|
||||||
}
|
}
|
||||||
var obj = Gun.obj, obj_map = obj.map, 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.link;
|
||||||
var empty = {}, noop = function(){}, u;
|
var empty = {}, noop = function(){}, u;
|
||||||
})(USE, './on');
|
})(USE, './on');
|
||||||
|
|
||||||
@ -1691,9 +1689,8 @@
|
|||||||
Gun.chain.map = function(cb, opt, t){
|
Gun.chain.map = function(cb, opt, t){
|
||||||
var gun = this, cat = gun._, chain;
|
var gun = this, cat = gun._, chain;
|
||||||
if(!cb){
|
if(!cb){
|
||||||
//if(chain = cat.each){ return chain }
|
if(chain = cat.each){ return chain }
|
||||||
//cat.each =
|
cat.each = chain = gun.chain();
|
||||||
chain = gun.chain();
|
|
||||||
chain._.nix = gun.back('nix');
|
chain._.nix = gun.back('nix');
|
||||||
gun.on('in', map, chain._);
|
gun.on('in', map, chain._);
|
||||||
return chain;
|
return chain;
|
||||||
|
@ -2829,10 +2829,11 @@ describe('Gun', function(){
|
|||||||
bob.pet = cat;
|
bob.pet = cat;
|
||||||
cat.slave = bob;
|
cat.slave = bob;
|
||||||
gun.on('put', {$: gun, put: Gun.graph.ify(user, s)});
|
gun.on('put', {$: gun, put: Gun.graph.ify(user, s)});
|
||||||
|
//console.debug.i=1;console.log("-------------");
|
||||||
gun.get(s.soul).get('bob').get('pet').get('slave').val(function(data){
|
gun.get(s.soul).get('bob').get('pet').get('slave').val(function(data){
|
||||||
//clearTimeout(done.to);
|
//clearTimeout(done.to);
|
||||||
//setTimeout(function(){
|
//setTimeout(function(){
|
||||||
//console.log("*****************", data);
|
//console.log("*****************", data);return;
|
||||||
expect(data.age).to.be(29);
|
expect(data.age).to.be(29);
|
||||||
expect(data.name).to.be("Bob!");
|
expect(data.name).to.be("Bob!");
|
||||||
expect(Gun.val.link.is(data.pet)).to.ok();
|
expect(Gun.val.link.is(data.pet)).to.ok();
|
||||||
@ -3460,10 +3461,12 @@ describe('Gun', function(){
|
|||||||
//console.log('*****************', key, val);
|
//console.log('*****************', key, val);
|
||||||
expect(val).to.be(undefined);
|
expect(val).to.be(undefined);
|
||||||
done.bzl = true;
|
done.bzl = true;
|
||||||
|
setTimeout(function(){
|
||||||
if(done.fbb && done.t && done.bzl){
|
if(done.fbb && done.t && done.bzl){
|
||||||
if(done.c){ return } done.c = 1;
|
if(done.c){ return } done.c = 1;
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
},100);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -3598,7 +3601,7 @@ describe('Gun', function(){
|
|||||||
|
|
||||||
function run(i){
|
function run(i){
|
||||||
|
|
||||||
console.log("----", i, "----");
|
//console.log("----", i, "----");
|
||||||
//2 === i && (console.debug.i = 1) && console.debug(1, '======= what happens?');
|
//2 === i && (console.debug.i = 1) && console.debug(1, '======= what happens?');
|
||||||
said.set({
|
said.set({
|
||||||
what: i + " Hello world!",
|
what: i + " Hello world!",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user