From 84020c492dea970630616c6e8fafc6d18ec7cca6 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Fri, 26 Feb 2016 12:34:37 -0800 Subject: [PATCH] emit deferred from HAM --- gun.js | 4 +++- lib/wsp.js | 12 ++++++------ package.json | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/gun.js b/gun.js index f948bbf2..45c1882e 100644 --- a/gun.js +++ b/gun.js @@ -392,7 +392,9 @@ Gun.is.node.state.ify([vertex, change, node], field, val); } emit({soul: soul, field: field, value: val, state: state, change: change}); - }, function(vertex, field, val){})(function(){ + }, function(vertex, field, val, state){ + Gun.on('deferred').emit(gun, {soul: soul, field: field, value: val, state: state, change: node}); + })(function(){ emit({soul: soul, change: node}); if(opt.soul){ opt.soul(soul) } if(!(ctx.count -= 1)){ ctx.cb() } diff --git a/lib/wsp.js b/lib/wsp.js index c502dae5..b4384c81 100644 --- a/lib/wsp.js +++ b/lib/wsp.js @@ -126,7 +126,7 @@ tran.get = function(req, cb){ var key = req.url.key , reply = {headers: {'Content-Type': tran.json, rid: req.headers.id, id: gun.wsp.msg()}}; - //console.log(req); + //Gun.log(req); // NTS HACK! SHOULD BE ITS OWN ISOLATED MODULE! // if(req && req.url && req.url.pathname && req.url.pathname.indexOf('gun.nts') >= 0){ return cb({headers: reply.headers, body: {time: Gun.time.is() }}); @@ -138,13 +138,13 @@ cb({headers: reply.headers, body: (err? (err.err? err : {err: err || "Unknown error."}) : list || null ) }) }); } - console.log("GET!", req); + //Gun.log("GET!", req); key = req.body; - console.log("tran.get", key); + //Gun.log("tran.get", key); var opt = {key: false}; //gun.get(key, function(err, node){ (gun.__.opt.wire.get||function(key, cb){cb(null,null)})(key, function(err, node){ - //console.log("tran.get", key, "<---", err, node); + //Gun.log("tran.get", key, "<---", err, node); reply.headers.id = gun.wsp.msg(); if(err || !node){ if(opt.on && opt.on.off){ opt.on.off() } @@ -182,7 +182,7 @@ // This will give you much more fine-grain control over security, transactions, and what not. var reply = {headers: {'Content-Type': tran.json, rid: req.headers.id, id: gun.wsp.msg()}}; if(!req.body){ return cb({headers: reply.headers, body: {err: "No body"}}) } - //console.log("\n\ntran.put ----------------->", req.body); + //Gun.log("\n\ntran.put ----------------->", req.body); if(Gun.is.graph(req.body)){ if(req.err = Gun.union(gun, req.body, function(err, ctx){ // TODO: BUG? Probably should give me ctx.graph if(err){ return cb({headers: reply.headers, body: {err: err || "Union failed."}}) } @@ -193,7 +193,7 @@ (gun.__.opt.wire.put || function(g,cb){cb("No save.")})(ctx.graph, function(err, ok){ if(err){ return cb({headers: reply.headers, body: {err: err || "Failed."}}) } // TODO: err should already be an error object? cb({headers: reply.headers, body: {ok: ok || "Persisted."}}); - //console.log("tran.put <------------------------", ok); + //Gun.log("tran.put <------------------------", ok); }); }).err){ cb({headers: reply.headers, body: {err: req.err || "Union failed."}}) } } else { diff --git a/package.json b/package.json index 2db6a0ae..bbaa0832 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gun", - "version": "0.3.7", + "version": "0.3.8", "description": "Graph engine", "main": "index.js", "scripts": {