-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Allow svelte/actions
to update passed variables
#8959
Comments
You are shadowing <script>
export let bar;
function foo(node, _bar) {
bar = 123;
return {
update(bar) {},
destroy() {},
};
}
</script>
<div use:foo={bar}>
{bar}
</div> |
This is on purpose. I'd like to update whatever I pass into |
I think I'm understanding what you want to achieve. But I don't see how this could be added in a meaningful way to Svelte. First of all it can only work for the special case of inline-actions, because reactivity can not leak into vanilla JS files. So updating Maybe there's a way to add this to sveltejs/rfcs#41, which at least has the potential to allow this type of logic. |
For completeness sake your code example is very similar to this #7429 |
This would break all javascript semantics and for that matter is impossible for svelte to implement without compiling the action functions which currently doesn't happen. You can write actions in any javascript file and use them in svelte. In order to support this, actions would have to be written in svelte files (which there actually is an RFC for btw) but even if that were to theoretically happen I still don't think is would be remotely easy to implement this kind of api in the compiler side. What svelte wants you to do in this case is use a store. So you should make I do think it would be useful for svelte to get some kind of syntax for converting a reactive local variable to a store similar to how you can go the other way. Like if I have <script>
import {writable} from "svelte";
let myValue = 5;
let _$_myValue = writable();
$: _$_myValue.set(myValue);
</script>
<div use:foo={_$_myValue} /> this could be useful if I have run into this problem before when using svelte as well and I think the general solution is to just make things into stores. |
You can pass callback to action and update it in callback, or use object instead primitive.
|
Describe the problem
Currently this prints
undefined
. This makes recreatingbind:group
much harder.Describe the proposed solution
Allow
svelte/actions
to update passed variables.Alternatives considered
The passed object could be a reference.
Importance
would make my life easier
The text was updated successfully, but these errors were encountered: