Skip to content

Commit

Permalink
Merge pull request #302 from receptron/parse_update_early
Browse files Browse the repository at this point in the history
parse update early
  • Loading branch information
snakajima authored May 10, 2024
2 parents 0833ea9 + 4ff3a28 commit 66f17c6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/graphai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ export class GraphAI {
return nodes;
}

private getValueFromResults(key: string, results: ResultDataDictonary<DefaultResultData>) {
const source = parseNodeName(key, this.version);
private getValueFromResults(source: DataSource, results: ResultDataDictonary<DefaultResultData>) {
return getDataFromSource(source.nodeId ? results[source.nodeId] : undefined, source);
}

Expand All @@ -82,7 +81,7 @@ export class GraphAI {
const update = node?.update;
if (update && previousResults) {
const result = this.getValueFromResults(update, previousResults);
this.injectValue(nodeId, result, update);
this.injectValue(nodeId, result, update.nodeId);
}
}
});
Expand Down Expand Up @@ -243,7 +242,8 @@ export class GraphAI {

// Notice that we need to check the while condition *after* calling initializeNodes.
if (loop.while) {
const value = this.getValueFromResults(loop.while, this.results(true));
const source = parseNodeName(loop.while, this.version);
const value = this.getValueFromResults(source, this.results(true));
// NOTE: We treat an empty array as false.
if (Array.isArray(value) ? value.length === 0 : !value) {
return false; // while condition is not met
Expand Down
4 changes: 2 additions & 2 deletions src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,15 @@ export class ComputedNode extends Node {

export class StaticNode extends Node {
public value?: ResultData;
public readonly update?: string;
public readonly update?: DataSource;
public readonly isResult: boolean;
public readonly isStaticNode = true;
public readonly isComputedNode = false;

constructor(nodeId: string, data: StaticNodeData, graph: GraphAI) {
super(nodeId, graph);
this.value = data.value;
this.update = data.update;
this.update = data.update ? parseNodeName(data.update, graph.version) : undefined;
this.isResult = data.isResult ?? false;
}

Expand Down

0 comments on commit 66f17c6

Please sign in to comment.