Reference · Browser

waiting

signature
waiting(any) -> bool

What 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

in a program
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

let rows = [1, 2]print(waiting(rows), waiting(null))
output
false false

Errors

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))
output
false

Chaining

It reads as a condition in the markup, together with the state it asks about:

in a program
<table class={waiting(rows) ? "stale" : ""}><button disabled={waiting(rows)}>Reload</button>

See also

live, watch, publish

Thread
6Useful? Like it, or add to its thread below.

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