Home/Docs/Watchers
Reactivity

Watchers

Declare const watcher = { ... } with a function per state key; it fires on change with (oldValue, newValue).

Component.html
<script>
  const state = { count: 0, log: "—" };
  const watcher = {
    count(old, next) {
      state.log = `count: ${old} → ${next}`;
    },
  };
</script>
<p>{state.count}{state.log}</p>