next up previous contents
Next: Node IDs Up: Client-Side Programming Previous: Client-Side Programming   Contents

The Basics

All of the functions in this subsection are client-side only.

Clients can open alert and confirm dialog boxes, in the usual annoying JavaScript way.

\begin{displaymath}\begin{array}{l}
\mathsf{val} \; \mathsf{alert} : \mathsf{st...
...f{string} \to \mathsf{transaction} \; \mathsf{bool}
\end{array}\end{displaymath}

Any transaction may be run in a new thread with the $ \mathsf{spawn}$ function.

\begin{displaymath}\begin{array}{l}
\mathsf{val} \; \mathsf{spawn} : \mathsf{tr...
...hsf{unit} \to \mathsf{transaction} \; \mathsf{unit}
\end{array}\end{displaymath}

The current thread can be paused for at least a specified number of milliseconds.

\begin{displaymath}\begin{array}{l}
\mathsf{val} \; \mathsf{sleep} : \mathsf{int} \to \mathsf{transaction} \; \mathsf{unit}
\end{array}\end{displaymath}

A few functions are available to registers callbacks for particular error events. Respectively, they are triggered on calls to $ \mathsf{error}$ , uncaught JavaScript exceptions, failure of remote procedure calls, the severance of the connection serving asynchronous messages, or the occurrence of some other error with that connection. If no handlers are registered for a kind of error, then a JavaScript alert() is used to announce its occurrence. When one of these functions is called multiple times within a single page, all registered handlers are run when appropriate events occur, with handlers run in the reverse of their registration order.

\begin{displaymath}\begin{array}{l}
\mathsf{val} \; \mathsf{onError} : (\mathsf...
...sf{unit}) \to \mathsf{transaction} \; \mathsf{unit}
\end{array}\end{displaymath}

There are also functions to register standard document-level event handlers.

\begin{displaymath}\begin{array}{l}
\mathsf{val} \; \mathsf{onClick} : (\mathsf...
...sf{unit}) \to \mathsf{transaction} \; \mathsf{unit}
\end{array}\end{displaymath}

Versions of standard JavaScript functions are provided that event handlers may call to mask default handling or prevent bubbling of events up to parent DOM nodes, respectively.

\begin{displaymath}\begin{array}{l}
\mathsf{val} \; \mathsf{preventDefault} : \...
...ropagation} : \mathsf{transaction} \; \mathsf{unit}
\end{array}\end{displaymath}

Finally, here is an HTML tag to leave a marker in the <head> of a document asking for some side-effecting code to be run. This pattern is much less common in Ur/Web applications than in normal HTML/JavaScript applications; see Section 8.6.3 for the more idiomatic, functional way of manipulating the visible page.

\begin{displaymath}\begin{array}{l}
\mathsf{val} \; \mathsf{script} : \mathsf{u...
...; \mathsf{unit}] \; \mathsf{head} \; [] \; [] \; []
\end{array}\end{displaymath}

Note that the Ur/Web version of <script> is used like <script code={...}/>, rather than <script>...</script>.


next up previous contents
Next: Node IDs Up: Client-Side Programming Previous: Client-Side Programming   Contents
2014-07-14