Looking for advice on how to refactor my logic to access the namesSplit variable in the evaluateResult function within my executable variable node class. Any suggestions?
export class ExecutableVariableNode implements IExecutableNode {
execute(treeNode: ExpressionTreeNode, exprData: ExpressionData): any {
let namesSplit = treeNode.name.split('.');
let key = namesSplit[0];
let contextEntry = exprData.contextEntry.find(_x => _x.name === key);
if (namesSplit.length > 1) {
this.evaluateResult(contextEntry.value);
}
}
isPrimitive(test): boolean {
return typeof test !== 'object';
}
// Get Values
evaluateResult(val) {
if (this.getType(val) === ExpressionVariableType.OBJECT) {
return Object.values(val);
}
else if (this.getType(val) === ExpressionVariableType.ARRAY_OF_OBJECTS) {
for (let obs of val) {
for (let n = 0; n < namesSplit.length; n++) {
if (namesSplit[n] == Object.keys(obs)) {
let result = Object.values(obs);
console.log(result);
break;
}
}
}
}
else if (this.getType(val) === LapsExpressionVariableType.ARRAY_OF_PRIMITIVES) {
throw new StdException('Array of Primitives not allowed!');
}
else if (this.getType(val) === LapsExpressionVariableType.PRIMITIVE) {
throw new StdException('Primtive values not allowed!');
}
}
}