From 656019e674602cc2cf57bb7c3fc2a814a3c731ac Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Wed, 25 May 2016 14:10:29 -0700 Subject: [PATCH] use hidden back, turn off null listeners --- gun.js | 9 +++++---- package.json | 2 +- test/common.js | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/gun.js b/gun.js index 8aeb6fe5..5fc45ec2 100644 --- a/gun.js +++ b/gun.js @@ -629,7 +629,7 @@ cb.call(chain, null); // This is in memory success, hardly "success" at all. } if(ctx.field){ - return gun.back.path(ctx.field, null, {chain: opt.chain || chain}); + return gun._.back.path(ctx.field, null, {chain: opt.chain || chain}); } if(ctx.not){ return gun.__.gun.get(ctx.soul, null, {chain: opt.chain || chain}); @@ -643,13 +643,13 @@ } else { // else if we are on an existing chain then... gun._.at('soul').map(put); // put data on every soul that flows through this chain. var back = function(gun){ - if(back.get || gun.back === gun || gun._.not){ return } // TODO: CLEAN UP! Would be ideal to accomplish this in a more ideal way. + if(back.get || gun._.back === gun || gun._.not){ return } // TODO: CLEAN UP! Would be ideal to accomplish this in a more ideal way. if(gun._.get){ back.get = true } - gun._.at('null').event(function(at){ + gun._.at('null').event(function(at){ this.off(); if(opt.init || gun.__.opt.init){ return Gun.log("Warning! You have no context to `.put`", val, "!") } gun.init(); }, -999); - return back(gun.back); + return back(gun._.back); }; if(!opt.init && !gun.__.opt.init){ back(gun) } } @@ -1004,6 +1004,7 @@ gun._.at('null').event(function(at){ if(!at.not){ return } // TODO: BUG! This check is synchronous but it could be asynchronous! var ctx = {by: gun.__.by(at.soul)}; + this.off(); if(at.field){ if(Gun.obj.has(ctx.by.node, at.field)){ return } gun._.at('soul').emit({soul: at.soul, field: at.field, not: true}); diff --git a/package.json b/package.json index aebf1f1e..57caac27 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gun", - "version": "0.3.91", + "version": "0.3.92", "description": "Graph engine", "main": "index.js", "scripts": { diff --git a/test/common.js b/test/common.js index f1914924..c934c4ba 100644 --- a/test/common.js +++ b/test/common.js @@ -3972,6 +3972,33 @@ describe('Gun', function(){ }); },100); }); + + it("Don't put on parents", function(done){ // TODO: ADD TO 0.5 BRANCH! // Another Stefdv find. + var test = gun.get('test'); + test.path('try.this.at.lvl4').put({msg:'hoi'}) + test.val(function(node,b){ + delete node._; + expect(Gun.obj.empty(node, 'try')).to.be.ok(); + node = Gun.obj.copy(gun.__.graph[Gun.is.rel(node.try)]); + + delete node._; + expect(Gun.obj.empty(node, 'this')).to.be.ok(); + node = Gun.obj.copy(gun.__.graph[Gun.is.rel(node.this)]); + + delete node._; + expect(Gun.obj.empty(node, 'at')).to.be.ok(); + node = Gun.obj.copy(gun.__.graph[Gun.is.rel(node.at)]); + + delete node._; + expect(Gun.obj.empty(node, 'lvl4')).to.be.ok(); + node = Gun.obj.copy(gun.__.graph[Gun.is.rel(node.lvl4)]); + + delete node._; + expect(Gun.obj.empty(node, 'msg')).to.be.ok(); + expect(node.msg).to.be('hoi'); + done(); + }); + }); }); describe('Streams', function(){