-
-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow any valid node with no incoming connections and with side effec…
…ts to run automatically (#2944) * Allow any valid node with no incoming connections to be a "starting node" * lint * lint * Use side effects to determine whether we should run the node or not * Rename hook * Update .vscode/settings.json
- Loading branch information
1 parent
410e586
commit 5035430
Showing
9 changed files
with
61 additions
and
26 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { getIncomers, useReactFlow } from 'reactflow'; | ||
import { useContext } from 'use-context-selector'; | ||
import { EdgeData, NodeData, SchemaId } from '../../common/common-types'; | ||
import { BackendContext } from '../contexts/BackendContext'; | ||
|
||
/** | ||
* Determines whether a node should use automatic ahead-of-time features, such as individually running the node or determining certain type features automatically. | ||
*/ | ||
export const useAutomaticFeatures = (id: string, schemaId: SchemaId) => { | ||
const { schemata } = useContext(BackendContext); | ||
const schema = schemata.get(schemaId); | ||
|
||
const { getEdges, getNodes, getNode } = useReactFlow<NodeData, EdgeData>(); | ||
const thisNode = getNode(id); | ||
|
||
// A node should not use automatic features if it has incoming connections | ||
const hasIncomingConnections = | ||
thisNode && getIncomers(thisNode, getNodes(), getEdges()).length > 0; | ||
|
||
// If the node is a generator, it should not use automatic features | ||
const isGenerator = schema.kind === 'generator'; | ||
// Same if it has any static input values | ||
const hasStaticValueInput = schema.inputs.some((i) => i.kind === 'static'); | ||
// We should only use automatic features if the node has side effects | ||
const { hasSideEffects } = schema; | ||
|
||
return { | ||
isAutomatic: | ||
hasSideEffects && !hasIncomingConnections && !isGenerator && !hasStaticValueInput, | ||
hasIncomingConnections, | ||
}; | ||
}; |
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