fix consensus4 bug

This commit is contained in:
Mark Nadal 2015-07-20 17:49:02 -07:00
parent ee04f3a9cd
commit 4f5f483956
2 changed files with 24 additions and 6 deletions

14
gun.js
View File

@ -553,13 +553,21 @@
} }
} else { } else {
(ctx[$.soul] = function(delta, $$){ (ctx[$.soul] = function(delta, $$){
$$ = $$ || $; var node = gun.__.graph[$$.soul]; $$ = $$ || $; var node = gun.__.graph[$$.soul], soul;
if(delta && $.soul != Gun.is.soul.on(delta)){ return } if(delta && $$.soul != Gun.is.soul.on(delta)){ return }
if($$.field && (soul = Gun.is.soul(node[$$.field]))){
(ctx[$$.soul + $$.field] || {off:function(){}}).off();
ctx[$$.soul + $$.field] = gun.__.on(soul).event(function(delta){
ctx[$.soul](delta, {soul: soul, field: null, at: $.field});
});
// TODO: do we need to load it? what about that $.gun context?
return;
}
if(opt.raw){ return cb.call($$.gun || gun, $$, delta, this) } if(opt.raw){ return cb.call($$.gun || gun, $$, delta, this) }
if(!opt.end && Gun.obj.empty(delta, Gun._.meta)){ return } if(!opt.end && Gun.obj.empty(delta, Gun._.meta)){ return }
if($$.key){ node = Gun.union.pseudo($.key, gun.__.key.s[$.key]) || node } if($$.key){ node = Gun.union.pseudo($.key, gun.__.key.s[$.key]) || node }
if(opt.change){ node = delta || node } if(opt.change){ node = delta || node }
//root.console.log("ON IT BABY!", $$, node);
cb.call($$.gun || gun, Gun.obj.copy($$.field? node[$$.field] : node), $$.field || $$.at); cb.call($$.gun || gun, Gun.obj.copy($$.field? node[$$.field] : node), $$.field || $$.at);
})(gun.__.graph[$.soul], $); })(gun.__.graph[$.soul], $);
if(!opt.once){ gun.__.on($.soul).event(ctx[$.soul]) } if(!opt.once){ gun.__.on($.soul).event(ctx[$.soul]) }

View File

@ -1838,14 +1838,24 @@ describe('Gun', function(){
}); });
it("gun put null path on put sub object", function(done){ // consensus4's bug it("gun put null path on put sub object", function(done){ // consensus4's bug
done.c = 1;
var gun = Gun(); var gun = Gun();
//Gun.log.verbose = true; //Gun.log.verbose = true;
var game = gun.put({board: null, teamA: null, teamB: null, turn: null}).key('the/game'); var game = gun.put({board: null, teamA: null, teamB: null, turn: null}).key('the/game');
game.path('board').on(function(board){ game.path('board').on(function(board, field){
console.log("board updated", board); expect(field).to.be('board');
if(done.c == 1){
expect(board).to.not.be.ok();
}
if(done.c === 2){
done.c++;
delete board._;
expect(board).to.be.eql({11: ' ', 22: ' ', 33: 'A'});
done();
}
}); });
setTimeout(function(){ setTimeout(function(){
//game.path('board').put({11: ' ', 22: ' ', 33: 'A'}); done.c++;
game.put({board: {11: ' ', 22: ' ', 33: 'A'}}); game.put({board: {11: ' ', 22: ' ', 33: 'A'}});
},100); },100);
}); });