gun/src/onto.js
Mark Nadal 638c2c3c23 have unbuild function wrap to prevent scope leaks & allow RETURN hehehe so I can reject @bmatusiak 's lS change O:) O:) I love you you're a hero!
later with @bmatusiak check sea.then for '../gun.js' vs '../' vs ...
note: src/index -> core.js
TODO: something about WebRTC candidates hitting ack decrement limits?
2024-01-17 10:13:00 -08:00

38 lines
918 B
JavaScript

;(function(){
// On event emitter generic javascript utility.
module.exports = function onto(tag, arg, as){
if(!tag){ return {to: onto} }
var u, f = 'function' == typeof arg, tag = (this.tag || (this.tag = {}))[tag] || f && (
this.tag[tag] = {tag: tag, to: onto._ = { next: function(arg){ var tmp;
if(tmp = this.to){ tmp.next(arg) }
}}});
if(f){
var be = {
off: onto.off ||
(onto.off = function(){
if(this.next === onto._.next){ return !0 }
if(this === this.the.last){
this.the.last = this.back;
}
this.to.back = this.back;
this.next = onto._.next;
this.back.to = this.to;
if(this.the.last === this.the){
delete this.on.tag[this.the.tag];
}
}),
to: onto._,
next: arg,
the: tag,
on: this,
as: as,
};
(be.back = tag.last || tag).to = be;
return tag.last = be;
}
if((tag = tag.to) && u !== arg){ tag.next(arg) }
return tag;
};
}());