-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add $state.frozen rune #9851
Conversation
🦋 Changeset detectedLatest commit: 34581f6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Ref #9762. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this mostly looks good but left some comments regarding testing.
do we want to use readonly
in dev? presumably we don't want people mutating objects inside $state.raw
, as it'll just fail confusingly
packages/svelte/tests/runtime-runes/samples/class-private-raw-state/main.svelte
Outdated
Show resolved
Hide resolved
Addressed feedback, added more tests. I didn't get around to making the object |
This comment was marked as outdated.
This comment was marked as outdated.
Should this be called $state.shallow() instead? |
Update the PR. This is now |
sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md
Outdated
Show resolved
Hide resolved
sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md
Outdated
Show resolved
Hide resolved
sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
$state.frozen
Similar to
$state
,$state.frozen
is also declared and can be used in many of the same ways (including on classes). However, the properties of any object and arrays are treated as read-only, and cannot be mutated. So if you intend to use objects as state and you want to mutate their properties and have reactivity work by default, it's recommended you use$state
instead.For the cases where you don't want Svelte's reactivity to apply deeply to state, and for those who might want to have more control over their data structures, you might find
$state
useful. Furthermore,$state.frozen
is ideal for those who want to work with data using immutable patterns rather than mutable patterns.