awv3
Version:
AWV client CAD framework
1 lines • 4.78 kB
JavaScript
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}exports.__esModule=!0;var _promise=require("babel-runtime/core-js/promise"),_promise2=_interopRequireDefault(_promise),_typeof2=require("babel-runtime/helpers/typeof"),_typeof3=_interopRequireDefault(_typeof2),_getIterator2=require("babel-runtime/core-js/get-iterator"),_getIterator3=_interopRequireDefault(_getIterator2),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),Events=function(){function e(){(0,_classCallCheck3["default"])(this,e),this._callbacks=void 0,this._inspectors=void 0}return e.prototype.once=function(e,t){this.on(e,t,!0)},e.prototype.on=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=arguments.length<=1||void 0===arguments[1]?void 0:arguments[1],r=!(arguments.length<=2||void 0===arguments[2])&&arguments[2];if(this._callbacks||(this._callbacks={}),Array.isArray(e)||"string"==typeof e&&"function"==typeof t)for(var a=Array.isArray(e)?e:[e],i=a,o=Array.isArray(i),s=0,i=o?i:(0,_getIterator3["default"])(i);;){var n;if(o){if(s>=i.length)break;n=i[s++]}else{if(s=i.next(),s.done)break;n=s.value}var l=n,c=this._callbacks[l];if(c||(c=this._callbacks[l]=[]),c.indexOf(t)<0&&(t.remove=r,c.push(t),this._inspectors))for(var f=this._inspectors,p=Array.isArray(f),u=0,f=p?f:(0,_getIterator3["default"])(f);;){var v;if(p){if(u>=f.length)break;v=f[u++]}else{if(u=f.next(),u.done)break;v=u.value}var h=v;h({action:"Add",type:l,callback:t})}}else if("object"===("undefined"==typeof e?"undefined":(0,_typeof3["default"])(e))&&void 0===t)for(var b in e){var _=e[b];"function"==typeof _&&this.on(b,_,r)}return this},e.prototype.inspect=function(e){this._inspectors||(this._inspectors=[]),this._inspectors.push(e)},e.prototype.removeListener=function(e,t){this._callbacks||(this._callbacks={}),e=Array.isArray(e)?e:[e];for(var r=e,a=Array.isArray(r),i=0,r=a?r:(0,_getIterator3["default"])(r);;){var o;if(a){if(i>=r.length)break;o=r[i++]}else{if(i=r.next(),i.done)break;o=i.value}var s=o,n=this._callbacks[s];if(n)if(t){var l=n.indexOf(t);if(l>-1&&n.splice(l,1),this._inspectors)for(var c=this._inspectors,f=Array.isArray(c),p=0,c=f?c:(0,_getIterator3["default"])(c);;){var u;if(f){if(p>=c.length)break;u=c[p++]}else{if(p=c.next(),p.done)break;u=p.value}var v=u;v({action:"Remove",type:s,callback:t})}}else if(delete this._callbacks[s],this._inspectors)for(var h=this._inspectors,b=Array.isArray(h),_=0,h=b?h:(0,_getIterator3["default"])(h);;){var y;if(b){if(_>=h.length)break;y=h[_++]}else{if(_=h.next(),_.done)break;y=_.value}var d=y;d({action:"Remove",type:s,callback:void 0})}}return this},e.prototype.removeListeners=function(){this._callbacks=void 0},e.prototype.removeInspectors=function(){this._inspectors=void 0},e.prototype.emit=function(e){for(var t=this,r=arguments.length,a=Array(r>1?r-1:0),i=1;i<r;i++)a[i-1]=arguments[i];var o=_promise2["default"].resolve();this._callbacks||(this._callbacks={});var s=this._callbacks[e];if(s)for(var n=function(){if(c){if(f>=l.length)return"break";p=l[f++]}else{if(f=l.next(),f.done)return"break";p=f.value}var r=p;o=o.then(function(i){return r.remove&&t.removeListener(e,r),r.call.apply(r,[t].concat(a))})},l=s,c=Array.isArray(l),f=0,l=c?l:(0,_getIterator3["default"])(l);;){var p,u=n();if("break"===u)break}return o},e.prototype.bubble=function(e){for(var t=this,r=arguments.length,a=Array(r>1?r-1:0),i=1;i<r;i++)a[i-1]=arguments[i];var o=_promise2["default"].resolve();this._callbacks||(this._callbacks={});var s=this._callbacks[e];if(s)for(var n=function(){if(c){if(f>=l.length)return"break";p=l[f++]}else{if(f=l.next(),f.done)return"break";p=f.value}var e=p;o=o.then(function(r){return e.call.apply(e,[t].concat(a))})},l=s,c=Array.isArray(l),f=0,l=c?l:(0,_getIterator3["default"])(l);;){var p,u=n();if("break"===u)break}else if(this.parent){var v;(v=this.parent).bubble.apply(v,[e].concat(a))}return o},e.prototype.findListener=function(e){this._callbacks||(this._callbacks={});var t=this._callbacks[e];return t?this:this.parent?this.parent.find(e):void 0},e.prototype.hasListener=function(e){var t=arguments.length<=1||void 0===arguments[1]?void 0:arguments[1];this._callbacks||(this._callbacks={});var r=this._callbacks[e];return!(!r||t&&t!==r)},e.mixin=function(t){var r=arguments.length<=1||void 0===arguments[1]?null:arguments[1];t.hasListener=e.prototype.hasListener,t.on=e.prototype.on,t.once=e.prototype.once,t.inspect=e.prototype.inspect,t.removeListener=e.prototype.removeListener,t.removeListeners=e.prototype.removeListeners,t.removeInspectors=e.prototype.removeInspectors,t.emit=e.prototype.emit,t.bubble=e.prototype.bubble,t.findListener=e.prototype.findListener,r&&t.on.bind(t)(r)},e}();exports["default"]=Events;