var EventStream = /** @class */ (function () {
    function EventStream() {
    }
    /**
     *  Emits an event of the given type with the given data. All callbacks that are listening to the particular
     *  event type will be notified.
     *
     * @param eventType
     * @param args
     */
    EventStream.emit = function (eventType) {
        var args = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            args[_i - 1] = arguments[_i];
        }
        EventStream.listeners(eventType).forEach(function (listener) { return listener(args); });
    };
    /**
     *  Emits an event of the given type with the given data. All callbacks that are listening to the particular
     *  event type will be notified.
     *
     * @param event
     */
    EventStream.emitEvent = function (event) {
        this.emit(event.type, event.payload);
    };
    /**
     * Return an array of listeners that are currently registered for the given event type.
     *
     * @param eventType
     */
    EventStream.listeners = function (eventType) {
        return EventStream.theListeners[eventType] || [];
    };
    /**
     * Removes all of the registered listeners. eventType is optional, if provided only listeners for that
     * event type are removed.
     *
     * @param eventType
     */
    EventStream.removeAllListeners = function (eventType) {
        if (eventType) {
            delete EventStream.theListeners[eventType];
        }
        else {
            Object.keys(EventStream.theListeners).forEach(function (key) {
                delete EventStream.theListeners[key];
            });
        }
    };
    /**
     * Register a specific callback to be called on a particular event. A token is returned that can be used
     * to remove the listener.
     */
    EventStream.addListener = function (eventType, listener) {
        if (EventStream.theListeners[eventType]) {
            EventStream.theListeners[eventType].push(listener);
        }
        else {
            EventStream.theListeners[eventType] = [listener];
        }
        return {
            remove: function () {
                var index = EventStream.theListeners[eventType].findIndex(function (e) { return e === listener; });
                if (index >= 0) {
                    EventStream.theListeners[eventType].splice(index, 1);
                }
            }
        };
    };
    EventStream.SYSTEM_EVENT_TYPE_PREFIX = "GAIA::";
    EventStream.theListeners = {};
    return EventStream;
}());
export default EventStream;
//# sourceMappingURL=EventStream.js.map