...
An Error will be thrown if there are any problems loading the module, such as a file not found or syntax error.
ExamplesExample 1.
Code Block | ||||
---|---|---|---|---|
| ||||
function increment() { // x and y must be declared in the parent scope where pjs.import() is used x += 1; y += 2; } exports.increment = increment; |
...
Code Block | ||||
---|---|---|---|---|
| ||||
function main() {
pjs.define("x", { type: "integer" });
pjs.define("y", { type: "integer" });
x = 1;
y = 2;
pjs.import("./main/*.js");
increment();
decrement();
decrement();
console.log(x, y); // outputs 0 0
}
exports.run = main; |
Example 2.
2.1. Create a module containing the external function to called by the main app.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
function mainExternal() { let myOtherString = "I am imported."; return myOtherString; } exports.handleImport = mainExternal; |
2.2. Create a module that serves as the main app, configured as the App Start File or Route. [ Reference: "Configuring Routes to Run Profound.js Modules", Using Workspaces. https://docs.profoundlogic.com/display/PUI/Using+Workspaces ]
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
function mainLocal() {
pjs.import("./myexternalfile.js");
let myString = "I am local.";
pjs.messageBox(myString);
myString = handleImport();
pjs.messageBox(myString);
}
exports.run = mainLocal; |
2.3. On the Profound.js IDE, go to [ Home Ribbon -> Launch -> Launch App in Browser Tab ]. The app will display "local" first and "imported" next on message boxes.