"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.listenGlobalComponent = listenGlobalComponent;
exports.firstGlobalComponentPromise = firstGlobalComponentPromise;
function listenGlobalComponent(system, id, callback) {
    const { emitter } = system;
    const listener = (component) => {
        callback(component);
    };
    emitter.addListener(id, listener);
    return () => {
        emitter.removeListener(id, listener);
    };
}
function firstGlobalComponentPromise(system, id) {
    const { emitter } = system;
    let component;
    let system_ = system;
    while (system_ && !component) {
        component = system_.getLocalComponents(id)[0];
        system_ = system_.parent;
    }
    if (component) {
        return Promise.resolve(component);
    }
    return new Promise((resolve) => {
        const listener = (component) => {
            emitter.removeListener(id, listener);
            resolve(component);
        };
        emitter.addListener(id, listener);
    });
}
//# sourceMappingURL=globalComponent.js.map