@tuoyuan/map-adapter-lib
Version:
地图适配器库
59 lines (58 loc) • 1.58 kB
JavaScript
var h = Object.defineProperty;
var o = (t, e, u) => e in t ? h(t, e, { enumerable: !0, configurable: !0, writable: !0, value: u }) : t[e] = u;
var s = (t, e, u) => o(t, typeof e != "symbol" ? e + "" : e, u);
class c {
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 i = 0; i < this.queue[e].length; i++)
if (this.queue[e][i] === u) {
this.queue[e].splice(i, 1);
break;
}
}
if (this.onceQueue[e]) {
for (let i = 0; i < this.onceQueue[e].length; i++)
if (this.onceQueue[e][i] === u) {
this.onceQueue[e].splice(i, 1);
break;
}
}
} else
delete this.queue[e], delete this.onceQueue[e];
}
emit(e, u) {
this.queue[e] && this.queue[e].forEach(function(i) {
i(u);
}), this.onceQueue[e] && (this.onceQueue[e].forEach(function(i) {
i(u);
}), delete this.onceQueue[e]), this.allQueue.forEach((i) => {
i(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;
}
}
}
export {
c as EventBus
};