"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.watchTree = void 0;
const Graph_1 = require("../Class/Graph");
const f_1 = __importDefault(require("../system/core/object/ForEachKeyValue/f"));
const callAll_1 = require("../util/call/callAll");
const watchUnit_1 = require("./watchUnit");
const watchTree = (unit, events, callback) => {
    return _watchTree(unit, callback, [], events);
};
exports.watchTree = watchTree;
const _watchTree = (unit, callback, path = [], events) => {
    const all = [];
    all.push((0, watchUnit_1.watchUnit)(unit, (moment) => {
        callback(path, moment);
    }, events));
    if (unit instanceof Graph_1.Graph) {
        (0, f_1.default)(unit.getUnits(), (unit, id) => {
            const p = [...path, id];
            all.push(_watchTree(unit, callback, p, events));
        });
    }
    return (0, callAll_1.callAll)(all);
};
//# sourceMappingURL=watchTree.js.map