# Source: events/eventbus.js

    /**
     * Created by zhangmike on 16/10/18.
     */
    export default function initEventBus(GMP) {
        var events = {},
            registerEvent = function(eName, handler, scope){
                events[eName] = events[eName]||[];
                events[eName].push({
                    scope: scope || this,
                    handler: handler
                });
            },
            removeEvent = function(eName, callback, scope){
                var fns = events[eName],
                    scope = scope || this;
                if (!fns) {
                    return;
                }
                events[eName] = events[eName].filter(function(fn){
                    if (callback && callback !== fn.callback ||
                        scope && scope !== fn.scope
                    ) {
                        return true;
                    } else {
                        return false;
                    }
                });
            },
            triggerEvent = function(eventName, params){
                var fns = events[eventName],
                    i,
                    fn;
                if (!fns) {
                    return;
                }
                for (var i = 0; fn = fns[i]; i++) {
                    fn.handler.apply(fns.scope, params || []);
                }
            };
        GMP["GMPEvents"] = {
            on: registerEvent,
            off: removeEvent,
            trigger: triggerEvent,
            _events: events
        };
    };