-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
docs: clarify effect alternatives section #10718
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
Conversation
|
The following example in the docs: let { result_1, result_2 } = $derived.by(() => {
// ... some lengthy code resulting in
return {
result_1: someValue,
result_2: someOtherValue
};
}); is a very good answer to the question I posed long ago in the Discord, i.e. what to do with the '1-condition-to-many-updates' scenario? Back then neither destructuring $derived, nor $derived with callback was around ... so I'm glad that's settled. Still using $effect might at first seem more flexible to migrators of ' You also mention in the docs that in extreme cases you can use untrack inside an $effect ... so that sorta goes against my assumption that it's buggy under the hood to update state in an $effect. Not to beat a dead horse but I wonder if having a As an aside how would you replicate this Svelte 4 code in Svelte 5 with untracked effect? let count = 1;
$: if( count > 0) count++ |
You would need to create an explicit dependencies array and use |
Thanks Simon. Yea I think this example is why I thought of '$watch' ... I vaguely remember someone else use your code (untrack + tick) to do so .. I was going that direction actually before giving up lol. Not that I find this particular example that useful, but the 'boilerplate inflation' here is quite drastic! |
If there are many real world use cases where something like this is the best/only solution to a certain problem, then we maybe can add something like |
Ah ok so Thiagolino mentioned something along these lines then. |
A handful of minor cleanups:
proxy
tofacade
since it's not aProxy