-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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: The $proxy
rune
#9998
Comments
I'm not sure we need input modifiers nor a |
@dummdidumm I'm going to reply here to not spam so many notifications
In your example this needs to work to do what <button onclick={() => proxy.value = 'test'}></button> |
I see - yes. In other words, if we allow |
I agree, this would essentially do what we're asking for with minimal overhead ( So that we're on the same page: We're asking for: <script>
let { value } = $props();
let proxiedValue = $proxy(value, { get(v) { return v.toUpperCase() }, set(v) { return v.toLowerCase() } });
</script>
<input bind:value={proxiedValue} />
<button onclick={() => proxiedValue = 'test'}>Test</button We're getting: <script>
let { value } = $props();
let proxy = $derived({ get value() { return value.toUpperCase() }, set value(val) { value = val.toLowerCase() } });
</script>
<input bind:value={proxy.value} />
<button onclick={() => proxy.value = 'test'}>Test</button
I mean, do we really want to allow side-effects of mutating objects created via |
You know what, I'm stupid - we don't even need |
Crazy how nature do that |
That... that actually already works in Svelte today?!? thanks ❤️ @dummdidumm |
The first issue with the get/set approach is that we lose all reactivity to object mutations REPL. So to make it work with objects, you'd at least need 1 getter, 1 setter per field and a modifier. Which would be fine, except that now, we've created a loop This quickly gets incapacitating if you have something like a Another example is this optimistic upload #12545 (comment). Extending the REPL from this mentioned comment and exporting a |
Describe the problem
Basically #3937 (comment) — addresses #3937
Describe the proposed solution
See #3937 (comment) (but as a rune)
Alternatives considered
Currently no sane workaround. It's difficult to overstate the utility of this; it's one of the things Svelte is lacking most severely, IMO.
Importance
nice to have
The text was updated successfully, but these errors were encountered: