Ajo

API reference

The entry points, the stateful host and the special attributes, with the full reference in the README.

The entry points are ajo, ajo/context, ajo/html and the JSX runtime, ajo/jsx-runtime with its twin ajo/jsx-dev-runtime. The README’s API reference lists every export and the members of the stateful host, and the package’s types.d.ts declares each signature and type. This page covers what those leave implicit. Types are imported from ajo with import type.

ajo

TypeScript
render(h: Children, el: ParentNode, child?: ChildNode | null, ref?: ChildNode | null): void

render reconciles the children of el with h, from child (default: el.firstChild) up to, but not including, ref (default: the end). Nodes outside that range are not touched. render(null, el) empties el and ends the stateful components that were inside it. Calling render again on the same container updates it in place.

ajo/context

context(fallback) returns a function: call it without arguments to read the nearest value, or with a value to write it for the calling component and its descendants. Context functions only work during a render. Outside one, a read returns the fallback and a write is ignored. current() returns the stateful component whose render is in progress, or null; during server rendering it is the protocol-only host. See Context.

ajo/html

render(h) returns an HTML string synchronously. Stateful components run once and are finished right after; see Server rendering for the output rules.

ajo/jsx-runtime

The compiler imports jsx, jsxs, jsxDEV and Fragment when the JSX import source is ajo; application code rarely calls them. The args object becomes the element, with nodeName and key added to it.

TSX
import { jsx } from 'ajo/jsx-runtime'

jsx('button', { class: 'save', children: 'Save' }) // the same as <button class="save">Save</button>

The stateful host

Inside a stateful component, this is the host: a DOM element, typed from the component’s tag, with the iterator, signal, next, throw and return added. A ref on the component receives the same object, and Lifecycle shows each member in use. A component picks its tag with is and default host attributes with attrs; an attr: value written in JSX replaces the default of the same name.

During server rendering, the host is not an element: it only has the iterator, signal, next, return and throw. There, next and return do nothing and throw rethrows immediately.

Special attributes

AttributeTypeOn an elementOn a stateful component
keystring | numberIdentifies it among its siblings.Identifies the host.
memounknownSkips updates while unchanged: an array is compared item by item, any other value with ===; memo alone renders once.The same, for renders of the parent.
skipbooleanAjo leaves its children alone.The component does not render.
ref(el: TElement | null) => voidReceives the element, and null when it is removed.Receives the host, and null when it is removed.
set:nameThe property’s typeAssigns the DOM property.Assigns the DOM property on the host.
attr:nameunknownNot special on elements.Sets an HTML attribute on the host.

class and style accept string | boolean | null, and xmlns a string. On a stateless component, every name, special or not, is an ordinary arg. Component args must be assignable to Args; TypeScript shows how to declare them.

Full reference: ajo README.md#api-reference, ajo types.d.ts