Text and expressions

A text hole evaluates a Rust expression. In text, a bare signal or memo name is read automatically. An attribute expression, such as the condition of a class: directive, is used as written; read its signal explicitly.

<p>{count}</p>
<div class="card" class:dark={dark.get()}>Content</div>

Classes are literal (class="card") or toggled with class:name={bool}, which adds name while the expression is true. class={expression} and style={expression} are refused at build time: the compiler must see every class name and declaration an element can have, so it can analyse the component’s styles. To choose among several classes, write one class: directive per class. Declarations go in the style section, under a class.

Templates use a fixed HTML vocabulary. A capitalised tag names a component. Unknown lowercase tags are refused. Void elements such as input and br close themselves; other elements must be closed.

The compiler accepts more tags than the element tree draws at this revision. textarea, select, HTML list elements (ul, ol, li), tables, br and a compile, but the document refuses them when it updates. Elements and events lists both sets.

Events and input bindings

An attribute named on plus an event name listens for that event: onclick listens for click. A script closure with no parameters can be used as a handler; a handler that needs the event can take a mutable event reference. Events bubble. The event exposes stop_propagation() and prevent_default(), and a pointer event its position. A handler may return Result<(), E> for any E: Display; an Err is reported as a refusal.

The element tree fires pointer, keyboard, focus, input and change events; Elements and events lists them. The compiler accepts other event names, and the document refuses a listener for any event it never fires. A handler that assigns to a captured binding is refused by the compiler.

input.wisp
<script>let draft: Signal<String> = Signal::new(String::new());</script><style>:global(body) { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; padding: 16px; }input { width: 240px; }</style><input bind:value={draft} /><p>You typed: {draft}</p>
vapors component source

bind:value connects the live value of an input, textarea or select to a signal: a Signal<String> for a text field, a Signal<f64> for a number or range input. bind:checked connects a checkbox or radio’s checked state to a Signal<bool>. The compiler refuses a binding combined with a handler for the same control event. Use one owner for that update.

The element tree draws input of type text, number, range and checkbox, so the example above runs. It does not draw textarea, select or a radio button: a document holding a binding on one of those refuses it on its next update.

bind:this={handle} on an element gives the script its node: a Signal<Option<NodeId>>, or inside a keyed {for} a Signal<BTreeMap<K, NodeId>> with one entry per row. It is refused on a component tag.

Conditions create branches

{if condition} selects a branch. Read a boolean signal explicitly in the condition. An optional {else} supplies the other branch; there is no {else if} syntax at this revision.

conditional.wisp
<script>let shown: Signal<bool> = Signal::new(true);</script><style>:global(body) { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; padding: 16px; }</style><input type="checkbox" bind:checked={shown} />{if shown.get()}  <p>The details are visible.</p>{else}  <p>The details are hidden.</p>{/if}
vapors component source

When the selected branch changes, the old branch’s owner is disposed and its nodes are removed. This differs from leaving both branches mounted and changing their visibility.

Keys identify rows

A {for} block reads a collection and uses a key to match its rows across updates. A kept row keeps its nodes. Its item and index signals update in place; reordering moves nodes rather than rebuilding every row.

list.wisp
<script>let rows: Signal<Vec<u32>> = Signal::new(vec![1, 2, 3]);let next_id: Signal<u32> = Signal::new(4);let add = move || {    let id = next_id.get();    rows.update(|items| items.push(id));    next_id.set(id + 1);};let reverse = move || rows.update(|items| items.reverse());let remove = move || rows.update(|items| { items.pop(); });</script><style>:global(body) { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; padding: 16px; }button { padding: 8px 12px; }</style><button onclick={add}>Add</button><button onclick={reverse}>Reverse</button><button onclick={remove}>Remove last</button><div>  {for row in rows.get() key=row}    <div>{row}</div>  {/for}</div>
vapors component source

Without a key expression, the index is used as the key. Pick an explicit stable key when items can move. Duplicate keys are refused before the rows are touched; the existing rows remain, and a subsequent valid update can proceed.

Template loops work with supported containers such as div; they do not require HTML list elements. The keyed-list lesson includes add, remove and reorder controls.

Components receive props

A capitalised tag must name a component type available in the script, with its corresponding props type. Unspecified props take their defaults. Plain props are read at mount; signal props share a reactive handle. The cards demo composes parent and child components.

Children and snippets

Content inside a component tag becomes the child’s children prop, declared as #[prop] let children: Snippet = Snippet::empty(); and placed in the child’s template with {render children()}. The cards demo passes each card’s body that way.

{snippet name(param: Type)}...{/snippet} declares a named template fragment, and {render name(args)} places it; each parameter is reactive (a Memo) and its type is an owned PartialEq + Clone type. A snippet cannot render itself. {render expr(args)} renders an expression that yields a Snippet or Option<Snippet>, such as a snippet passed in as a prop.

A component declares its own events with #[dispatcher(a, b)] let events; in its script and raises them through that handle; a parent listens with ona={...} on the component tag.

Forms that are refused

InputResult
A bare attribute with no valueRefusal naming the accepted form
A repeated attributeRefusal at its source position
An unknown character referenceRefusal at the ampersand
HTML comments or a title elementRefusal with a pointer to the supported approach
{else if}Refusal; nest an {if} inside the {else}
A snippet that renders itself, or bind:this on a component tagRefusal during code generation

The full compiler guide lists the remaining reserved names and deferred forms.