-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Svelte 5: Bring back $state.link #13452
Comments
For reference: #12938 (comment) here is the decision to remove The problem was that, after correcting the behaviour, it used the Examples: sync let box = link(() => parentValue, onMerge);
console.log(box.value); |
Couldn't you just use a let a = $state(0);
let b = $derived(a); |
No, derives are read-only (though mutable). So you cannot do |
Ah, I see. let a = $state(0);
let b = $state($state.snapshot(a));
$effect(()=>{
b = $state.snapshot(a);
}); It shouldn't be too much of a problem that |
Describe the problem
Knowing that $state.link existed once, I can't stop thinking how many times I could use it in my project. It's really useful and removes the need of having to write an extra $effect that does nothing other than assigning a value to a variable. Also the work around that uses an $effect isn't really good either because the assignment inside $effect is not fine-grained.
Describe the proposed solution
I think it would be nice to have it back and makes migrating from svelte 4 easier since in svelte 4 you could assign to the reactive variable and it would update again if its dependency changed.
For example, you could do the following in svelte 4 when you didn't want to change the original data passed by the user and still update your finalData if it got updated
So here finalData was updated internally but it would have been updated again if the user decided to update the data prop.
This could translate to the following in Svelte 5 which is neat:
Importance
nice to have
The text was updated successfully, but these errors were encountered: