awv3
Version:
AWV client CAD framework
1 lines • 5.05 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.onFirst=function(e,t){this.on(e,t,!1,1)},e.prototype.onLast=function(e,t){this.on(e,t,!1,-1)},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],i=arguments.length<=3||void 0===arguments[3]?void 0:arguments[3];if(this._callbacks||(this._callbacks={}),Array.isArray(e)||"string"==typeof e&&"function"==typeof t)for(var o=Array.isArray(e)?e:[e],a=o,s=Array.isArray(a),n=0,a=s?a:(0,_getIterator3.default)(a);;){var l;if(s){if(n>=a.length)break;l=a[n++]}else{if(n=a.next(),n.done)break;l=n.value}var c=l,p=this._callbacks[c];if(p||(p=this._callbacks[c]=[]),p.indexOf(t)<0&&(t.remove=r,i&&(t.priority=i),p.push(t),p.sort(function(e,t){return t.priority||0-e.priority||0}),this._inspectors))for(var f=this._inspectors,u=Array.isArray(f),v=0,f=u?f:(0,_getIterator3.default)(f);;){var h;if(u){if(v>=f.length)break;h=f[v++]}else{if(v=f.next(),v.done)break;h=v.value}var b=h;b({action:"Add",type:c,callback:t})}}else if("object"===("undefined"==typeof e?"undefined":(0,_typeof3.default)(e))&&void 0===t)for(var _ in e){var y=e[_];"function"==typeof y&&this.on(_,y,r,i)}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,i=Array.isArray(r),o=0,r=i?r:(0,_getIterator3.default)(r);;){var a;if(i){if(o>=r.length)break;a=r[o++]}else{if(o=r.next(),o.done)break;a=o.value}var s=a,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,p=Array.isArray(c),f=0,c=p?c:(0,_getIterator3.default)(c);;){var u;if(p){if(f>=c.length)break;u=c[f++]}else{if(f=c.next(),f.done)break;u=f.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,i=Array(r>1?r-1:0),o=1;o<r;o++)i[o-1]=arguments[o];var a=_promise2.default.resolve();this._callbacks||(this._callbacks={});var s=this._callbacks[e];if(s)for(var n=function(){if(c){if(p>=l.length)return"break";f=l[p++]}else{if(p=l.next(),p.done)return"break";f=p.value}var r=f;a=a.then(function(o){return r.remove&&t.removeListener(e,r),r.call.apply(r,[t].concat(i))})},l=s,c=Array.isArray(l),p=0,l=c?l:(0,_getIterator3.default)(l);;){var f,u=n();if("break"===u)break}return a},e.prototype.bubble=function(e){for(var t=this,r=arguments.length,i=Array(r>1?r-1:0),o=1;o<r;o++)i[o-1]=arguments[o];var a=_promise2.default.resolve();this._callbacks||(this._callbacks={});var s=this._callbacks[e];if(s)for(var n=function(){if(c){if(p>=l.length)return"break";f=l[p++]}else{if(p=l.next(),p.done)return"break";f=p.value}var e=f;a=a.then(function(r){return e.call.apply(e,[t].concat(i))})},l=s,c=Array.isArray(l),p=0,l=c?l:(0,_getIterator3.default)(l);;){var f,u=n();if("break"===u)break}else if(this.parent){var v;(v=this.parent).bubble.apply(v,[e].concat(i))}return a},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.onFirst=e.prototype.onFirst,t.onLast=e.prototype.onLast,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;