"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TaonBuildObserver = void 0;
const lib_1 = require("tnp-core/lib");
const lib_2 = require("tnp-helpers/lib");
const dev_mode_models_1 = require("../../../../abstract/taon-worker/dev-mode/dev-mode.models");
const immutable_1 = require("immutable");
//#endregion
const defaultValue = (0, immutable_1.Record)({
    backend: dev_mode_models_1.DevMode.PorjectBuildStatus.NOT_STARTED,
    browser: dev_mode_models_1.DevMode.PorjectBuildStatus.NOT_STARTED,
    websql: dev_mode_models_1.DevMode.PorjectBuildStatus.NOT_STARTED,
    errorMessage: undefined,
});
// @ts-ignore TODO weird inheritance problem
class TaonBuildObserver extends lib_2.BaseFeatureForProject {
    // TODO remove anyStd from exitprocess
    // TODO when in watch mode exit -> delete first all subprocesses (keep them here)
    buildStatusInfo = defaultValue();
    mergeSkipUndefined(record, patch) {
        return record.mergeWith((oldValue, newValue) => (newValue === undefined ? oldValue : newValue), patch);
    }
    async updateAction(info) {
        //#region @backendFunc
        if (lib_1._.isObject(info)) {
            this.buildStatusInfo = this.mergeSkipUndefined(this.buildStatusInfo, info);
        }
        console.log(this.buildStatusInfo.toJS());
        await this.project.ins.devBuildRepository.updatePool({
            buildStatusInfo: this.buildStatusInfo.toJS(),
        });
        //#endregion
    }
    debouceUpdate = lib_1._.debounce(async () => {
        await this.updateAction();
    }, 1000);
    updateSuccess = lib_1._.debounce(async (info) => {
        this.buildStatusInfo = this.mergeSkipUndefined(this.buildStatusInfo, info);
        this.debouceUpdate();
    });
    updateError = lib_1._.debounce(async (info) => {
        this.buildStatusInfo = this.mergeSkipUndefined(this.buildStatusInfo, info);
        this.debouceUpdate();
    });
    start() { }
}
exports.TaonBuildObserver = TaonBuildObserver;
//# sourceMappingURL=success-build-observer.js.map