Skip to content

Commit

Permalink
JS: Fix viewmodel freezing
Browse files Browse the repository at this point in the history
We have to freeze the viewmodel value, not the CoerceResult object
  • Loading branch information
exyi committed Feb 23, 2024
1 parent a8b54f7 commit 2fa1273
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export function tryCoerce(value: any, type: TypeDefinition | null | undefined, o
if (result instanceof CoerceError) {
return result; // we cannot freeze CoerceError because we modify its path property
}
return Object.freeze(result);
Object.freeze(result.value)
return result
}

export function coerce(value: any, type: TypeDefinition, originalValue: any = undefined): any {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -682,3 +682,13 @@ test("changing dynamic type property notifies when dynamic types are different -
}
expect(notifyCount).toBe(1);
});

test("state is frozen", () => {
expect(Object.isFrozen(vm.state)).toBe(true);
expect(Object.isFrozen(s.state)).toBe(true);
expect(Object.isFrozen(vm.Dynamic.state)).toBe(true);

vm.Dynamic.setState({ x: 1 })
s.doUpdateNow()
expect(Object.isFrozen(vm.Dynamic.state)).toBe(true);
})

0 comments on commit 2fa1273

Please sign in to comment.