Write GSX Views
This guide shows how to author views with Glyim’s GSX syntax: elements, text holes, event and binding directives, and keyed iteration — and how the compiler turns them into blueprints with mutation-specialized patches.
Author a view
Section titled “Author a view”GSX view elements are first-class expressions in Glyim. A complete component from the design’s flagship example:
1use ui::{View, Host, Handler};2
3#[state]4struct Counter {5 count: i32,6 step: i32,7 name: String,8}9
10#[component]11fn CounterView(s: &Counter) -> View {12 <section class="counter" aria-label="Counter">13 <h1>"Hello, {s.name}!"</h1>14
15 <button on:click={|s, _| s.count -= s.step}>"−"</button>16 <output class:warn={s.count < 0}>"{s.count}"</output>17 <button on:click={|s, _| s.count += s.step}>"+"</button>18
19 <input bind:value={s.name} placeholder="Your name" />20
21 {if s.count > 10 {22 <p class="big">"That's a lot."</p>23 } else {24 <></>25 }}26
27 <ul>28 {for item in s.history.iter() by item.id {29 <li>"{item.label}"</li>30 }}31 </ul>32 </section>33}Know the text rules
Section titled “Know the text rules”Text is always a string literal — JSX-style raw text is not part of the syntax, which keeps the lexer unchanged and avoids whitespace-collapsing rules:
1<h1>"Hello, {s.name}!"</h1>The GSX parser splits the literal into static pieces and typed holes at parse time, so each hole’s read-set is syntactically visible and escaping is type-driven. Spaces between siblings are not significant; write " " explicitly when you need one.
Use attributes, spreads, and directives
Section titled “Use attributes, spreads, and directives”| Construct | Syntax | Meaning |
|---|---|---|
| Attribute | name="lit", name={expr} |
Static string or dynamic expression. |
| Bare attribute | disabled |
Equivalent to disabled={true}. |
| Shorthand | {name} |
Equivalent to name={name}. |
| Spread | {..props} |
Typed against the target’s prop struct. |
| Event handler | on:click={handler} |
Handlers are state transformers fn(&mut S, E). |
| Class toggle | class:active={cond} |
Statically decomposed into slots. |
| Style toggle | style:width={px} |
Statically decomposed into slots. |
| Two-way binding | bind:value={place} |
place is a place expression (lvalue). |
Lowercase tags resolve through the active dialect schema — the compiler validates tags, props, events, and children against the schema, never by string matching. Uppercase tags such as <Name …/> resolve through the def-map like any item. Namespaced escapes such as <web:canvas/> and <native:window/> select host-specific dialects.
Control flow is the language
Section titled “Control flow is the language”There are no template directives such as v-if or {#each} — you use Glyim’s native if, match, and for inside { }, and the compiler recognizes those forms as regions:
1{if s.count > 10 {2 <p class="big">"That's a lot."</p>3} else {4 <></>5}}For lists, add a by key expression — a GSX-scoped contextual keyword accepted only in child-position for — to get keyed reconciliation:
1{for item in s.history.iter() by item.id {2 <li>"{item.label}"</li>3}}Run it through the compiler stage
Section titled “Run it through the compiler stage”The glyim-gsx stage is a library: it lowers checked GSX expressions through View IR (skeleton + slots + regions), read/write-set analysis with prefix interference, and mutation-specialized patch functions, then emits flat-u32 blueprints plus an SSR string. The headless, op-recording host mounts, patches, and dispatches views so tests can assert exact update costs — the Counter test in crates/glyim-gsx/tests/counter.rs is the reference walkthrough.
