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 unstate utility function #9776
Conversation
🦋 Changeset detectedLatest commit: fb73276 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 ↗︎
|
This creates a new object from the given one - is it somehow possible to get the underlying original object instead? If not, this should be called out in the docs. |
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
@dummdidumm We can't return the original object. I've updated the docs. |
Could we add the original object reference to a symbol in the proxy and just take it from there when unwrapping? Also, what happens if you unwrap something and have a class that itself uses proxy objects? Does import { UNWRAP_SYMBOL } from 'svelte';
class Foo {
nestedStuff = $state({ .. });
[UNWRAP_SYMBOL]: () => {
// does this even make sense?
// could we apply this automatically when transforming classes?
return {
...this,
nestedStuff: unwrap(this.nestedStuff)
};
} |
I don't get what this gives us? If anything, that means that it won't be reactive anymore. You might want to reactively
That's a good point. I'll add something for that. |
I don't understand how the two are related, and I don't understand what you mean by "you might want to reactivityl |
You can't use that object ever again. We've attached a symbol to that very object and we can't remove the symbol. The symbol prevents the object from being used in |
Mhm yeah that makes sense, we also can't |
unstate
To remove reactivity from objects and arrays created with
$state
, useunstate
:This is handy when you want to pass some state to an external library or API that doesn't expect a reactive object – such as
structuredClone
.