This commit is contained in:
lik
2026-05-30 21:09:24 +08:00
parent 212c94224b
commit 010cf160a0
1075 changed files with 67487 additions and 1 deletions

20
utils/eventBus.js Normal file
View File

@@ -0,0 +1,20 @@
export default function createBus() {
return {
events: {},
on(event, callback) {
if (!this.events[event]) this.events[event] = [];
this.events[event].push(callback);
},
off(event, callback) {
if (!this.events[event]) return;
if (!callback) this.events[event] = [];
else {
const index = this.events[event].indexOf(callback);
if (index !== -1) this.events[event].splice(index, 1);
}
},
emit(event, ...args) {
if (this.events[event]) this.events[event].forEach((callback) => callback(...args));
},
};
}