-
Notifications
You must be signed in to change notification settings - Fork 93
Custom Javascript Code Mechanisms (v1)
This is a quick brain dump of the current state (v4) of the Javascript systems in Paco.
There are two:
- Execute Script actions
- Custom Form Rendering/Custom Feedback Rendering
They are different in that the Execute Script actions are executed based upon trigger events and run headless in a Javascript interpreter with bridge objects from the phone platform into the Javascript environment to provide Paco services to the JS writer.
The Custom Form/Feedback Rendering embed the same objects, but within the embedded webview with a Javascript engine.
The javascript api code for the execute script actions is currently in
https://github.com/google/paco/blob/develop/Paco/assets/custom_base_interpreter.js
The javascript api code for the custom rendering is currently in
https://github.com/google/paco/blob/develop/Paco/assets/custom_base.js
These two are identical other than that one is headless and the other is within a webview. The headless one does not have jquery and it does not have any of the paco.renderer module for rendering form elements. They need to be refactored to get rid of duplication.
The custom_base_interpreter.js is used in the class https://github.com/google/paco/blob/develop/Paco/src/com/pacoapp/paco/js/interpreter/AndroidJsInterpreterBuilder.java
The custom_base.js is used in the class https://github.com/google/paco/blob/develop/Paco/src/com/pacoapp/paco/ui/ExperimentExecutorCustomRendering.java
Look in the renderWebView
method to see how it is set up.
and in the class
https://github.com/google/paco/blob/develop/Paco/src/com/pacoapp/paco/ui/FeedbackActivity.java
Look in the onCreate
method to see how it mostly does the same as renderWebView
in the ExperimentExecutor
.
Basically, the interpreter own what is happening. These classes set up the interpreter and provide it with the necessary services.
The javascript api uses base layers of javascript functions which are platform specific to get access to native services such as the database, the experiment definition, the notification tray, step sensors, and others. These base apis are provided by each platform as bridge objects that provide js callable functions that trigger native actions.
You can find the bridge object implementations in the package:
https://github.com/google/paco/tree/develop/Paco/src/com/pacoapp/paco/js/bridge.