Replies: 1 comment 3 replies
-
See also this comment and related issues. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Opinion
Sveltes runes system does not provide transparency on whether a variable is reactive or not. This is especially problematic when working with state passed between files and components as it is very easy to drop reactivity through for example decomposition or variable assignments. It is also an issue when consuming 3rd party packages as the only way to know whether a value is reactive or not is to read documentation that hopefully describes this. This is a known issue but it does not seem to be actively worked on at the moment afaik.
Sveltes $state is syntactically similar to reactive() in vue and shares some of its limitations. in vue, the main, and recommended way to declare reactivity is with ref(). this always return an object with a ".value" key that contains the reactive state. This can be implemented manually in svelte, however i think there is a need to standardize this pattern in svelte itself so that 3rd party packages can share a common syntax across the ecosystem.
As a test, i made a simple typescript implementation of a state$() function (note: state$ != $state) that returns a StateRune class, where the '$' key contains the reactive value. Copy it and try it out! This makes it crystal clear when passing the variable between files that it is a reactive value, and that the reactivity is preserved.
Since this is obviously trivial to implement yourself, you could make the argument that it is not needed as a part of svelte itself, but i think the need is rather to create a standardized way on how to use runes in a portable way in the svelte ecosystem. An actual implementation should therefore be called something like
$ref
instead ofstate$
. Both $ref and $state runes could be supported in parallel as they cover somewhat different needs/patterns.So what are your thoughts? Is there a need for this or are there more idiomatic ways to achieve this already?
Beta Was this translation helpful? Give feedback.
All reactions