"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StateHasChangedUC = void 0;
exports.makeStateHasChangedUC = makeStateHasChangedUC;
const core_1 = require("@vived/core");
const AppDispatcher_1 = require("../Entities/AppDispatcher");
class StateHasChangedUC extends core_1.AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "ON_STATE_CHANGE";
    }
}
exports.StateHasChangedUC = StateHasChangedUC;
StateHasChangedUC.type = "StateHasChangedUC";
StateHasChangedUC.get = (appObjects) => (0, core_1.getSingletonComponent)(StateHasChangedUC.type, appObjects);
function makeStateHasChangedUC(appObject) {
    return new StateHasChangedUCImp(appObject);
}
class StateHasChangedUCImp extends StateHasChangedUC {
    constructor(appObject) {
        super(appObject, StateHasChangedUC.type);
        this.requestVersion = 3;
        this.stateHasChanged = (stateObject, assets, validationErrorMessage) => {
            if (!this.appDispatcher)
                return;
            const payload = {
                stateObject,
                assets,
                validationErrorMessage,
            };
            this.appDispatcher.formRequestAndDispatch(this.requestType, this.requestVersion, payload);
        };
        this.appDispatcher = appObject.getComponent(AppDispatcher_1.AppDispatcher.type);
        if (!this.appDispatcher) {
            this.warn(`${StateHasChangedUC.type} has been added to an App Object that does not have a AppDispatcher. Add a dispatcher first`);
            this.dispose();
        }
    }
}
//# sourceMappingURL=StateHasChangedUC.js.map