-
-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow any valid node with no incoming connections and with side effects to run automatically #2944
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
942897b
Allow any valid node with no incoming connections to be a "starting n…
joeyballentine c014a89
lint
joeyballentine 1e654ae
lint
joeyballentine 3c52429
Use side effects to determine whether we should run the node or not
joeyballentine 8c5f2f9
Rename hook
joeyballentine 108811a
Merge branch 'main' into starter-node-redefine
joeyballentine 5d72b25
Merge branch 'main' into starter-node-redefine
joeyballentine c2a271f
Update .vscode/settings.json
joeyballentine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joeyballentine Making these nodes side-effect nodes is major change. It completely messes up our current system of "only nodes with side effects run" and is going to cause these nodes to be executed unnecessarily.
Why did you make this change in the first place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It actually doesn't mess that up in practice, at least not that I found in testing. I think it's because they already run.
Anyway, I did that because they technically do have side effects. I explained this. We've even talked about similar things before: when I gave every image output a preview, you said they all had side effects. When we talked about giving every node the ability to toggle an image preview inline in the output, you said we'd need a way to toggle side effects on those nodes.
Why is that suddenly not the case now?