framework-entersol-web
Version:
Framework based on bootstrap 5
2 lines • 3.63 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:true});exports["default"]=exports.EventHandler=void 0;function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},_typeof(o)}function _slicedToArray(r,e){return _arrayWithHoles(r)||_iterableToArrayLimit(r,e)||_unsupportedIterableToArray(r,e)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n}function _iterableToArrayLimit(r,l){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=t){var e,n,i,u,a=[],f=!0,o=!1;try{if(i=(t=t.call(r)).next,0===l){if(Object(t)!==t)return;f=!1}else for(;!(f=(e=i.call(t)).done)&&(a.push(e.value),a.length!==l);f=!0);}catch(r){o=!0,n=r}finally{try{if(!f&&null!=t["return"]&&(u=t["return"](),Object(u)!==u))return}finally{if(o)throw n}}return a}}function _arrayWithHoles(r){if(Array.isArray(r))return r}function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o)}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+""}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}var EventHandler=exports.EventHandler=/*#__PURE__*/function(){function EventHandler(){_classCallCheck(this,EventHandler);this.events={}}return _createClass(EventHandler,[{key:"dispatch",value:function dispatch(event){for(var _len=arguments.length,data=new Array(_len>1?_len-1:0),_key=1;_key<_len;_key++){data[_key-1]=arguments[_key]}if(!this.events[event])return;this.events[event].forEach(function(_ref){var _ref2=_slicedToArray(_ref,2),callback=_ref2[0],id=_ref2[1];return callback.apply(void 0,data.concat([id]))})}},{key:"subscribe",value:function subscribe(eventString,callback,id){var _this=this;var events=eventString.split(/[ ,]+/);events.forEach(function(e){if(!_this.events[e])_this.events[e]=[];_this.events[e].push([callback,id])})}},{key:"unsubscribe",value:function unsubscribe(eventString,id){var _this2=this;var events=eventString.split(/[ ,]+/);events.forEach(function(e){if(!_this2.events[e])return;var rest=_this2.events[e].filter(function(_ref3){var _ref4=_slicedToArray(_ref3,2),eventId=_ref4[1];return eventId!=id});_this2.events[e]=rest})}}])}();var _default=exports["default"]=new EventHandler;
//# sourceMappingURL=event-handler.js.map