From 515011833209d084df05bb2e4d5a4bf2fc680dc1 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Wed, 17 Sep 2014 14:18:41 -0700 Subject: [PATCH] team, hooks, text.ify --- examples/admin/index.html | 1 + gun.js | 22 +++++++++++----------- shots.js | 22 +++++++++++----------- web/deck/index.html | 2 +- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/examples/admin/index.html b/examples/admin/index.html index 0d84f5b2..4cd198de 100644 --- a/examples/admin/index.html +++ b/examples/admin/index.html @@ -76,6 +76,7 @@ scope.$data.path(scope.key).set( scope.data[scope.key] = elem.text() ); + // scope.$apply(); }); }; }); diff --git a/gun.js b/gun.js index ab826009..5fcef772 100644 --- a/gun.js +++ b/gun.js @@ -23,10 +23,10 @@ if(Gun.list.is(opt.peers)){ opt.peers = Gun.obj.map(opt.peers, function(n,f,m){ m(n,{}) }) } gun.__.opt.peers = opt.peers || gun.__.opt.peers || {}; gun.__.opt.uuid = opt.uuid || gun.__.opt.uuid || {}; - gun.__.opt.hook = gun.__.opt.hook || {}; - Gun.obj.map(opt.hook, function(h, f){ + gun.__.opt.hooks = gun.__.opt.hooks || {}; + Gun.obj.map(opt.hooks, function(h, f){ if(!Gun.fns.is(h)){ return } - gun.__.opt.hook[f] = h; + gun.__.opt.hooks[f] = h; }); if(!stun){ Gun.on('opt').emit(gun, opt) } return gun; @@ -54,8 +54,8 @@ cb.fn = function(){} gun._.key = key; // missing: hear shots! - if(Gun.fns.is(gun.__.opt.hook.load)){ - gun.__.opt.hook.load(key, function(err, data){ + if(Gun.fns.is(gun.__.opt.hooks.load)){ + gun.__.opt.hooks.load(key, function(err, data){ gun._.loaded = (gun._.loaded || 0) + 1; // TODO: loading should be idempotent even if we got an err or no data if(err){ return (gun._.dud||cb.fn)(err) } if(!data){ return (gun._.blank||cb.fn)() } @@ -77,8 +77,8 @@ Gun.log("make key", key); cb = cb || function(){}; this.__.keys[key] = this._.node; - if(Gun.fns.is(this.__.opt.hook.key)){ - this.__.opt.hook.key(key, this._.node, function(err, data){ + if(Gun.fns.is(this.__.opt.hooks.key)){ + this.__.opt.hooks.key(key, this._.node, function(err, data){ Gun.log("key made", key); if(err){ return cb(err) } return cb(null); @@ -157,8 +157,8 @@ if(set.err){ return cb(set.err), gun } Gun.union(gun.__.nodes, set.nodes); // while this maybe should return a list of the nodes that were changed, we want to send the actual delta gun._.node = gun.__.nodes[cb.root._[own.sym.id]] || cb.root; // TODO? Maybe BUG! if val is a new node on a field, _.node should now be that! Or will that happen automatically? - if(Gun.fns.is(gun.__.opt.hook.set)){ - gun.__.opt.hook.set(set.nodes, function(err, data){ // now iterate through those nodes to S3 and get a callback once all are saved + if(Gun.fns.is(gun.__.opt.hooks.set)){ + gun.__.opt.hooks.set(set.nodes, function(err, data){ // now iterate through those nodes to S3 and get a callback once all are saved //Gun.log("gun set hook callback called"); if(err){ return cb(err) } return cb(null); @@ -850,7 +850,7 @@ } return opt; } - gun.__.opt.hook.load = gun.__.opt.hook.load || tab.load; - gun.__.opt.hook.set = gun.__.opt.hook.set || tab.set; + gun.__.opt.hooks.load = gun.__.opt.hooks.load || tab.load; + gun.__.opt.hooks.set = gun.__.opt.hooks.set || tab.set; }); }({})); \ No newline at end of file diff --git a/shots.js b/shots.js index 961da94a..5849ba76 100644 --- a/shots.js +++ b/shots.js @@ -23,7 +23,7 @@ msg.headers = req.headers; msg.body = req.body; // TODO: include body-parser here? if('get' === msg.method){ // get is used as subscribe - gun.__.opt.hook.sub(msg, function(reply){ + gun.__.opt.hooks.sub(msg, function(reply){ if(!res){ return } if(!reply){ return res.end() } if(reply.headers){ @@ -56,8 +56,8 @@ /* WARNING! TODO: BUG! Do not send OK confirmation if amnesiaQuaratine is activated! Not until after it has actually been processed!!! */ - if(Gun.fns.is(gun.__.opt.hook.set)){ - gun.__.opt.hook.set(context.nodes, function(err, data){ // now iterate through those nodes to S3 and get a callback once all are saved + if(Gun.fns.is(gun.__.opt.hooks.set)){ + gun.__.opt.hooks.set(context.nodes, function(err, data){ // now iterate through those nodes to S3 and get a callback once all are saved if(err){ return meta.JSON(res, {err: err}); // server should handle the error for the client first! Not force client to re-attempt. } @@ -261,12 +261,12 @@ return sub; }()); - opt.hook = opt.hook || {}; - gun.opt({hook: { - load: opt.hook.load || s3.load - ,set: opt.hook.set || s3.set - ,key: opt.hook.key || s3.key - ,sub: opt.hook.sub || gun.server.sub + opt.hooks = opt.hooks || {}; + gun.opt({hooks: { + load: opt.hooks.load || s3.load + ,set: opt.hooks.set || s3.set + ,key: opt.hooks.key || s3.key + ,sub: opt.hooks.sub || gun.server.sub }}, true); }); meta.json = 'application/json'; @@ -275,10 +275,10 @@ res.setHeader('Content-Type', meta.json); } if(!data && multi){ - res.write(JSON.stringify(multi||'')+'\n'); + res.write(Gun.text.ify(multi||'')+'\n'); return; } - return res.end(JSON.stringify(data||'')); + return res.end(Gun.text.ify(data||'')); }; meta.CORS = function(req, res){ if(!res || res.CORSHeader || res._headerSent){ return } diff --git a/web/deck/index.html b/web/deck/index.html index 30a180b1..a168a11e 100644 --- a/web/deck/index.html +++ b/web/deck/index.html @@ -97,7 +97,7 @@ AJ ONeal CIO, 8 years experience with Software and Database Architecture.
- Core contributor to NodeJS, + Contributor to NodeJS core, in the top 1 percentile rank of all StackOverflow users, built a Billboard Hot 100 rap artist's Twitter feed client.