-
Notifications
You must be signed in to change notification settings - Fork 491
refactor: centralized node mode management to layoutStore #8045
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,14 +7,14 @@ import { | |
| LGraphGroup, | ||
| type LGraphNode | ||
| } from '@/lib/litegraph/src/litegraph' | ||
| import { layoutStore } from '@/renderer/core/layout/store/layoutStore' | ||
| import { useSettingStore } from '@/platform/settings/settingStore' | ||
| import type { ComfyExtension } from '@/types/comfy' | ||
|
|
||
| import { app } from '../../scripts/app' | ||
|
|
||
| function setNodeMode(node: LGraphNode, mode: number) { | ||
| node.mode = mode | ||
| node.graph?.change() | ||
| layoutStore.setNodeMode(node.id.toString(), mode) | ||
| } | ||
|
Comment on lines
16
to
18
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Good refactor to centralized mode management. The function now correctly delegates to ♻️ Optional: Use batch mode update function setNodeMode(node: LGraphNode, mode: number) {
layoutStore.setNodeMode(node.id.toString(), mode)
}
+
+function setNodesModeForGroup(nodes: LGraphNode[], mode: number) {
+ const nodeIdModes: Record<string, number> = {}
+ for (const node of nodes) {
+ nodeIdModes[node.id.toString()] = mode
+ }
+ layoutStore.setNodesMode(nodeIdModes)
+}Then update the callbacks to use the batch function instead of looping. 🤖 Prompt for AI Agents |
||
|
|
||
| function addNodesToGroup(group: LGraphGroup, items: Iterable<Positionable>) { | ||
|
|
||
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.
🧹 Nitpick | 🔵 Trivial
Consider batch mode updates for subgraph children.
When traversing subgraph nodes, each child triggers a separate
layoutStore.setNodeModecall. For large subgraphs, usinglayoutStore.setNodesModewith a pre-collected map of node IDs to modes could be more efficient.♻️ Optional: Collect child nodes and batch update
// If this selected node is a subgraph, apply the same mode uniformly to all its children // This ensures predictable behavior: all children get the same state as their parent if (selectedNode.isSubgraphNode?.() && selectedNode.subgraph) { + const childNodeModes: Record<string, number> = {} traverseNodesDepthFirst([selectedNode], { visitor: (node) => { // Skip the parent node since we already handled it above if (node === selectedNode) return undefined - // Apply the parent's new mode to all children uniformly - layoutStore.setNodeMode(node.id.toString(), newModeForSelectedNode) + childNodeModes[node.id.toString()] = newModeForSelectedNode return undefined } }) + if (Object.keys(childNodeModes).length > 0) { + layoutStore.setNodesMode(childNodeModes) + } }🤖 Prompt for AI Agents