Skip to main content

Part 1 / Reactivity / Statements

リアクティブな を宣言するだけでなく、任意の ステートメント をリアクティブに実行することもできます。例えば、count の値が変化するたびにログを取ることができます。

let count = 0;

$: console.log(`the count is ${count}`);

ブロックで簡単にステートメントをグループ化することができます。

$: {
	console.log(`the count is ${count}`);
	alert(`I SAID THE COUNT IS ${count}`);
}

if ブロックなどの前に $: を置くこともできます。

$: if (count >= 10) {
	alert('count is dangerously high!');
	count = 0;
}

Next: Updating arrays and objects

initialising