Configuration
The framework uses
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
When adding configuration parameters to the
The configuration parameter merge function has the following signature:
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
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.