| > It doesn't throw a bunch of alien syntax at you, expecting you to decipher it like an ancient scroll Sounds promising, but the first examples contrasts a React `useEffect` hook (a simple function call, into which you pass a callback and a dependency array) with <script>
$: {
console.log("Count Changed!", count)
}
</script>
<!-- html -->
Which prompted in me roughly these questions:- Is this actually just JavaScript? - Oh, is `$` a label? [I googled this to confirm it is] - I thought JavaScript didn't have a `goto` statement? [I googled this to confirm it doesn't] - How does this ever get invoked? [I still don't know the answer to this question -- MDN says that labels can only be used with `break` and `continue` statements] - Does it get invoked only when `count` changes? - If so, how? - If not, how do I specify the dependencies? It might 'just work', but it's also not 'just JavaScript'. |
Initially the same way it would without the $: { ... } wrapper - that is true both for Svelte and vanilla JavaScript.
> Does it get invoked only when `count` changes?
It's invoked whenever a named variable that is mentioned in the block is explicitly assigned to.
That's the whole "magic" here really. It's "just" JS in the sense that there's no additional syntax introduced that would make it incompatible with any of the available JS parsers, so by extension TS parsers as well.