You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Instead of going the classes route, maybe regular $state could benefit from more interoperability with $derived.
Note that the following works:
exportconstgetExampleRunes=(initialValue: number): Example=>{constexample=$state({value: initialValue,getdoubled(){returnthis.value*2},});returnexample;// <- currently causes a warning, though}
This is also what I would just use in most cases.
The only real advantage of $derived in this scenario is, that it provides caching.
Now, if you want to add the value as a $derived, I see no simple way to do that, except splitting things up again. At that point we are back at defining getters/setters for everything manually or switching to a class, which has all the annoying downsides that come with classes (serializability issues, this everywhere, etc.).
Uh oh!
There was an error while loading. Please reload this page.
Describe the problem
Sorry about the goofy issue title. What I mean is this:
Context: I was converting a function that created a hash of Svelte stores to runes, and missed the implication of the note on the docs page that says:
So I spent a while wondering why the pojo returned from
getExampleRunes
above wasn't working.Describe the proposed solution
Consider adding another sentence to that note, something like...
Alternatives considered
I'm fine with using classes. It's just a documentation issue.
Importance
nice to have
The text was updated successfully, but these errors were encountered: