Reference
Reference
Runtime API
window.WF — the runtime every compiled page calls, usable from a script of your own, the console or a library's callback.
This chapter is the reference for window.WF, the runtime every compiled page calls. Look up a function here when a script of your own, a library's callback or the browser's console needs to do what a page does — navigate, show a toast, read a store.
app.js opens with the runtime, and the page reaches it as window.WF. This plain script, in src/, moves to a route, shows a toast and logs what a store holds:
// src/support.js
function openHelp() {
WF.navigate("/about");
WF.toast("Saved", { tone: "success" });
console.log(WF.storeSnapshot("Cart"));
}
Calling the runtime
These rules apply to every function in this chapter:
- Who calls it. The compiled pages call the runtime. So may a project script under
src/or inmeta.scripts, a library's callback, or you in the browser's console. - Which functions to call. Most names here are what the compiler emits for a language feature, listed so you can read the output. The ones meant for your own code are marked ●.
- Modules. The runtime is a set of feature modules. Each table names the module a function belongs to, and a build ships only the modules its own code reaches. The project's own scripts count: a
WF.toast(…)insrc/support.jsshipstoast. Only a call the build cannot see — a name built from a string, a script loaded from another origin — needs"build": { "runtime": "full" }(Call WF from a script).
Events the runtime dispatches
wf:render is dispatched on document once a drawing lands: the first mount, the takeover of a pre-rendered page, and every route change. Its detail is { route, params }. A script that finds elements itself listens for it:
// src/highlight-tables.js
document.addEventListener("wf:render", (e) => {
for (const t of document.querySelectorAll("table.sortable")) t.dataset.route = e.detail.route;
});
See also: JavaScript interop.
State
| Function | Module | What it does |
|---|---|---|
|
|
|
A reactive value: call it to read it; |
|
|
|
A value computed from signals, recomputed when they change. |
|
|
|
Runs |
|
|
|
Runs |
|
|
|
Registers |
|
|
|
A repeating or one-shot timer that stops with the current scope. |
|
|
|
An event listener removed with the current scope. |
|
|
|
An element handle, filled when the element is made; used as the element itself ( |
Elements
| Function | Module | What it does |
|---|---|---|
|
|
|
Makes an element. A function given as an attribute or a child follows the signals it reads. |
|
|
|
A text node that follows what |
|
|
|
A component's props, with defaults filled in. |
|
|
|
Live classes: the classes |
|
|
|
Puts |
|
|
|
Writes the attributes a component call passes onto the component's root element. |
|
|
|
A handler on a component's root element. |
|
|
|
What a bound control holds, typed: a number field's number ( |
|
|
|
Fires a component's declared event. |
Bodies
What the control-flow statements and slots compile to.
| Function | Module | What it does |
|---|---|---|
|
|
|
|
|
|
|
What an |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
A component's slot, drawing the caller's fill. |
|
|
|
A |
Keys, focus and gestures
| Function | Module | What it does |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The combination as |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Motion
| Function | Module | What it does |
|---|---|---|
|
|
|
Plays an animation now, and returns a handle with |
|
|
|
Plays an element's animation again from the start ( |
|
|
|
Enter and exit animations. |
|
|
|
Opens or closes a box to its measured height. |
|
|
|
A number that counts to its new value. |
|
|
|
Plays an animation when the element is scrolled into view. |
|
|
|
An element carried across a route change. |
Routing and pages
| Function | Module | What it does |
|---|---|---|
|
|
|
Moves to a route (a page load in a static build). |
|
|
|
The current route's parameters. |
|
|
|
The router |
|
|
|
Keeps a link's |
|
|
|
Internal: plays a |
|
|
|
Page chunks and their stylesheets. |
|
|
|
Set at boot from the config. |
Browser values
| Function | Module | What it does |
|---|---|---|
|
|
|
What the language's |
|
|
|
|
|
|
|
The theme the reader chose. |
|
|
|
Switches the theme: |
Data and connections
| Function | Module | What it does |
|---|---|---|
|
|
|
A read: |
|
|
|
A request through the engine — retries, timeouts, cache, typed errors — that resolves to the parsed body, and rejects on a failure. |
|
|
|
What |
|
|
|
Shows a change at once, rolled back if the action throws. |
|
|
|
Runs an action so that a throw rolls back its optimistic changes. |
|
|
|
The engine's request itself. |
|
|
|
Drops cached answers — every one with no argument, or each key equal to or starting with |
|
|
|
A post that survives the page unloading. |
|
|
|
The service an |
|
|
|
The runtime's middleware, as a service's |
|
|
|
A socket, a stream of events, a channel between tabs. |
|
|
|
A peer: a WebRTC data channel. |
|
|
|
A |
Stores
| Function | Module | What it does |
|---|---|---|
|
|
|
A store, built the first time something reads it. |
|
|
|
Drops the |
|
|
|
Calls |
|
|
|
What every store, or one, holds. |
|
|
|
Puts a store back to what it held. |
|
|
|
A |
Widgets and layers
| Function | Module | What it does |
|---|---|---|
|
|
|
Shows a toast above everything and says it to a screen reader. |
|
|
|
|
|
|
|
An alert dialog and a promise of the answer: |
|
|
|
Says |
|
|
|
What |
|
|
|
What |
|
|
|
Closes a popup on Escape or a click outside, and returns focus to its trigger. |
|
|
|
A layer drawn in the browser's top layer at an anchor or a point: what |
|
|
|
What |
|
|
|
Where a layer of |
|
|
|
An id no other element of the page has. |
|
|
|
Wires an off-canvas panel to its toggle button: a |
|
|
|
What |
|
|
|
A control's label, hint and error; a |
|
|
|
A |
|
|
|
Internal: asks a |
|
|
|
What |
|
|
|
What |
|
|
|
What |
|
|
|
What |
|
|
|
What |
|
|
|
What |
|
|
|
What |
Calls
| Function | Module | What it does |
|---|---|---|
|
|
|
What an async action's call compiles to: the call already running with those arguments, or a new one (every call, with |
|
|
|
A click or submit handler that marks |
|
|
|
|
Results and JSON
A result is ["ok", value] ("ok" when it holds nothing) or ["err", error]; an enum's case with a payload is [case, …payload] and a bare case its name.
| Function | Module | What it does |
|---|---|---|
|
|
|
|
|
|
|
What |
|
|
|
|
|
|
|
A project script's answer held to its |
|
|
|
A |
|
|
|
A dictionary's |
Safety
| Function | Module | What it does |
|---|---|---|
|
|
|
The URL where a browser may follow it, |
|
|
|
As |
|
|
|
Adds an app's own schemes (from |
|
|
|
Markup through the allow-list. |
|
|
|
An attribute holding JSON, as the prop it stands for. |
safeUrl and sanitize each have a build-time twin, and both twins are held to one shared table of cases.
Text and formatting
| Function | Module | What it does |
|---|---|---|
|
|
|
Renders the language's Markdown to HTML. |
|
|
|
Colours |
|
|
|
Formats a value in the page's locale, as |
|
|
|
A relative time in the page's locale: |
|
|
|
Sets up |
Values
Each of these is a function of the value it works on.
| Functions | Module | What they are |
|---|---|---|
|
|
|
The list and string helpers, and |
|
|
|
A state changed in place — |
|
|
|
The methods of |
|
|
|
The methods of |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
A |
|
|
|
An enum value's case and its payload. |
Boot and interop
| Function | Module | What it does |
|---|---|---|
|
|
|
Draws the app into |
|
|
|
The |
|
|
|
Marks |
|
|
|
Draws beside a pre-rendered page and takes it over in place. |
|
|
|
What |
|
|
|
What |
|
|
|
A page's own |
|
|
|
An |
|
|
|
The service worker, the update flow, and forgetting the writes kept offline. |
|
|
|
Loads the |
|
|
|
The |
|
|
|
What |
|
|
|
For WebFluent Studio. |
portal(box, read) keeps box in the element, or ref: handle, that read() names. It reads read() again when what it reads changes and once the drawing is over, keeps the box aside while read() is null, and takes it away with its scope. It returns what runs the lifetimes its block asked for while it was drawn.
The icons module has no functions: it is the table of glyphs, holding only the icons the program names.