"use strict";
var ExtensionTreeModel_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExtensionTreeModel = void 0;
const tslib_1 = require("tslib");
const di_1 = require("@opensumi/di");
const ide_components_1 = require("@opensumi/ide-components");
const ide_core_browser_1 = require("@opensumi/ide-core-browser");
const tree_view_node_defined_1 = require("./tree-view.node.defined");
let ExtensionTreeModel = ExtensionTreeModel_1 = class ExtensionTreeModel extends ide_components_1.TreeModel {
    constructor(root) {
        super();
        this.flushDispatchChangeDelayer = new ide_core_browser_1.ThrottledDelayer(ExtensionTreeModel_1.DEFAULT_FLUSH_DELAY);
        this.init(root);
    }
    init(root) {
        this.root = root;
        // 分支更新时通知树刷新, 不是立即更新，而是延迟更新，待树稳定后再更新
        // 100ms的延迟并不能保证树稳定，特别是在node_modules展开的情况下
        // 但在普通使用上已经足够可用，即不会有渲染闪烁问题
        this.root.watcher.on(ide_components_1.TreeNodeEvent.BranchDidUpdate, () => {
            if (!this.flushDispatchChangeDelayer.isTriggered()) {
                this.flushDispatchChangeDelayer.cancel();
            }
            this.flushDispatchChangeDelayer.trigger(async () => {
                this.dispatchChange();
            });
        });
    }
};
exports.ExtensionTreeModel = ExtensionTreeModel;
ExtensionTreeModel.DEFAULT_FLUSH_DELAY = 100;
exports.ExtensionTreeModel = ExtensionTreeModel = ExtensionTreeModel_1 = tslib_1.__decorate([
    (0, di_1.Injectable)({ multiple: true }),
    tslib_1.__param(0, (0, di_1.Optional)()),
    tslib_1.__metadata("design:paramtypes", [tree_view_node_defined_1.ExtensionTreeRoot])
], ExtensionTreeModel);
//# sourceMappingURL=tree-view.model.js.map