FCF 2.0 development in progress...
> > >
[News] [Packages API] [Downloads] [Donate to the project] [Contacts]

Configuration

The framework uses fcf.Configuration class objects to store configuration data and pass it to program nodes. Objects of this class store configuration settings as fields of the object. And to add configuration parameters to an object, the fcf.Configuration.append method is used.

let configuration = new fcf.Configuration(); configuration.append({ param1: "value1" }); console.log(configuration.param1);

Output:

value1

The framework uses a global configuration object that contains global settings parameters and is available through a call to the fcf.getConfiguration() function. Also, some objects use instances of the fcf.Configuration class to store their settings.

When adding configuration parameters to the fcf.Configuration object, the current parameters are merged with the added ones. The default upgrade is to simply overwrite the configuration setting. But if necessary, you can set merge rules, for this you need to define a merge function and declare it in the merge parameter.

The configuration parameter merge function has the following signature: mixed func(mixed a_current, mixed a_source)

The a_current argument is the value that is currently set in the configuration, and the a_source argument is the value that is passed in as new. The function must return the result of the merge. The a_current and a_source arguments are copies of the original values, so during data merging, it is allowed to write to these arguments.

In order for the fcf.Configuration object to merge using a predefined function, you need to add a merge function to the merge configuration parameter. This parameter is an object, the value of the object element should be the path to the merge function, and the path of the configuration parameter should be the key.

Consider an example of using merge functions:

let configuration = new fcf.Configuration(); (fcf.isServer() ? global : window).mergeFunctions = { param: (a_current, a_source) => { return fcf.append(a_current, a_source); }, subarray: (a_current, a_source) => { return fcf.append(a_current, a_source); } }; configuration.append({ merge: { "param": "mergeFunctions.param", "param.subarray": "mergeFunctions.subarray", }, param: { value1: 1, subarray: [1], } }); console.log("Step 1: ", configuration.param); configuration.append({ param: { value2: 2, subarray: [2], } }); console.log("Step 2: ", configuration.param);

Output:

Step 1: { value1: 1, subarray: [ 1 ] } Step 2: { value1: 1, subarray: [ 1, 2 ], value2: 2 }

The above example shows the declaration of the param configuration parameter, which is an object and is not overwritten, but supplemented when the configuration is added. Also, this parameter contains the subarray field, which, when adding a configuration, complements the array contained in it.