You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
app.js opens with the runtime, and the page can reach it as window.WF.
Compiled code calls it; so may a hand-written script in public/, a
library's callback, or you in the browser's console:
A build keeps only the modules its own code reaches, so a script calling a
module nothing else uses needs "build": { "runtime": "full" }
(chapter 32). Most names here are what the
compiler emits for the language's features; the ones worth calling yourself
are marked ●.
Events the runtime says
wf:render is dispatched on document once a drawing lands — the first
mount, the takeover of a pre-rendered page, and every route change — with
{ route, params } in detail. A script that finds elements itself listens
for it (JavaScript interop).
State — core
Function
Does
signal(value) ●
A reactive value: call it to read, .set(v), .update(f), .subscribe(f)
computed(fn) ●
A value computed from signals, recomputed when they change
effect(fn) ●
Runs fn, and again when a signal it read changes; a returned function is its cleanup
scoped(fn), onCleanup(fn)
Ownership: what fn creates is disposed of with its scope; onCleanup registers a disposal
Calls fn with every action and the state either side of it; returns the function that stops it
storeSnapshot(name?) ●
What every store — or one — holds
restoreStore(name, values) ●
Puts a store back to what it held
persist(…)
A persist value's storage, versions and migrations
Nothing is recorded while nothing is watching.
Widgets — toast, overlay, announce, field, tooltip, carousel, drawer, form
Function
Does
toast(message, tone, ms) ●
Shows a toast: "success", "danger", "warning", "info"; 3 seconds by default
announce(text) ●
Says text to screen readers, politely
dialog, popup, tabs, menu, drawer, tooltip, carousel, field
What the matching built-ins compile to
form(options), validate(…)
A Form handle and its rules
Safety — core, sanitize
Function
Does
safeUrl(url) ●
The URL where a browser may follow it, "" where it may not
sanitize(html) ●
Markup through the allow-list
jsonAttr(raw)
An attribute holding JSON, as the prop it stands for
Both safeUrl and sanitize have a build-time twin, held to one table of
cases.
Text — text, format
markdown(text) ● renders the language's Markdown to HTML;
highlight(code, lang) ● colours wf, json, bash or css;
format(value, style, option) ● and ago(date) ● format in the locale.
Values — helpers, scalars
The list and string helpers (sortBy, groupBy, unique, take,
first, last, capitalize, truncate, dedent, lines, words,
range, removeAt) and the built-in types' methods (plus, minus,
until, year … inZone, money, times, convert, host, path,
domain, mix, lighten, darken, alpha, contrast, preview,
uuid, dateOf, timeOf, urlWith, urlQuery), and caseOf(v) and
payload(v) for an enum case — each a function of the value it works on.
Everything else
Module
Functions
i18n
locales(default, tables) → WF.i18n, with t, locale, dir, setLocale
offline
offline(options), update() — the service worker and the update flow
head
head(tags) — a page's own head tags
host
attach(node, mount, update, cleanup) — what mount:, update: and cleanup: compile to, on Host or any element; a component's fragment is attached at its root element. portal(box, read) — what a Portal compiles to: box is kept in the element (or ref: handle) read() names, read again when what it reads changes and once the drawing is over, kept aside on null, and taken away with its scope; it returns what runs the lifetimes its block asked for while it was drawn
picture
picture(…) — an image's <picture>
hydrate
hydrate(fn, container), hydrating(root) — draw beside a pre-rendered page and take it over in place
core
mount(fn, container), mainOf(root) — boot; live(node) — something holds node, so a takeover keeps the drawn one rather than the painted one