Lifecycle

Lifecycle blocks give you a place to set up and clean up per‑element behavior.

construct

Runs once when the behavior binds to an element.

behavior .card {
  construct {
    ready = true;
  }
}

destruct

Runs when the element is removed or the behavior is unbound.

behavior .card {
  destruct {
    console.log("bye");
  }
}

Ordering

Order matters:

1) declarations (state + bindings)
2) construct
3) on blocks

If you need state or bindings in construct, define them above it.

Cleanup pattern

behavior .panel {
  on click() { open = !open; }

  destruct {
    open = false;
  }
}