


export default class EventSystem {
	constructor(){
		this.callbacks = {};
	}

	on(e,cb){
		if(!this.callbacks[e]){
			this.callbacks[e] = [];
		}
		this.callbacks[e].push(cb)
		return this;
	}


	off(e,cb){
		let index = this.callbacks[e].indexOf(cb)
		if( index> -1) {
			this.callbacks[e].splice(index,1);
		}
		return this;
	}


	emit(eventName,data){
		this.callbacks[eventName] && this.callbacks[eventName].forEach((cb) => cb(data));
		return this;
	}
} 