Replies: 1 comment 2 replies
-
For writable state you can do something similar to export const number1 = $state({ value: 5 }); For computed state, you may not even export const number2 = () => number1.value * 2; If you want something similar to export function computed(fn) {
const value = $derived.by(fn);
return { get value() { return value; } };
} (Note on naming: There are precedents in built-in Svelte modules for the value property being called |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am rewriting my TopoEditor from VueJs to Svelte (as all my other projects are now in Svelte).
It has some 100 state variables split between ref/reactive ($state) and computed ($derived). To make code manageable, it uses a number of Typescript files for handling the logic and avoiding passing large number of variables as props between the components.
The way I am solving it is Svelte has much more boiler-plate than in VueJS.
In VueJs, with store.ts as:
the component can use and set the values as follows:
To do the same in Svelte, store.svelte.ts is:
and in the component
store.svelte.ts has roughly 3 times more lines than store.ts (VueJS). With 100 variables, that's a lot.
Am I solving this correctly?
Beta Was this translation helpful? Give feedback.
All reactions