mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
team, hooks, text.ify
This commit is contained in:
parent
6418ce4c81
commit
5150118332
@ -76,6 +76,7 @@
|
||||
scope.$data.path(scope.key).set(
|
||||
scope.data[scope.key] = elem.text()
|
||||
);
|
||||
// scope.$apply();
|
||||
});
|
||||
};
|
||||
});
|
||||
|
22
gun.js
22
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;
|
||||
});
|
||||
}({}));
|
22
shots.js
22
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 }
|
||||
|
@ -97,7 +97,7 @@
|
||||
<b>AJ ONeal</b>
|
||||
CIO, 8 years experience with Software and Database Architecture.
|
||||
<div class="small">
|
||||
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.
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user