From ee04f3a9cd7c6002bc004d001b16a0394ac687a2 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Mon, 20 Jul 2015 15:00:26 -0700 Subject: [PATCH 1/2] new branch --- .gitignore | 4 +++- gun.js | 1 + test/common.js | 13 +++++++++++++ web/img/Thumbs.db | Bin 101376 -> 101376 bytes 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5a1e39c8..b200f1e9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ node_modules/* npm-debug.log *data.json *.db -.idea/ \ No newline at end of file +.idea/ +*.bak +*.new \ No newline at end of file diff --git a/gun.js b/gun.js index 349b27fa..141b747d 100644 --- a/gun.js +++ b/gun.js @@ -559,6 +559,7 @@ if(!opt.end && Gun.obj.empty(delta, Gun._.meta)){ return } if($$.key){ node = Gun.union.pseudo($.key, gun.__.key.s[$.key]) || 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); })(gun.__.graph[$.soul], $); if(!opt.once){ gun.__.on($.soul).event(ctx[$.soul]) } diff --git a/test/common.js b/test/common.js index dbcc5f10..16e177d1 100644 --- a/test/common.js +++ b/test/common.js @@ -1836,6 +1836,19 @@ describe('Gun', function(){ }); }) }); + + it("gun put null path on put sub object", function(done){ // consensus4's bug + var gun = Gun(); + //Gun.log.verbose = true; + var game = gun.put({board: null, teamA: null, teamB: null, turn: null}).key('the/game'); + game.path('board').on(function(board){ + console.log("board updated", board); + }); + setTimeout(function(){ + //game.path('board').put({11: ' ', 22: ' ', 33: 'A'}); + game.put({board: {11: ' ', 22: ' ', 33: 'A'}}); + },100); + }); }); describe('Streams', function(){ diff --git a/web/img/Thumbs.db b/web/img/Thumbs.db index 2699a75fbf374d99c87c127f76d9902e307b44ce..a146854d9b9259083411bec826b5daeee03ebcda 100644 GIT binary patch delta 123 zcmZpe!PYQ?Z9@(Vn}OEl6tDf8i&*BdaxU$ViFw=BxVK+{Je42n z94=qJvG{bqo3dHL=Z7Xo(}ZJU(cx|XH%pXNFmu#Y_s&q=yl~;91{^KgQK>6}9{lNTywY^oAq;_xw2 X`Wc+naCfsr&5y@$>Fp8;j4!kSEL<|b From 4f5f4839560d9ce062c38aa7facf54dd81412c5b Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Mon, 20 Jul 2015 17:49:02 -0700 Subject: [PATCH 2/2] fix consensus4 bug --- gun.js | 14 +++++++++++--- test/common.js | 16 +++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/gun.js b/gun.js index 141b747d..dc1fb76b 100644 --- a/gun.js +++ b/gun.js @@ -553,13 +553,21 @@ } } else { (ctx[$.soul] = function(delta, $$){ - $$ = $$ || $; var node = gun.__.graph[$$.soul]; - if(delta && $.soul != Gun.is.soul.on(delta)){ return } + $$ = $$ || $; var node = gun.__.graph[$$.soul], soul; + 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.end && Gun.obj.empty(delta, Gun._.meta)){ return } if($$.key){ node = Gun.union.pseudo($.key, gun.__.key.s[$.key]) || 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); })(gun.__.graph[$.soul], $); if(!opt.once){ gun.__.on($.soul).event(ctx[$.soul]) } diff --git a/test/common.js b/test/common.js index 16e177d1..e004705f 100644 --- a/test/common.js +++ b/test/common.js @@ -1838,14 +1838,24 @@ describe('Gun', function(){ }); it("gun put null path on put sub object", function(done){ // consensus4's bug + done.c = 1; var gun = Gun(); //Gun.log.verbose = true; var game = gun.put({board: null, teamA: null, teamB: null, turn: null}).key('the/game'); - game.path('board').on(function(board){ - console.log("board updated", board); + game.path('board').on(function(board, field){ + 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(){ - //game.path('board').put({11: ' ', 22: ' ', 33: 'A'}); + done.c++; game.put({board: {11: ' ', 22: ' ', 33: 'A'}}); },100); });