Hmm. I'm not sure whether that's correct. $: is comparable to Vue's computed instead of a reactive value. Any variables in the component are automatically reactive. External Stores are reactive with a $ prefix.
Yeah, I know nothing about frontend frameworks (Angular was just getting started last time I did any frontend work), and having read about Svelte for the first time just now, the "$:" thing seems pretty reasonable to me.
<script>
let count = 0;
$: doubled = count * 2;
</script>
<p>{count} doubled is {doubled}</p>
I'd be very confused if `doubled` were to somehow automatically update any time the value of `count` changes, if merely defined as a standard variable (e.g. `let doubled = count * 2;`). This would totally break my mental programming model.
I'm not sure what the parent commenter had in mind as an alternative, or how it could be made simpler or terser.
Comments
Hmm. I'm not sure whether that's correct. $: is comparable to Vue's computed instead of a reactive value. Any variables in the component are automatically reactive. External Stores are reactive with a $ prefix.
Yeah, I know nothing about frontend frameworks (Angular was just getting started last time I did any frontend work), and having read about Svelte for the first time just now, the "$:" thing seems pretty reasonable to me.
I'd be very confused if `doubled` were to somehow automatically update any time the value of `count` changes, if merely defined as a standard variable (e.g. `let doubled = count * 2;`). This would totally break my mental programming model.I'm not sure what the parent commenter had in mind as an alternative, or how it could be made simpler or terser.
I've been wrong about all this, I need to go through the tutorials again and try to understand this better. Apologies.