sveltejs / svelte

Cybernetically enhanced web apps
https://svelte.dev
MIT License
76.8k stars 3.98k forks source link

$effect enhancement #11447

Closed jreuss closed 2 weeks ago

jreuss commented 2 weeks ago

Describe the problem

As the $effect rune is now, I find it to be, well not ideal. I need $effect mostly to ensure that dom is ready and also to 'watch' a variable. In both cases its kind of unwieldy. In my opinion its too easy to end up with unwanted sideeffect (reruns), when the entire function scope is just evaluated as is). Before (in svelte 4) I could do this:

$: someFunction(arg1, arg2)

which would effectively watch arg1 and arg2. I could reference whatever other properties inside someFunction or anywhere else, without having to worry this might cause the effect to run again.

Describe the proposed solution

I would love to be able to limit the scope of effect to particular variables. Perhaps allow both use cases:

$(() => {}) would watch any reactive variables inside the function scope.

$((arg1, arg2) => { })

would only watch the parameters

Importance

would make my life easier

Prinzhorn commented 2 weeks ago

Duplicate of https://github.com/sveltejs/svelte/issues/9248