Client-Side vs Web-Side Engines
Last updated
Last updated
FormIt plugins utilize two distinct JavaScript engines:
The panel displaying the HTML (Web-Side)
The Client-side (FormIt) makes calls to FormIt and its geometry kernel.
These two JavaScript engines work in distinct processes.
FormIt runs multiple JavaScript engines simultaneously:
The FormIt application has its own JavaScript engine
Each plugin Toolbar has its own JavaScript engine.
Each plugin Panel has its own JavaScript engine (Chromium)
Plugins can specify where the JavaScript is loaded:
Specified using manifest.json
Specified using index.html
Web-side scripts are loaded from the web page.
Web-side scripts can call into the Client-Side (FormIt) JavaScript using multiple async calls.
CallMethod
takes a function name and the arguments that will run on the FormIt Side. The passed-in function will be called with the result of the function call.
Pros:
➕ Noawait
needed.
Cons:
➖ A callback is needed to get the result and is called “who knows when”.
➖ Scripts are defined in two different places.
➖ Requires plugin logic to be split into two different files.
*Available in FormIt 2022.1 and newer only
CallJS takes the JavaScript function to be called on the FormIt Side and the arguments.json object.
Pros:
➕ The result is available when needed
Cons:
➖ **** Have to decorate all the async calls with await, forgetting to do so will mess things up.
➖ **** Potentially slower due to await
With an async call, the Web Side calls the FormIt Side. This call starts in one process, sent to another process, then the result is passed back to the starting process. This is why await is needed.
Only built-in FormIt APIs can be called by default.
Pros:
➕ The result is available when needed.
➕ Allows combining all code into one JS file run from the web side, with no scripts defined in manifest.json.
Cons:
➖ **** Have to decorate all the async calls with await
, forgetting to do so will mess things up.
➖ **** Potentially slower due to await.
*Available in FormIt 2023.0 and newer only
To call a user defined function on the FormIt Side, the function needs to be registered. For example:
Client-Side (FormIt)
Web-Side (HTML)
See HelloBlockAsync for an example.
Pros:
➕ The result is available when needed.
➕ Allows combining all code into one JS file run from the web side, with no scripts defined in manifest.json.
Cons:
➖ **** Have to decorate all the async calls with await, forgetting to do so will mess things up.
➖ **** Potentially slower due to await.