Skip to content

Commit

Permalink
fix(state): save state
Browse files Browse the repository at this point in the history
  • Loading branch information
ido-pluto committed Aug 28, 2024
1 parent fa3e706 commit 945b02e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/forms/src/components-control/form-utils/view-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class ViewStateManager {
}

get useState() {
return this.stateProp && this._astro.request.method === 'POST';
return this.stateProp;
}

constructor(private _bind: BindForm<any>, private _elementsState: any, private _astro: AstroGlobal, private _bindId: string | number) {
Expand Down Expand Up @@ -70,27 +70,27 @@ export default class ViewStateManager {
}

public async loadState() {
if (!this.useState) {
if (!this.useState || this._astro.request.method !== 'POST') {
return false;
}

const state: any = await this._parseState();
if (!state) return false;

if(state.bind && state.elements){
if (state.bind && state.elements) {
Object.assign(this._bind, state.bind);
Object.assign(this._elementsState, state.elements);
}
return true;
}

public async createViewState(): Promise<string> {
const data = this.useState ?{
const data = this.useState ? {
bind: this.omitProps ?
omitProps(this._bind.__getState(), this.omitProps):
omitProps(this._bind.__getState(), this.omitProps) :
getSomeProps(this._bind.__getState(), this.stateProp),
elements: this._elementsState
}: {};
} : {};

const stringify = superjson.stringify(data);
const compress = await snappy.compress(stringify, {});
Expand Down

0 comments on commit 945b02e

Please sign in to comment.