/**
 * @module utils/EventBus
 */
'use strict';

import TinyEmitter from 'tiny-emitter';
import {HashMap} from '../typings/common';

type EventHandler = {
    fn: Function;
    ctx?: any;
};

class EventBus extends TinyEmitter {
    e: HashMap<EventHandler[]> = {};
    emit(event: string, ...args: any[]): TinyEmitter {
        // uncomment lines below for debug info
        // var data = [].slice.call(arguments, 1);
        // console.log("Event: [" + name + "]" + (data !== undefined ? " -> " + JSON.stringify(data) : ""));
        return super.emit.apply(this, arguments);
    }
}

/**
 * @alias utils/EventBus:eventBus
 */
export default new EventBus();
