Reference · Browser
waiting
waiting(any) -> boolWhat it does
Whether a component's live state is waiting for an answer: true from the moment the
arguments of its live(load, ...) change until the new value arrives (and while a page
the browser made waits for its first), false otherwise. The state keeps its old value
meanwhile, so a grid that moved to December can say it still shows November. It takes
the state by its name, and what reads it follows it. On the server it is false,
since the server renders with the answer.
Examples
server fn load_month(month: str) = db.query("select * from sales where month = ?", month)component Grid(month: str) { state rows = live(load_month, month) <table class={waiting(rows) ? "stale" : ""}> <caption>{month}{waiting(rows) ? " (loading)" : ""}</caption> {for r in rows => <tr key={r.id}><td>{r.day}</td><td>{r.total}</td></tr>} </table>}Edge cases
- The argument is a
stateof the component, written by its name. Anything else, alet, a prop or an expression, is refused when the program loads:`waiting` takes a component's live state by its name (`state m = live(...)`).quillo checkdoes not see this; the program's load does. - A state that is not live (
state n = 0) compiles, and is never waiting. - It is
trueonly for a load the arguments started, or the first load of a page made in the browser: a loader run again because a table changed keeps showing the old rows until the new ones come, withoutwaitingturning true. - When the loader answers with an error value, the state becomes that error value and
waitingisfalse. - On the server, and in a plain program, it is
falsefor anything.
let rows = [1, 2]print(waiting(rows), waiting(null))false falseErrors
waiting never fails at run time: on the server it is false whatever it is given,
and in the browser a wrong argument is refused before the page runs, as above.
print(waiting(42))falseChaining
It reads as a condition in the markup, together with the state it asks about:
<table class={waiting(rows) ? "stale" : ""}><button disabled={waiting(rows)}>Reload</button>See also
Thread 0 posts
On waiting(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo