"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Holder_1 = require("../../../../../Class/Holder");
const _ids_1 = require("../../../../_ids");
const globalComponent_1 = require("../../../../globalComponent");
class Observe extends Holder_1.Holder {
    constructor(system) {
        super({
            fi: ['component', 'observer'],
            fo: [],
            i: [],
            o: ['entry'],
        }, {
            input: {
                component: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_OBSERVE);
    }
    async f({ observer, component }, done, fail) {
        const { api: { document: {}, }, } = this.__system;
        const globalId = component.getGlobalId();
        const _component = await (0, globalComponent_1.firstGlobalComponentPromise)(this.__system, globalId);
        const leaf = _component.getFirstRootLeaf();
        if (leaf.$element instanceof Text) {
            fail('cannot observe text node');
            return;
        }
        this._unlisten = observer.observe(leaf.$element, (entry) => {
            this._output.entry.push(entry);
        });
    }
    d() {
        if (this._unlisten) {
            this._unlisten();
            this._unlisten = undefined;
        }
    }
}
exports.default = Observe;
//# sourceMappingURL=index.js.map