Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert(dataType !== null); // check invalid dataType
let setter_func2 = null;
if (setter_func) {
setter_func2 = function (variant) {
const variable2 = !!variant.value;
setter_func(variable2);
return StatusCodes.Good;
};
}
const nodeId = makeNodeId(id);
// make sur the provided function returns a valid value for the variant type
// This test may not be exhaustive but it will detect obvious mistakes.
assert(isValidVariant(VariantArrayType.Scalar, dataType, func()));
return bindVariableIfPresent(nodeId, {
get: function () {
return new Variant({
dataType: dataType,
arrayType: VariantArrayType.Scalar,
value: func()
});
},
set: setter_func2
});
}
let setter_func2 = null;
if (setter_func) {
setter_func2 = (variant: Variant) => {
const variable2 = !!variant.value;
setter_func(variable2);
return StatusCodes.Good;
};
}
const nodeId = makeNodeId(id);
// make sur the provided function returns a valid value for the variant type
// This test may not be exhaustive but it will detect obvious mistakes.
/* istanbul ignore next */
if (!isValidVariant(VariantArrayType.Scalar, dataType, func())) {
errorLog("func", func());
throw new Error("bindStandardScalar : func doesn't provide an value of type " + DataType[dataType]);
}
return bindVariableIfPresent(nodeId, {
get() {
return new Variant({
arrayType: VariantArrayType.Scalar,
dataType,
value: func()
});
},
set: setter_func2
});
function bindStandardArray(id, variantDataType, dataType, func) {
assert(_.isFunction(func));
assert(variantDataType !== null); // check invalid dataType
const nodeId = makeNodeId(id);
// make sur the provided function returns a valid value for the variant type
// This test may not be exhaustive but it will detect obvious mistakes.
assert(isValidVariant(VariantArrayType.Array, dataType, func()));
bindVariableIfPresent(nodeId, {
get: function () {
const value = func();
assert(_.isArray(value));
return new Variant({
dataType: variantDataType,
arrayType: VariantArrayType.Array,
value: value
});
},
set: null // read only
});
}
function bindStandardArray(
id: number,
variantDataType: DataType,
dataType: any,
func: () => any[]
) {
assert(_.isFunction(func));
assert(variantDataType !== null); // check invalid dataType
const nodeId = makeNodeId(id);
// make sur the provided function returns a valid value for the variant type
// This test may not be exhaustive but it will detect obvious mistakes.
assert(isValidVariant(VariantArrayType.Array, variantDataType, func()));
bindVariableIfPresent(nodeId, {
get() {
const value = func();
assert(_.isArray(value));
return new Variant({
arrayType: VariantArrayType.Array,
dataType: variantDataType,
value
});
},
set: null // read only
});
}