From a0a5be519a3123e13aac7b16207217b51d90c9a5 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Mon, 26 Sep 2016 22:43:50 -0700 Subject: [PATCH 1/4] Update gun.js --- gun.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gun.js b/gun.js index 22550fb9..d2d92298 100644 --- a/gun.js +++ b/gun.js @@ -938,9 +938,12 @@ var soul = at.get[_soul], node = cat.graph[soul], field = at.get[_field]; if(node && (!field || obj_has(node, field))){ // TODO: BUG!!! Shouldn't this ack????? + if(field){ + node = Gun.obj.put({_: node._}, field, node[field]); + } cat.on('in', { - put: Gun.graph.node(node), // TODO: BUG! Clone node! - get: soul + '@': at.req? at['#'] : 0, // temporary hack + put: Gun.graph.node(node) // TODO: BUG! Clone node! }); return; } @@ -2058,7 +2061,7 @@ '$': at.get // msg BODY }; Tab.on(msg['#'], function(err, data){ // TODO: ONE? PERF! Clear out listeners, maybe with setTimeout? - at.gun.Back(-1).on('in', {'@': at['#'], err: err, put: Gun.graph.node(data)}); + at.gun.Back(-1).on('in', {'@': at['#'], err: err, put: data}); }); Tab.peers(peers).send(msg, {headers: {'gun-sid': Tab.server.sid}}); }); From 347ac0ff37e3a2074a6f381613f11ba178f1aaf3 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Mon, 26 Sep 2016 22:50:35 -0700 Subject: [PATCH 2/4] Update wsp.js --- lib/wsp.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/wsp.js b/lib/wsp.js index 7a3c0975..0e3754b9 100644 --- a/lib/wsp.js +++ b/lib/wsp.js @@ -147,13 +147,14 @@ } tran.get = function(req, cb){ var body = req.body, lex = body['$'], reply = {headers: {'Content-Type': tran.json}}, opt; - gun.get(lex, function(err, node, key, at, ev){ + gun.on('out', {gun: gun, get: lex, req: 1, '#': Gun.on.ask(function(at, ev){ ev.off(); + var graph = at.put; return cb({headers: reply.headers, body: { '#': gun.wsp.msg(), '@': body['#'], - '$': node, - '!': err + '$': graph, + '!': at.err }}); return; if(Gun.obj.empty(node)){ @@ -180,7 +181,7 @@ }([])); */ cb({headers: reply.headers, chunk: node }); // Use this if you don't want streaming chunks feature. - }, opt); + })}); } tran.put = function(req, cb){ //console.log("tran.put", req); @@ -225,4 +226,4 @@ wsp(opt.server); } }); -}({})); \ No newline at end of file +}({})); From 05bb232d4dae45cf5f2d5e375c0dadbeecf10124 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Tue, 27 Sep 2016 11:32:36 -0700 Subject: [PATCH 3/4] put now accepts refs again --- gun.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gun.js b/gun.js index d2d92298..11e41338 100644 --- a/gun.js +++ b/gun.js @@ -1142,6 +1142,15 @@ ify(as); return gun; } + if(Gun.is(data)){ + data.any(function(e,d,k,at,ev){ + ev.off(); + var s = Gun.node.soul(d); + if(!s){Gun.log("Can only save a node, not a property.");return} + gun.put(Gun.val.rel.ify(s), cb, opt); + }); + return gun; + } as.ref = as.ref || (root === (tmp = gun.Back(1)))? gun : tmp; as.ref.any(any, {as: as, '.': null}); if(!as.out){ From f748ef0308bbbce06a1871bd7e25d51b9c79fccd Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Tue, 27 Sep 2016 11:40:20 -0700 Subject: [PATCH 4/4] add set back in for @stefdv --- gun.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gun.js b/gun.js index 11e41338..848e8968 100644 --- a/gun.js +++ b/gun.js @@ -2008,6 +2008,18 @@ return this.Back(-1).put(Gun.node.ify({}, this._.get), null, this._.get); } }()); + + ;(function(){ + Gun.chain.set = function(item, cb, opt){ + var gun = this; + cb = cb || function(){}; + return item.val(function(node){ + var put = {}, soul = Gun.node.soul(node); + if(!soul){ return cb.call(gun, {err: Gun.log('Only a node can be linked! Not "' + node + '"!')}) } + gun.put(Gun.obj.put(put, soul, Gun.val.rel.ify(soul)), cb, opt); + }); + } + }()); })(require, './src/api'); }());