{"size": 482, "ext": "js", "max_stars_repo_path": "src/utils/Bus.js", "max_stars_repo_name": "YouHan26/canvas-tree", "max_stars_repo_stars_event_min_datetime": "2019-02-19T10:33:00.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-19T10:33:00.000Z", "max_issues_repo_path": "src/utils/Bus.js", "max_issues_repo_name": "YouHan26/canvas-tree", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/utils/Bus.js", "max_forks_repo_name": "YouHan26/canvas-tree", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 17.2142857143, "max_line_length": 54, "alphanum_fraction": 0.5912863071}
class Bus {
	constructor() {
		this.listeners = {};
	}

	on(type, func) {
		this.listeners[type] || (this.listeners[type] = []);
		const key = new Date().getTime();
		this.listeners[type].push({
			key,
			func
		});
		return key;
	}

	trigger(type, ...args) {
		const listeners = this.listeners[type];
		if (listeners && listeners.length > 0) {
			listeners.forEach(function (listener) {
				const {func} = listener;
				func && func(...args);
			});
		}
	}
}

export default Bus;
