fix chain emit & faith

This commit is contained in:
Mark Nadal 2020-03-04 22:58:25 -08:00
parent da7c243fb0
commit 9de7d0f38d
5 changed files with 44 additions and 8 deletions

7
gun.js
View File

@ -799,12 +799,13 @@
var stop = {};
var root = ctx.root, next = root.next||'', put = ctx.put, tmp;
var S = +new Date;
Gun.graph.is(put, function(node, soul){
if(!(tmp = next[soul]) || !tmp.$){ return }
//Gun.graph.is(put, function(node, soul){
for(var soul in put){ var node = put[soul]; // Gun.obj.native() makes this safe.
if(!(tmp = next[soul]) || !tmp.$){ continue }
root.stop = stop; // temporary fix till a better solution?
tmp.on('in', {$: tmp.$, get: soul, put: node});
root.stop = null; // temporary fix till a better solution?
});
}
console.STAT && console.STAT(S, +new Date - S, 'fire');
ctx.DBG && (ctx.DBG.f = +new Date);
if(!(tmp = ctx.out)){ return }

View File

@ -101,7 +101,7 @@
DBG && (DBG.sa = DBG.sa || +new Date);
DBG && (DBG.sal = q.length);
var ack, tmp;
// TODO!!!! CHANGE THIS INTO PUFF!!!!
// TODO!!!! CHANGE THIS INTO PUFF!!!!!!!!!!!!!!!!
for(var id in r.tags){
if(!r.tags.hasOwnProperty(id)){ continue } var tag = r.tags[id];
if((tmp = r.disk[f]) && (tmp = tmp.tags) && tmp[tag]){ continue }
@ -366,7 +366,7 @@
p.disk.$ = json;
console.STAT && (ST = +new Date - S) > 9 && console.STAT(S, ST, 'rad parsed JSON');
DBG && (DBG.rpd = +new Date);
p.map(q, p.ack);
p.map(q, p.ack); // hmmm, v8 profiler can't see into this cause of try/catch?
return;
}catch(e){ tmp = e }
if('{' === data[0]){
@ -382,7 +382,7 @@
//var i = 0, l = q.length, ack;
var S = +new Date;
var err = p.err, data = p.not? u : p.disk;
var i = 0, ack; while(i < 9 && (ack = q[i++])){ ack(err, data, info) }
var i = 0, ack; while(i < 9 && (ack = q[i++])){ ack(err, data, info) } // too much?
console.STAT && console.STAT(S, +new Date - S, 'rad packs', ename(file));
console.STAT && console.STAT(S, i, 'rad packs #', ename(file));
if(!(q = q.slice(i)).length){ return }

View File

@ -23,7 +23,7 @@ function Store(opt){
move(tmp, opt.file+'/'+file, cb);
});
};
store.get = function(file, cb){ var tmp;
store.get = function(file, cb){ var tmp; // this took 3s+?
if(tmp = puts[file]){ cb(u, tmp); return }
fs.readFile(opt.file+'/'+file, function(err, data){
if(err){

8
sea.js
View File

@ -1148,8 +1148,14 @@
var u;
function check(msg){ // REVISE / IMPROVE, NO NEED TO PASS MSG/EVE EACH SUB?
if((msg._||'').faith && (this.as.opt||'').faith && 'function' == typeof msg._){ this.to.next(msg); return }
var eve = this, at = eve.as, put = msg.put, soul = put['#'], key = put['.'], val = put[':'], state = put['>'], id = msg['#'], tmp;
if((msg._||'').faith && (at.opt||'').faith && 'function' == typeof msg._){
SEA.verify(SEA.opt.pack(put), false, function(data){ // this is synchronous if false
put['='] = SEA.opt.unpack(data);
eve.to.next(msg);
});
return
}
var no = function(why){ at.on('in', {'@': id, err: why}) };
//var no = function(why){ msg.ack(why) };
(msg._||'').DBG && ((msg._||'').DBG.c = +new Date);

View File

@ -334,6 +334,35 @@ describe('SEA', function(){
});
})
it('save json', function(done){
user.get('a').get('c').put(JSON.stringify({hello:'world'}), function(ack){
expect(ack.err).to.not.be.ok();
done();
});
})
it('read json', function(done){
user.get('a').get('c').once(function(data){
expect(data).to.be(JSON.stringify({hello:'world'}));
done();
});
})
it('save & read encrypt', function(done){
SEA.encrypt('hi', user._.sea, function(data){
var is = data.slice();
user.get('a').get('d').put(data, function(ack){
expect(ack.err).to.not.be.ok();
setTimeout(function(){
user.get('a').get('d').once(function(data){
expect(data).to.be(is);
done();
});
})
});
})
})
it('refresh login', function(done){
this.timeout(9000);
setTimeout(function(){