LuxelEspañol

Luxel v0.2 · Guide · part 2 of 2

Views (2)

Contract leafWhere it goesWhat the server sends
collection({ key, fields })‹Collection bind>A list of items, each with its key

Inside a collection item, the fields have their own leaf types: text(), money(), date(), quantity(), number(), status([...]) and value().

What the compiler checks:

  • a bind that names no path is LUXEL-E006 (the message lists the paths and suggests the closest);
  • a Text bound to a collection, or a Collection bound to a single value, is LUXEL-E014;
  • a money Text with children is LUXEL-E011 (put the visible label in label);
  • label on a non-money Text is LUXEL-E011.

The handler side is checked too: .luxel/server.ts types each path, so ctx.set('contacts.summary', 42) is a TypeScript error.

Layout: Stack, Row and as

Stack and Row are plain containers. They have no layout of their own: the layout comes from your stylesheet, through className, as in any CSS project.

as picks the element: main, section, header, footer, div (default), p, form, span, table, thead, tbody, tr, td, th, ul, ol, li, figure. View takes as too (default main).

‹Stack as="table" className="table"> ‹Stack as="thead"> ‹Stack as="tr"> ‹Text id="h-name" as="th">Name‹/Text> ‹Text id="h-email" as="th">Email‹/Text> ‹/Stack> ‹/Stack> {/* ‹Collection as="tbody"> … see Collections */} ‹/Stack>

as="form" has a meaning beyond the element: it groups the Fields that an Action inside it sends.

The layout may nest at most 16 elements (LUXEL-E050). Flatten wrappers that only carry a class.

Classes and stylesheets

  • No inline styles: style is LUXEL-E010. The strict CSP allows no inline style attribute.
  • className takes space-separated tokens matching [a-z][a-z0-9_-]*, at most 8.
  • Stylesheets are files of your project:

// luxel.config.ts styles: ['src/styles.css'], // every page views: { agencies: { loginView: 'login', styles: ['src/agencies.css'] }, // this view only },

For each view the compiler keeps only the CSS rules the view can use. Then:

  • if that CSS fits the inline budget (css.inlineLimit, counted as css.inlineMeasure: see below), it is inlined in a ‹style> that the CSP allows by its hash;
  • if it is larger, the critical part (what the first paint needs) is inlined with its hash and the whole page CSS is linked as one hashed file, applied after the paint;
  • if even the critical part is above the limit, the whole CSS is linked and blocks the paint, and the build warns with LUXEL-W003.

css: { mode: 'auto' | 'inline' | 'link', inlineLimit, inlineMeasure } in luxel.config.ts changes this; auto is the default. inlineMeasure says what inlineLimit counts: 'brotli' (the bytes the CSS adds to the compressed page) or 'raw' (its uncompressed bytes); the default budget is chosen in ADR-059. Inlined CSS travels with every page and is not cached between pages; a linked file is cached, but the first page that needs it waits for it. For measurements, LUXEL_CSS_INLINE_LIMIT and LUXEL_CSS_INLINE_MEASURE override the config (set them for luxel build and luxel-host alike).

Hover, focus and other local presentation come from CSS. There is no JavaScript to toggle classes.

Static data at build time

Because the view runs in Node at build time, you can use anything the build can evaluate:

  • imports of your own files and static data;
  • constants;
  • your own helper components (plain, synchronous functions);
  • .map() over arrays;
  • fragments;
  • cond && ‹X />, where cond is known at build time.

A real example, the month labels under a chart:

const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; ‹Row className="chart__labels"> {MONTHS.map((m, i) => ( ‹Text id={`m${i + 1}`} as="span">{m}‹/Text> ))} ‹/Row>

Each generated Text gets its own id: static texts need one.

A helper component:

// src/components/Notice.tsx import { Status } from '@luxel-framework/ui'; export function Notice({ id }: { id: string }) { return ‹Status id={id} errorClassName="notice notice--error" successClassName="notice notice--success" />; }

‹Notice id="result" />

What you cannot do:

  • read server state at build time (there is none: state arrives per request through bind);
  • return a Promise from a component (LUXEL-E025);
  • throw (LUXEL-E019), or import a module that does not exist (LUXEL-E020);
  • compute with an item field of a collection (see Collections).

cond && ‹X /> decides once, at build time. A part that appears or disappears per user is decided by the server: an empty text, a collection with zero items, a state class, or an item marked unavailable.

Determinism

The compiler runs each view twice. If the two results differ, the build fails with LUXEL-E026. So no Date.now(), no Math.random(), nothing that changes between runs: the same input must give the same bytes. A date or a random id the page needs comes from the server.

Runtime messages

The runtime shows two texts of its own: when the server cannot be reached, and on an unexpected error. The app owns them:

// luxel.config.ts messages: { network: 'Could not reach the server. Check your connection and try again.', unexpected: 'Something went wrong. Reload the page.', },

‹View messages={{ … }}> overrides them for one view.

Edit this page on GitHub

This page: 7.9 KB of JavaScript (Luxel's shared runtime), 0 KB from your app.

Measured when the site is built: the runtime files this page loads, compressed as they are sent.

Made by IntiOps. The Luxel 0.1.0 betas are on npm (0.1.0-beta.1, 0.1.0-beta.2), with an alpha of 0.2 (0.2.0-alpha.1): no external security review yet.