@tuoyuan/map-adapter-lib
Version:
地图适配器库
2 lines (1 loc) • 1.19 kB
JavaScript
"use strict";var h=Object.defineProperty;var o=(i,e,u)=>e in i?h(i,e,{enumerable:!0,configurable:!0,writable:!0,value:u}):i[e]=u;var s=(i,e,u)=>o(i,typeof e!="symbol"?e+"":e,u);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class l{constructor(){s(this,"queue");s(this,"onceQueue");s(this,"allQueue");this.queue={},this.onceQueue={},this.allQueue=[]}on(e,u){this.queue[e]=this.queue[e]||[],this.queue[e].push(u)}once(e,u){this.onceQueue[e]=this.onceQueue[e]||[],this.onceQueue[e].push(u)}off(e,u){if(u){if(this.queue[e]){for(let t=0;t<this.queue[e].length;t++)if(this.queue[e][t]===u){this.queue[e].splice(t,1);break}}if(this.onceQueue[e]){for(let t=0;t<this.onceQueue[e].length;t++)if(this.onceQueue[e][t]===u){this.onceQueue[e].splice(t,1);break}}}else delete this.queue[e],delete this.onceQueue[e]}emit(e,u){this.queue[e]&&this.queue[e].forEach(function(t){t(u)}),this.onceQueue[e]&&(this.onceQueue[e].forEach(function(t){t(u)}),delete this.onceQueue[e]),this.allQueue.forEach(t=>{t(e,u)})}addListener(e){this.allQueue.push(e)}removeListener(e){for(let u=0;u<this.allQueue.length;u++)if(this.allQueue[u]===e){this.allQueue.splice(u,1);break}}}exports.EventBus=l;