"use strict";
const Q = require("q");
class EventBroker {
    constructor(_triggerEvent) {
        this._triggerEvent = _triggerEvent;
        this.registeredData = {};
    }
    fireEvent(eventName, data) {
        this._triggerEvent(eventName, { data });
        return Q();
    }
    registerData(dataName, data) {
        this.registeredData[dataName] = data;
        return Q();
    }
    fetchData(dataName) {
        const data = this.registeredData[dataName];
        if (undefined !== data) {
            return Q({ data });
        }
        return Q.reject("No data is registered under " + dataName);
    }
}
exports.EventBroker = EventBroker;
exports.name = "EventBroker";
function instance(triggerEvent) {
    return {
        commands: new EventBroker(triggerEvent),
    };
}
exports.instance = instance;
