Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
40 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 25 additions & 4 deletions
29
packages/dev/core/src/FlowGraph/Blocks/Data/flowGraphCachedOperationBlock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,29 @@ | ||
import { FlowGraphBlock } from "core/FlowGraph/flowGraphBlock"; | ||
import { FlowGraphContext } from "core/FlowGraph/flowGraphContext"; | ||
import type { IFlowGraphBlockConfiguration } from "../../flowGraphBlock"; | ||
import { FlowGraphBlock } from "../../flowGraphBlock"; | ||
import type { FlowGraphContext } from "../../flowGraphContext"; | ||
import type { FlowGraphDataConnection } from "../../flowGraphDataConnection"; | ||
import type { RichType } from "../../flowGraphRichTypes"; | ||
|
||
const CACHE_NAME = "cachedValue"; | ||
|
||
export class FlowGraphCachedOperationBlock extends FlowGraphBlock { | ||
public _updateOutputs(context: FlowGraphContext) {} | ||
export abstract class FlowGraphCachedOperationBlock<OutputT> extends FlowGraphBlock { | ||
public readonly output: FlowGraphDataConnection<OutputT>; | ||
|
||
constructor(outputRichType: RichType<OutputT>, config?: IFlowGraphBlockConfiguration) { | ||
super(config); | ||
|
||
this.output = this._registerDataOutput("output", outputRichType); | ||
} | ||
public abstract _doOperation(context: FlowGraphContext): OutputT; | ||
|
||
public _updateOutputs(context: FlowGraphContext) { | ||
const cachedValue = context._getExecutionVariable(this, CACHE_NAME + context.executionId); | ||
if (cachedValue !== undefined) { | ||
this.output.setValue(cachedValue, context); | ||
return; | ||
} | ||
const calculatedValue = this._doOperation(context); | ||
context._setExecutionVariable(this, CACHE_NAME + context.executionId, calculatedValue); | ||
this.output.setValue(calculatedValue, context); | ||
} | ||
} |
14 changes: 5 additions & 9 deletions
14
packages/dev/core/src/FlowGraph/Blocks/Data/flowGraphConstantOperationBlock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters