Proposal: Introducing more $ sugar to reduce boilerplate like .current?
#15410
Replies: 2 comments 4 replies
-
|
Another example, I think <script>
import { innerWidth, innerHeight } from 'svelte/reactivity/window';
</script>
<p>{$innerWidth}x{$innerHeight}</p>is better than: <script>
import { innerWidth, innerHeight } from 'svelte/reactivity/window';
</script>
<p>{innerWidth.current}x{innerHeight.current}</p>I think providing best DX with performant reactivity is one of Svelte's goals. People don't like Vue's |
Beta Was this translation helpful? Give feedback.
-
|
I do not think this will be changed. The definition does not need to be that complicated: export const value = $state({ current: undefined });(If you really want to, you can transform |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When I exports something from a
.svelte.jsfile, I always need to wrap it with code like this:And accessing it became:
I wonder whether we can provide some sugar like the store syntax? Like, so that we can use
$valuelike a normal store.What I mean is basically provide a new rune - let's name it
$wrap- then inside a.svelte.jsfile, users canexport default $wrap(value)wherevalueis a$state().And user can access it via
import value from "...svelte.js"and use$valuelike using a store!I think this way is easier than using getter and setters.
Beta Was this translation helpful? Give feedback.
All reactions