Computations now occupy their own nodes on the dependency graph

This mitigates most issues with properties having self-loops, 
particularly in cases like Strength where the value `strength` is used 
in the description of Strength
This commit is contained in:
Stefan Zermatten
2021-12-07 21:05:24 +02:00
parent 6698d2fd74
commit e34f29f952
17 changed files with 247 additions and 110 deletions

View File

@@ -4,9 +4,13 @@ import { traverse } from '/imports/parser/resolve.js';
export default function linkCalculationDependencies(dependencyGraph, prop, {propsById}){
prop._computationDetails.calculations.forEach(calcObj => {
// Store resolved ancestors
let memo = {
const memo = {
// ancestors: {} //this gets added if there are resolved ancestors
};
// Add this calculation to the dependency graph
const calcNodeId = `${prop._id}.${calcObj._key}`;
dependencyGraph.addNode(calcNodeId, calcObj);
// Traverse the parsed calculation looking for variable names
traverse(calcObj.parseNode, node => {
// Skip nodes that aren't symbols or accessors
@@ -17,10 +21,15 @@ export default function linkCalculationDependencies(dependencyGraph, prop, {prop
node.name.slice(1), memo, prop, propsById
);
if (!ancestorProp) return;
dependencyGraph.addLink(prop._id, ancestorProp._id, calcObj);
// Link the ancestor prop as a direct dependency
dependencyGraph.addLink(
calcNodeId, ancestorProp._id, 'ancestorReference'
);
} else {
// Link variable name references as variable dependencies
dependencyGraph.addLink(prop._id, node.name, calcObj);
dependencyGraph.addLink(
calcNodeId, node.name, 'variableReference'
);
}
});
// Store the resolved ancestors in this calculation's local scope