Modules
The
-
string name - Module name. Must contain the full path to the module in FCF format. -
[string] dependencies = [] - An array of module dependencies that will be loaded and passed to the module function as arguments. -
[string] lazy = [] - An array of module dependencies that will be loaded after the module function is executed. Dependency data can be used in case of cyclic dependencies and data is accessed via global variables. -
function module - A function that should return module data. Arguments from the array of module dependencies act as parameters.
File declaration example:
modules/dependence.js file:
fcf.module({
name: "modules/dependence.js",
dependencies: [],
lazy: [],
module: () => {
class Dependence {
dosome(){
console.log("Hello world");
}
};
return Dependence;
}
});
modules/main.js file:
fcf.module({
name: "modules/main.js",
dependencies: ["modules/dependence.js"],
lazy: [],
module: (Dependence) => {
let dependence = new Dependence();
return {
dosome: () => {
dependence.dosome();
}
};
}
});
A Javascript file can contain multiple modules, making it easy to load multiple files saved in one file.
Modules can be loaded either by standard means, using
The last parameter of the
Example loading modules/main.js module
let [mainModule] = fcf.require("modules/main.js", {async: false}).
In the above example, the module is loaded synchronously into the
Loading simple JavaScript files.
The framework's modularity mechanism allows you to load simple JS files, if the script file on the server side returns the result of execution through the
To do this, you need to set the
helloWorld.js file
let globalEnvironment = fcf.isServer() ? global : window;
if (!globalEnvironment.variables) {
globalEnvironment.variables = {};
}
globalEnvironment.variables.helloWorld = () => {
console.log("Hello world");
};
main.js file
fcf.getConfiguration().append ({
sources: {
"": {
files: {
"helloWorld.js": { result: "variables.helloWorld" },
}
}
}
});
async function doCallHelloWorld() {
let [helloWorld] = await fcf.require("helloWorld.js");
helloWorld();
}
In order to set the parameters for downloading a file, you first need to declare the source configuration option, which contains options for describing the source files of the package. The key is the name of the package, and the value is the description parameters. The application itself, i.e. the root path of the application, is specified as a package with the name of the empty string ""
The
-
string filePath - A tokenized string containing the path to the file on the browser side. Using tokenization, it is easy to organize the switching of the downloaded file from the debug version to the release version using the user context settings. The following variables are available in the tokenizer:-
string path - Full path to the file -
string directory - File directory -
string shortName - Short filename without extension -
string name - File name -
string extension - File extension
-
-
string result - A string containing the path to a global variable containing the result of the JS module. This option is used to load modules declared without using thefcf.module function. -
string loadState - If the parameter is defined, then the first time the JS module is loaded in the tokenized string, the condition is first determined, and if the result of the calculated string returnstrue , then the module is considered already loaded. This method allows you to load JS modules not declared by thefcf.module function using the script tag and thefcf.require method together (that is, to avoid double loading the module).Example:
fcf.getConfiguration().
append ({ sources: { "jquery": { webMain: "jquery.js", webFiles: { "jquery.js": { result: "jQuery", loadState: "@{{!!window.jQuery}}@", filePath: "@{{directory}}@/@{{shortName}}@@{{!fcf.getContext().debug && name.indexOf(\".min.\") == -1 ? \".min\" : \"\"}}@.@{{extension}}@", } } }, } });
In addition to the