event.js
449 Bytes
export default {
listeners: [],
on(type, handle) {
if (typeof handle === 'function') {
console.debug(`listen event ${type}`);
this.listeners.push([type, handle]);
}
},
emit(type, ...params) {
this.listeners.forEach(([listenType, handle]) => type === listenType && handle(...params));
console.debug(`receive event ${type}: ${JSON.stringify(params)}`);
},
removeAllListeners() {
this.listeners = [];
}
};