KScript docs
EN

Components

Nesting, identity and lazy rendering

A live component can contain an independent child component. A parent update keeps the child's DOM and state, and a child action uses the signed ancestor state to reconstruct the context it was rendered in. Changing the child's ID mounts a new instance. To update a mounted child from the parent, send it an event.

  • For a list of components that can reorder or change membership, pass each one a unique ID such as <row-editor live-id="editor-{$row.id}" record="{$row}" />. For an explicit <live> block, set its id attribute.
  • Use live-key="{$item.id}" for repeated siblings whose DOM identity should survive a reorder.
  • Use live-ignore for a browser-owned widget. Keep KScript's bound controls and action handlers outside that widget.
  • Use live-replace to build a fresh node on each redraw.
  • Add lazy to initialize and render the block when it enters the viewport, or defer to load just after the document is ready. The optional direct <placeholder> child is rendered before the block mounts.
HTML page
<live id="summary" lazy>
  <placeholder><p role="status">Loading summary…</p></placeholder>
  <state name="shown" value="true" />
  <p @if($shown)>Ready</p>
</live>

Edit this page on GitHub