ask for things

This commit is contained in:
Mark Nadal 2017-10-30 07:19:18 -07:00
parent e92aae7b55
commit 4c8b679c4c
2 changed files with 35 additions and 9 deletions

7
gun.js
View File

@ -932,6 +932,7 @@
if(get['.']){
if(at.get){
msg = {get: {'.': at.get}, gun: at.gun};
(back.ask || (back.ask = {}))[at.get] = msg.gun; // TODO: PERFORMANCE? More elegant way?
return back.on('out', msg);
}
msg = {get: {}, gun: at.gun};
@ -941,6 +942,7 @@
if(at.get){
msg.gun = at.gun;
get['.'] = at.get;
(back.ask || (back.ask = {}))[at.get] = msg.gun; // TODO: PERFORMANCE? More elegant way?
return back.on('out', msg);
}
}
@ -1102,14 +1104,15 @@
if(at.ack){
//tmp.ack = tmp.ack || -1;
tmp.on('out', {get: {'#': soul}});
return;
if(!at.ask){ return } // TODO: PERFORMANCE? More elegant way?
}
obj_map(at.next, function(gun, key){
obj_map(at.ask || at.next, function(gun, key){
//(tmp.gun.get(key)._).on('out', {get: {'#': soul, '.': key}});
//tmp.on('out', {get: {'#': soul, '.': key}});
(gun._).on('out', {get: {'#': soul, '.': key}});
//at.on('out', {get: {'#': soul, '.': key}});
});
Gun.obj.del(at, 'ask'); // TODO: PERFORMANCE? More elegant way?
}
function ack(msg, ev){
var as = this.as, get = as.get || empty, at = as.gun._;

View File

@ -3578,8 +3578,7 @@ describe('Gun', function(){
});
});
it('Nested listener should be called does it?', function(done){
it('If chain cannot be called, ack', function(done){
var gun = Gun(), u;
gun.on('put', {gun: gun, put: Gun.graph.ify({
@ -3595,21 +3594,45 @@ describe('Gun', function(){
done.a = 1;
});
//console.debug.i=1;console.log('-------------------');
app.get('a').get('b').get(function(d){
expect(d.put).to.be(u);
expect(done.a).to.be.ok();
if(done.c){ return }
done(); done.c = 1;
});
window.app = app;
return;
});
it('Chain on known nested object should ack', function(done){
var gun = Gun(), u;
gun.on('put', {gun: gun, put: Gun.graph.ify({
bar: {
wat: 1
}
}, 'nl/app')});
var app = gun.get('nl/app').get('bar');
app.get(function(d){
//console.log("!!", d.put);
if(!d || !d.put || !d.put.wat){ return }
expect(d.put.wat).to.be(1);
done.a = 1;
});
app.get('a').get('b').get(function(d){
//console.log("????", d.put);
expect(d.put).to.be(u);
expect(done.a).to.be.ok();
if(done.c){ return }
done(); done.c = 1;
});
});
return;
it('Nested listener should be called', function(done){
var gun = Gun();
/*
var app = gun.get('nl/app').get('bar');
app.on(function(d){
@ -3622,7 +3645,7 @@ describe('Gun', function(){
console.log(gun._.now);
app.put({a: {b:2}});
console.log('_______________________');
return;
return;*/
var app = gun.get('nl/app');
var node = app.get('watcher/1').put({"stats":{"num":3},"name":"trex"});