bus-plus
Version:
bus bus-plus 公交车 mitter 事件订阅 事件发布
1 lines • 2.4 kB
JavaScript
var e={};e.d=function(t,r){for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},e.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)};var t={};function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}e.d(t,{m:function(){return a}});function n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var a=function(){"use strict";var e,t,a;function o(){var e,t,r,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Map;!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,o),e=this,r=void 0,(t="maps")in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,this.maps=n}return e=o,t=[{key:"useEvent",value:function(e,t,r){var n={once:r,handle:t};if(this.maps.has(e)){var a=this.maps.get(e);a.push(n),this.maps.set(e,a)}else this.maps.set(e,[n])}},{key:"on",value:function(e,t){return this.useEvent(e,t,!1),this}},{key:"once",value:function(e,t){this.useEvent(e,t,!0)}},{key:"off",value:function(e,t){if("function"==typeof t){var r=this.maps.get(e)||[];this.maps.set(e,r.filter(function(e){return e.handle!==t}))}else this.maps.delete(e);return this}},{key:"emit",value:function(e){for(var t=this,n=arguments.length,a=Array(n>1?n-1:0),o=1;o<n;o++)a[o-1]=arguments[o];return(this.maps.get(e)||[]).forEach(function(n){var o;n.handle.apply(n,function(e){if(Array.isArray(e))return r(e)}(o=a)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(o)||function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return r(e,t)}}(o)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),n.once&&t.off(e,n.handle)}),this}},{key:"has",value:function(e,t){return(this.maps.get(e)||[]).some(function(e){return e.handle===t})}},{key:"clear",value:function(){return this.maps.clear(),this}}],n(e.prototype,t),o}(),o=t.m;export{o as BusPlus};