FrontSubmit
Sends an expression to be executed on WLJS Interpreter (frontend / browser)
FrontSubmit[expr_, opts___]
Options
"Window"
specifies a window socket, to which an expression will be sent. Use CurrentWindow to fetch a window object from the evaluation context.
"Tracking"
by the default it is False
. See below which benefits it gives to a user
Tracking
If it is enabled, FrontSubmit
returns a reference to a group of instances created by this submission on the frontend. It is group into an object FrontEndInstanceGroup
.
instanceGroup = FrontSubmit[expr_, opts__, "Tracking"->True];
Why do you need this?
Destroy
It is possible to destroy all instances created in the group by simply calling Delete
Delete[instanceGroup]
It can remove graphics primitives (Disk[]
, Line[]
...) you added to an existing graph, or anything else, which is identifiable as an instance.
Usage with Meta-Markers
Using an extension MetaMarker, one can execute an expression in the context of a specified container
FrontSubmit[expr_, m_MetaMarker, opts___]
Be aware of a context loss in a case of an handler function called from outside the cell. Therefore "Window"
option comes to provide the missing information about a window.
With[{win = CurrentWindow[]},
(* normal evaluation context *)
EventHandler[InputButton[], Function[Null,
(* NO evaluation context *)
FrontSubmit[Alert["Hello World"], "Window" -> win]
(* provided explicitly *)
]]
]
or another example with a timer SetTimeout
With[{win = CurrentWindow[]},
(* normal evaluation context *)
SetTimeout[
(* NO evaluation context *)
FrontSubmit[Alert["Boom"], "Window"->win]
, 3000];
"Hi there!"
]
Please have a look at this guide - Advanced animation
Examples
Calling an WLJS (or Frontend) function
FrontSubmit[Alert["Hello World!"]]
which will produce a pop-up modal window.
Or to call a custom-defined Javascript function
core.ShowReversed = async (args, env) => {
const text = await interpretate(args[0], env);
alert(text..split("").reverse().join(""));
}
FrontSubmit[ShowReversed["Must be reversed..."]];
Controlling ViewBox
A typical graphics figure is usually a ViewBox. Here we mark its instance with a unique ID using MetaMarker
Plot[x, {x,0,1}, Epilog->{MetaMarker["pp"]}]
and then we can destroy it and replace with some other text
FrontSubmit[ViewBox`OuterExpression["Hello World"], MetaMarker["pp"]]
Append objects to a static graph
We can append anything to a graphics canvas without reevaluation of a cell
Plot[x, {x,0,1}, Epilog->{MetaMarker["pp"]}]
and then
FrontSubmit[Arrow[RandomReal[{0,1}, {2,2}]], MetaMarker["pp"]]
to append an arrow to a marked graph