// eventBus.js
export const eventBus = {
	listeners: {},

	$on(eventName, listener) {
		if (!this.listeners[eventName]) {
			this.listeners[eventName] = [];
		}
		this.listeners[eventName].push(listener);
	},

	$emit(eventName, ...args) {
		const listeners = this.listeners[eventName];
		if (listeners && listeners.length>0) {
			listeners.forEach((listener) => listener(...args));
		}
	},

	$off(eventName, listener) {
		const listeners = this.listeners[eventName];
		if (listeners) {
			this.listeners[eventName] = listeners.filter(l => l !== listener);
		}
	}
};
