Skip to content

Commit

Permalink
Merge pull request #1782 from riganti/js-state-freeze
Browse files Browse the repository at this point in the history
JS: Fix viewmodel freezing
  • Loading branch information
tomasherceg committed Feb 23, 2024
2 parents a8b54f7 + 2fa1273 commit 58f1854
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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
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 58f1854

Please sign in to comment.