-
-
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.opaque
rune
#14639
base: main
Are you sure you want to change the base?
feat: add $state.opaque
rune
#14639
Conversation
🦋 Changeset detectedLatest commit: 21b0865 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 |
preview: https://svelte-dev-git-preview-svelte-14639-svelte.vercel.app/ this is an automated message |
|
TODO: when we land |
Given the syntactical requirements, I assume there's no way to make this work with classes? |
Nope. I think that’s fine though |
Couldn't something like this be done? (apologies for the terrible spacing) class Thing{
constructor() {
([this.stuff, this.invalidate] = $state.opaque(stuff));
}
} Couldn't the private property for the |
I don't think we should optimise for the usage of |
This PR adds the
$state.opaque
rune. This is a special kind of rune designed to solve problems with handling and managing state from external sources/libraries.Specifically, for cases where Svelte is not involved in understanding that of the reactivity of the thing you're passing in – thus being opaque to Svelte. In order to let Svelte 5 know that something has changed, an invalidate function is provided so you can manually control letting Svelte know it should invalidate any reactive dependencies on this piece of state:
This means that reassignments and mutations to opaque state will not trigger reactive updates. You always need to invoke the invalidate function. Furthermore, this means that you will likely need to adopt the recent function bindings feature if you intend to use opaque state with
bind:something
.Closes #14520.