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.
-
When I exports something from a
.svelte.js
file, 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
$value
like a normal store.What I mean is basically provide a new rune - let's name it
$wrap
- then inside a.svelte.js
file, users canexport default $wrap(value)
wherevalue
is a$state()
.And user can access it via
import value from "...svelte.js"
and use$value
like using a store!I think this way is easier than using getter and setters.
Beta Was this translation helpful? Give feedback.
All reactions