mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-27 01:39:47 +00:00
[Refactor] Prefer modern for..of loops (#566)
- Replaces traditional incrementing `for` loops and `forEach()` calls with modern `for..of` syntax - Improves readability - Semantic checking used; not expecting issues to arise from this portion
This commit is contained in:
@@ -658,8 +658,7 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
|
||||
|
||||
const nodes = this.computeExecutionOrder(false, true)
|
||||
const columns: LGraphNode[][] = []
|
||||
for (let i = 0; i < nodes.length; ++i) {
|
||||
const node = nodes[i]
|
||||
for (const node of nodes) {
|
||||
const col = node._level || 1
|
||||
columns[col] ||= []
|
||||
columns[col].push(node)
|
||||
@@ -667,14 +666,12 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
|
||||
|
||||
let x = margin
|
||||
|
||||
for (let i = 0; i < columns.length; ++i) {
|
||||
const column = columns[i]
|
||||
for (const column of columns) {
|
||||
if (!column) continue
|
||||
|
||||
let max_size = 100
|
||||
let y = margin + LiteGraph.NODE_TITLE_HEIGHT
|
||||
for (let j = 0; j < column.length; ++j) {
|
||||
const node = column[j]
|
||||
for (const node of column) {
|
||||
node.pos[0] = layout == LiteGraph.VERTICAL_LAYOUT ? y : x
|
||||
node.pos[1] = layout == LiteGraph.VERTICAL_LAYOUT ? x : y
|
||||
const max_size_index = layout == LiteGraph.VERTICAL_LAYOUT ? 1 : 0
|
||||
@@ -751,7 +748,9 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
|
||||
* @param action Action to run for every canvas
|
||||
*/
|
||||
canvasAction(action: (canvas: LGraphCanvas) => void): void {
|
||||
this.list_of_graphcanvas?.forEach(action)
|
||||
const canvases = this.list_of_graphcanvas
|
||||
if (!canvases) return
|
||||
for (const canvas of canvases) action(canvas)
|
||||
}
|
||||
|
||||
/** @deprecated See {@link LGraph.canvasAction} */
|
||||
@@ -1057,9 +1056,9 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
|
||||
const snapTo = this.getSnapToGridSize()
|
||||
if (!snapTo) return
|
||||
|
||||
getAllNestedItems(items).forEach((item) => {
|
||||
for (const item of getAllNestedItems(items)) {
|
||||
if (!item.pinned) item.snapToGrid(snapTo)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1297,18 +1296,18 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
|
||||
/** @todo Clean up - never implemented. */
|
||||
triggerInput(name: string, value: any): void {
|
||||
const nodes = this.findNodesByTitle(name)
|
||||
for (let i = 0; i < nodes.length; ++i) {
|
||||
for (const node of nodes) {
|
||||
// @ts-expect-error
|
||||
nodes[i].onTrigger(value)
|
||||
node.onTrigger(value)
|
||||
}
|
||||
}
|
||||
|
||||
/** @todo Clean up - never implemented. */
|
||||
setCallback(name: string, func: any): void {
|
||||
const nodes = this.findNodesByTitle(name)
|
||||
for (let i = 0; i < nodes.length; ++i) {
|
||||
for (const node of nodes) {
|
||||
// @ts-expect-error
|
||||
nodes[i].setTrigger(func)
|
||||
node.setTrigger(func)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1390,9 +1389,11 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
|
||||
const link = this._links.get(linkId)
|
||||
if (!link) continue
|
||||
if (link.parentId === before.parentId) link.parentId = rerouteId
|
||||
LLink.getReroutes(this, link)
|
||||
?.filter(x => x.parentId === before.parentId)
|
||||
.forEach(x => x.parentId = rerouteId)
|
||||
|
||||
const reroutes = LLink.getReroutes(this, link)
|
||||
for (const x of reroutes.filter(x => x.parentId === before.parentId)) {
|
||||
x.parentId = rerouteId
|
||||
}
|
||||
}
|
||||
|
||||
return reroute
|
||||
|
||||
Reference in New Issue
Block a user