init
This commit is contained in:
commit
2b8870a40e
51 changed files with 5845 additions and 0 deletions
24
utils/eventManager.js
Normal file
24
utils/eventManager.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
// 事件管理器模块
|
||||
const eventManager = {
|
||||
listeners: {},
|
||||
on(event, callback) {
|
||||
if (!this.listeners[event]) {
|
||||
this.listeners[event] = [];
|
||||
}
|
||||
this.listeners[event].push(callback);
|
||||
},
|
||||
off(event, callback) {
|
||||
const callbacks = this.listeners[event];
|
||||
if (callbacks) {
|
||||
this.listeners[event] = callbacks.filter(cb => cb !== callback);
|
||||
}
|
||||
},
|
||||
emit(event, data) {
|
||||
const callbacks = this.listeners[event];
|
||||
if (callbacks) {
|
||||
callbacks.forEach(callback => callback(data));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = eventManager;
|
Loading…
Add table
Add a link
Reference in a new issue