neo-neo-bblessed
Version:
A fork of neo-blessed (which is a fork of blessed) with bug fixes and maintenance.
3 lines (2 loc) • 1.67 kB
JavaScript
const a=Array.prototype.slice;function r(){this._events||(this._events={})}r.prototype.setMaxListeners=function(e){this._maxListeners=e},r.prototype.addListener=function(e,t){this._events[e]?typeof this._events[e]=="function"?this._events[e]=[this._events[e],t]:this._events[e].push(t):this._events[e]=t,this._emit("newListener",[e,t])},r.prototype.on=r.prototype.addListener,r.prototype.removeListener=function(e,t){const n=this._events[e];if(!n)return;if(typeof n=="function"||n.length===1){delete this._events[e],this._emit("removeListener",[e,t]);return}const s=n;for(let i=0;i<s.length;i++)if(s[i]===t||s[i].listener===t){s.splice(i,1),this._emit("removeListener",[e,t]);return}},r.prototype.off=r.prototype.removeListener,r.prototype.removeAllListeners=function(e){e?delete this._events[e]:this._events={}},r.prototype.once=function(e,t){const n=this;function s(...i){return n.removeListener(e,s),t.apply(this,i)}return s.listener=t,this.on(e,s)},r.prototype.listeners=function(e){const t=this._events[e];return typeof t=="function"?[t]:t||[]},r.prototype._emit=function(e,t){const n=this._events[e];let s;if(!n){if(e==="error")throw new t[0];return}if(typeof n=="function")return n.apply(this,t);const i=n;for(let o=0;o<i.length;o++)i[o].apply(this,t)===!1&&(s=!1);return s!==!1},r.prototype.emit=function(e,...t){const n=a.call(arguments,1),s=a.call(arguments);let i=this;if(this._emit("event",s),this.type==="screen")return this._emit(e,n);if(this._emit(e,n)===!1)return!1;const o="element "+e;n.unshift(this);do if(i._events[o]&&i._emit(o,n)===!1)return!1;while(i=i.parent);return!0};const f=r;f.EventEmitter=r,module.exports=f;
//# sourceMappingURL=events.js.map