import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { AppDispatcher } from "../Entities/AppDispatcher";
export class StateHasChangedUC extends AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "ON_STATE_CHANGE";
    }
}
StateHasChangedUC.type = "StateHasChangedUC";
StateHasChangedUC.get = (appObjects) => getSingletonComponent(StateHasChangedUC.type, appObjects);
export 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.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