Action Closures

An action closure wraps an action and serializes it so that it can be included into a view as data, and later the runtime can invoke the action.

Syntax

An action without parameter:

action { <statements> }

Here, action is a keyword.

An action with parameter p (there can only be one parameter at most):

action(p) { <statements> }

Here, the variable p is a parameter that can be filled in by the runtime. Because this will be details of the just triggered user event, we’ll call it event in the following.

The statements can be assignments in particular, e.g.

action(p) { input = p }

for storing p in a variable cell input.

Example

> var cell c = null
c : data
> cell q = c
q = null
q : data
> def data = { type: "button", ontap: action(event) { c = ["buttonpress", event] } }
data : data
> data
{ "type": "button", "ontap": { "_rmx_type": "msg_view_invoke", "name": "$closure_6542_0", "env": "$cloenv_1" }}

As you can see, the action closure is translated to an object { "_rmx_type": "msg_view_invoke", "name": "$closure_6542_0", "env": "$cloenv_1" }. This just means that the closure has been serialized as this object, and can be included into the view.

What does the object mean?

> #invoke $closure_6542_0 "$cloenv_1" 42
p = [ "buttonpress", 42 ]