This commit is contained in:
Mark Nadal 2018-02-19 16:55:26 -08:00
parent 67201a17b8
commit 16d9a42ff8
2 changed files with 0 additions and 95 deletions

View File

@ -1,45 +0,0 @@
;(function(exports){ // On event emitter generic javascript utility.
function On(){ var on = this;
if(!On.is(on)){ return new On() }
return function(e, fn, i){ return on.e = e, fn? on.event(fn, i) : on };
};
On.is = function(on){ return (on instanceof On) }
On.chain = On.prototype;
On.chain.create = function(){ return On.call(null) }
var on = function(e){
on.event.e = e;
on.event.s[e] = on.event.s[e] || [];
return on;
};
On.chain.emit = function(a,b,c,d){
var on = this, e = on.e, s = on.s[e];
exports.list.map(s, function(at, i){ at.on(a,b,c,d) });
if(s && !s.length){ delete on.s[e] }
}
function At(fn, i){ var at = this;
if(!At.is(at)){ return new At() }
at.on = fn;
at.i = i; // TODO: MARK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! COME BACK HERE!
};
At.is = function(at){ return (at instanceof At) }
On.chain = On.prototype;
On.chain.event = function(fn, i){
//on.event = function(fn, i){
var on = this, e = on.e, s = on.s[e] = on.s[e] || [], at = At(fn, i);
var e = {fn: fn, i: i || 0, off: function(){ return !(e.fn = false) }}; // TODO: PERFORMANCE! Prototype-ify this and reduce any on complexity.
return s.push(e), i? s.sort(sort) : i, e;
}
//on.event.s = {};
//return on;
var sort = exports.list.sort('i');
exports.on = On; //On();
}(Gun || {}));
/*
on('foo', function(){
})
on('foo').emit('yay');*/

View File

@ -1,50 +0,0 @@
function input(msg){
var ev = this, cat = this.as, gun = msg.gun, at = gun._, change = msg.put, rel, tmp;
// dispatch to chain listeners.
// dispatch to children.
// dispatch to echoes.
if(u === change){
// Here are the possible options:
// 1. We think the data does not exist because peers/disk cannot find it.
// 2. We know the data does not exist because a parent is or was changed to a primitive.
// Souls can only (1) because they have no parent.
// Has can be (1) or (2).
// Gets and chains can be (1) or (2).
if(cat.soul || cat.has){
// a soul can never become undefined.
// a soul can only not be found.
if(cat.soul && u !== cat.put){
return;
}
// a key may sometimes might not be found.
// a key on a soul can not become undefined,
// but the chain might be on a chain that
// does not exist, and therefore can be undefined.
ev.to.next(msg); // ex, notify val and stuff.
echo(cat, msg, ev); // ex, notify a sub-object pointer like `mark.pet`! // TODO: BUG ON VAL, it will still not get called because it checks !node when it should also check ack.
if(cat.soul){ return }
obj_map(cat.next, unknown); // notify children.
}
if(cat.has){
if()
}
return;
}
if(cat.soul){
return;
}
if(cat.has){
return;
}
if(cat.get){
return;
}
ev.to.next(msg);
}
function unknown(ref, key){
(ref = (ref._)).put = u;
ref.on('in', {get: key, put: u, gun: ref.gun});
}
gun.get('users').map().map().get('who').get('say').map().on(cb);