try to simplify?

This commit is contained in:
Mark Nadal 2016-10-08 02:33:22 -07:00
parent 4facd22aec
commit da3e644c70
2 changed files with 30 additions and 16 deletions

22
gun.js
View File

@ -915,6 +915,7 @@
}
function get(at, cat){
var soul = at.get[_soul], node = cat.graph[soul], field = at.get[_field];
console.debug(4, 'GET', soul, node, field);
if(node && (!field || obj_has(node, field))){
if(field){
node = Gun.obj.put({_: node._}, field, node[field]);
@ -936,6 +937,7 @@
if(cat.graph){
Gun.obj.map(at.put, ham, {at: at, cat: cat}); // all unions must happen first, sadly.
}
console.debug(6, 'IN', at);
Gun.obj.map(at.put, map, {at: at, cat: cat});
}
function ham(data, key){
@ -1354,6 +1356,8 @@
}
if(get = at.get){
if(!get[_soul]){
console.debug(3, 'out', cat.get);
console.debug(2, 'out', cat.get);
if(obj_has(get, _field)){
get = get[_field];
if((cat.ask = cat.ask || {})[get || node_]){ return }
@ -1438,6 +1442,9 @@
Gun.on.ack(tmp, at);
if(at.err){ return }
};
console.debug(11, 'in', cat.get, change, Gun.obj.copy(cat.ask), cat.next, cat.on('in').s.slice());
console.debug(9, 'in', cat.get, change, Gun.obj.copy(cat.ask), cat.next, cat.on('in').s.slice());
console.debug(7, 'in', cat.get, change, Gun.obj.copy(cat.ask), cat.next, cat.on('in').s.slice());
if(value.call(cat, at, ev)){
return;
}
@ -1454,7 +1461,10 @@
if(cat.proxy){
if(cat.proxy.it === at){
if(!cat.proxy.rel){ return true }
//ev.stun();
console.debug(13, 'values', cat.get, put, Gun.obj.copy(cat.ask), Gun.obj.copy(coat.ask));
ask(cat, Gun.node.soul(put), cat);
console.debug(14, 'values', cat.get, put);
return true;
} // TODO: PERF! Anyway to simplify this?
if(cat.proxy.rel){
@ -1462,7 +1472,9 @@
cat.put = coat.put;
}
// TODO: BUG! This mutated `at` won't effect the original at that was sent via the poly-proxy approach. Meaning what is still cached in the poly-set is not this better/recent/fuller one.
console.debug(12, 'values', cat.get, put, cat.proxy, cat.on('in').s.slice());
cat.on('in', obj_to(at, cat.proxy.it = {get: cat.get || at.get}));
console.debug(15, 'values', cat.get, put, cat.proxy, cat.on('in').s.slice());
}
if(Gun.val.is(put)){
//ask(); // ask?
@ -1502,12 +1514,11 @@
//coat.put = u; // this okay?
tmp = coat.proxy = {rel: rel, ref: coat.root.get(rel)};
tmp.ev = ev; /*tmp.res = ev.stun(rel);*/ tmp.as = coat;
console.debug(10, 'values', cat.get, put, cat.proxy);
tmp.ref.on('in', input, coat);
// TODO: BUG, MAKE SURE NOT TO DO ASK IF ^ IS CACHED SINCE IT WILL ON ITS OWN END.
ask(cat, rel, coat);
if(put !== cat.put){
ev.stun();
}
if(put !== cat.put){ ev.stun() }
return true;
}
function value2(at, ev){
@ -1618,6 +1629,7 @@
return;
}
}
console.debug(8, '---->>', key, data);
if(via.gun === cat.gun){
at.change = data;
at.put = data;
@ -1733,6 +1745,7 @@
var opt = opt || {}, gun = opt.gun = this;
if(opt.change){ opt.change = 1 }
opt.any = cb;
console.debug(1, 'any', gun._.get);
return gun.on('in', any, opt).on('out', {get: opt});
}
function any(at, ev){ var opt = this;
@ -1742,6 +1755,8 @@
//console.log("ooooooooh jolllllly", data);
if(null !== opt['.']){
if(Gun.val.rel.is(cat.put)){
if(cat.ask && cat.ask._ && 0 >= cat.ask._['*']){ return } // TODO: CLEAN UP!!!
console.debug(12, 'ANY!', at, cat);
cat.root.get(tmp).any(function(err,d,k,a,e){e.off()});
return;
}
@ -2169,6 +2184,7 @@
if(!data){ return } // localStorage isn't trustworthy to say "not found".
if(Gun.obj.has(lex, '.')){var tmp = data[lex['.']];data = {_: data._};if(u !== tmp){data[lex['.']] = tmp}}
//console.log('@@@@@@@@@@@@local get', data, at);
console.debug(5, 'get local', data);
gun.Back(-1).on('in', {'@': at['#'], put: Gun.graph.node(data)});
//},100);
}

View File

@ -576,7 +576,6 @@ describe('Gun', function(){
Gun.obj.map(a.node, function(v,f){
//setTimeout(function(){
var emit = {field: 'where', soul: f};
console.log(2, emit);
resume(emit);
//},10);
})
@ -1460,6 +1459,7 @@ describe('Gun', function(){
var gun = Gun();
var check = {};
gun.get('g/n/m/f/l/n/r').map().on(function(v,f){
//console.log("***********", f,v);return;
check[f] = v;
if(check.alice && check.bob && check.alice.PhD){
expect(check.alice.age).to.be(24);
@ -2849,7 +2849,6 @@ describe('Gun', function(){
}
}, s)});
gun.get('change/pointer/point').path('bob').any(function(err, data){
console.log("*********************", data);
if(done.c){
expect(data.age).to.be(30);
expect(data.name).to.be('Bob!');
@ -2865,11 +2864,9 @@ describe('Gun', function(){
done.c=1;
});
setTimeout(function(){
//console.debug.i=1;console.log("---------------------");
gun.get('change/pointer/point').path('bob').put({age: 30});
},400);
});
it('mutate pointer to self deep', function(done){
var s = Gun.state.map();s.soul = 'change/pointer/point/deep';
Gun.on('put', {gun: gun, put: Gun.graph.ify({
@ -2935,7 +2932,7 @@ describe('Gun', function(){
},100);
},400);
});
return;
it('mutate pointer to primitive after any deep', function(done){
var s = Gun.state.map();s.soul = 'change/pointer/to/prime/deep';
Gun.on('put', {gun: gun, put: Gun.graph.ify({
@ -2969,8 +2966,8 @@ describe('Gun', function(){
},100);
},400);
});
it('mutate pointer to another pointer after any', function(done){
return;
it.only('mutate pointer to another pointer after any', function(done){
var s = Gun.state.map();s.soul = 'change/pointer/to/pointer';
Gun.on('put', {gun: gun, put: Gun.graph.ify({
bob: {_: {'#': 'dafssfad'},
@ -2983,10 +2980,11 @@ describe('Gun', function(){
}
}, s)});
var bob = gun.get('dafssfad').any(function(err, data){
//console.log("***", data);
console.log("***", data);
});
console.debug.i=1;console.log("--------------------");
gun.get('change/pointer/to/pointer').path('bob').any(function(err, data){
//console.log("*********", data);
console.log("*********", data);return;
if(done.soul && done.soul !== Gun.node.soul(data)){
expect(Gun.node.soul(data)).to.be('fsdaadsf');
expect(data.cat).to.be(true);
@ -3002,7 +3000,7 @@ describe('Gun', function(){
expect(data.name).to.be('Bob!');
expect(Gun.val.rel.is(data.pet)).to.be.ok();
});
return;
setTimeout(function(){
gun.get('change/pointer/to/pointer').path('bob').put(Gun.node.ify({cat: true}, 'fsdaadsf'));
setTimeout(function(){
@ -3010,8 +3008,8 @@ describe('Gun', function(){
},100);
},400);
});
it('deep freeze put', function(done){
return;
it.only('deep freeze put', function(done){
gun.get('deep/freeze').put({
bob: {
age: 29,
@ -3060,7 +3058,7 @@ describe('Gun', function(){
done();
});
});
return;
it('put put put put', function(){
var gun = Gun();
var get = gun.get('put/put/put/put');