@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
77 lines (76 loc) • 2.69 kB
JavaScript
"use strict";
export class DependenciesController {
constructor(param) {
this.param = param;
this._cyclicGraphDetected = false;
this.methodDependencies = [];
}
setError(message) {
this._errorMessage = this._errorMessage || message;
}
errorMessage() {
return this._errorMessage;
}
reset() {
this.param.graphDisconnectPredecessors();
this.methodDependencies.forEach((methodDependency) => {
methodDependency.reset();
});
this.methodDependencies = [];
}
update(functionGenerator) {
this._cyclicGraphDetected = false;
this._connectImmutableDependencies(functionGenerator);
this.methodDependencies = functionGenerator.methodDependencies;
this._handleMethodDependencies();
this._listenForNameChanges();
}
_connectImmutableDependencies(functionGenerator) {
const dependendies = functionGenerator.immutableDependencies;
for (const dependency of dependendies) {
if (this._cyclicGraphDetected == false) {
if (this.param.addGraphInput(dependency) == false) {
this._cyclicGraphDetected = true;
this.setError("cannot create expression, infinite graph detected");
this.reset();
return;
}
}
}
}
_handleMethodDependencies() {
this.methodDependencies.forEach((methodDependency) => {
if (this._cyclicGraphDetected == false) {
this._handleMethodDependency(methodDependency);
}
});
}
_handleMethodDependency(method_dependency) {
const node_simple = method_dependency.resolved_graph_node;
if (node_simple) {
if (!this.param.addGraphInput(node_simple)) {
this._cyclicGraphDetected = true;
this.setError("cannot create expression, infinite graph detected");
this.reset();
return;
}
}
}
_listenForNameChanges() {
this.methodDependencies.forEach((methodDependency) => {
methodDependency.listen_for_name_changes();
});
}
// private connect_missing_paths(function_generator: FunctionGenerator){
// const jsep_nodes_by_missing_paths = function_generator.jsep_nodes_by_missing_paths
// const missing_paths = Object.keys(jsep_nodes_by_missing_paths)
// missing_paths.forEach((missing_path)=>{
// const fullPath = CoreWalker.make_absolute(this.param.node(), missing_path)
// const jsep_nodes = jsep_nodes_by_missing_paths[missing_path]
// jsep_nodes.forEach(jsep_node=>{
// const missing_expression_reference = this.references_controller.register(this.param, jsep_node, fullPath)
// this.missing_expression_references_by_id[missing_expression_reference.id] = missing_expression_reference
// })
// })
// }
}