by pcthrowaway · 3y ago · 0 comments
So if you want to update y on some changes to x, you do
$: y = x
And if you need something more complicated, a transformation perhaps, you put the logic in a function and assign y to the result of that function parseX(val) { ... }
$: y = parseX(x)https://svelte.dev/repl/44e3aece18294ddb834bcdfb4394af48?ver...
` <script>
let name = 'world';
const flip = () => name = name === name.toUpperCase() ? name.toLowerCase() : name.toUpperCase()
$: console.log({ name })
</script><h1>Hello {name}!</h1>
<button on:click={flip}>flip!</button> `