[CodeHealth] Improve code readability (#830)

This commit is contained in:
filtered
2025-03-23 08:48:26 +11:00
committed by GitHub
parent d3685bc6df
commit ba7f870e0f
3 changed files with 32 additions and 39 deletions

View File

@@ -856,8 +856,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
if (links) { if (links) {
for (const id of links) { for (const id of links) {
const link = this.graph._links.get(id) const link = this.graph._links.get(id)
if (!link) continue if (link) link.type = type
link.type = type
} }
} }
} }
@@ -1417,9 +1416,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
if (!this.graph) throw new NullGraphError() if (!this.graph) throw new NullGraphError()
const link = this.graph._links.get(linkId) const link = this.graph._links.get(linkId)
if (!link) continue if (link) link.origin_slot--
link.origin_slot--
} }
} }
@@ -1483,9 +1480,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
if (!this.graph) throw new NullGraphError() if (!this.graph) throw new NullGraphError()
const link = this.graph._links.get(input.link) const link = this.graph._links.get(input.link)
if (!link) continue if (link) link.target_slot--
link.target_slot--
} }
this.onInputRemoved?.(slot, slot_info[0]) this.onInputRemoved?.(slot, slot_info[0])
this.setDirtyCanvas(true, true) this.setDirtyCanvas(true, true)
@@ -2641,43 +2636,41 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
for (const [i, link_id] of links.entries()) { for (const [i, link_id] of links.entries()) {
const link_info = graph._links.get(link_id) const link_info = graph._links.get(link_id)
if (link_info?.target_id != target.id) continue
// is the link we are searching for... // is the link we are searching for...
if (link_info?.target_id == target.id) { // remove here
// remove here links.splice(i, 1)
links.splice(i, 1) const input = target.inputs[link_info.target_slot]
const input = target.inputs[link_info.target_slot] // remove there
// remove there input.link = null
input.link = null
// remove the link from the links pool // remove the link from the links pool
link_info.disconnect(graph, "input") link_info.disconnect(graph, "input")
graph._version++ graph._version++
// link_info hasn't been modified so its ok // link_info hasn't been modified so its ok
target.onConnectionsChange?.( target.onConnectionsChange?.(
NodeSlotType.INPUT, NodeSlotType.INPUT,
link_info.target_slot, link_info.target_slot,
false, false,
link_info, link_info,
input, input,
) )
this.onConnectionsChange?.( this.onConnectionsChange?.(
NodeSlotType.OUTPUT, NodeSlotType.OUTPUT,
slot, slot,
false, false,
link_info, link_info,
output, output,
) )
break break
}
} }
} else { } else {
// all the links in this output slot // all the links in this output slot
for (const link_id of links) { for (const link_id of links) {
const link_info = graph._links.get(link_id) const link_info = graph._links.get(link_id)
// bug: it happens sometimes
if (!link_info) continue if (!link_info) continue
const target = graph.getNodeById(link_info.target_id) const target = graph.getNodeById(link_info.target_id)

View File

@@ -199,10 +199,10 @@ export class Reroute implements Positionable, LinkSegment, Serialisable<Serialis
validateLinks(links: ReadonlyMap<LinkId, LLink>, floatingLinks: ReadonlyMap<LinkId, LLink>): boolean { validateLinks(links: ReadonlyMap<LinkId, LLink>, floatingLinks: ReadonlyMap<LinkId, LLink>): boolean {
const { linkIds, floatingLinkIds } = this const { linkIds, floatingLinkIds } = this
for (const linkId of linkIds) { for (const linkId of linkIds) {
if (!links.get(linkId)) linkIds.delete(linkId) if (!links.has(linkId)) linkIds.delete(linkId)
} }
for (const linkId of floatingLinkIds) { for (const linkId of floatingLinkIds) {
if (!floatingLinks.get(linkId)) floatingLinkIds.delete(linkId) if (!floatingLinks.has(linkId)) floatingLinkIds.delete(linkId)
} }
return linkIds.size > 0 || floatingLinkIds.size > 0 return linkIds.size > 0 || floatingLinkIds.size > 0
} }

View File

@@ -54,10 +54,10 @@ export class MovingRenderLink implements RenderLink {
// Store output info // Store output info
const outputNode = network.getNodeById(outputNodeId) ?? undefined const outputNode = network.getNodeById(outputNodeId) ?? undefined
if (!outputNode) throw new Error(`Creating DraggingRenderLink for link [${link.id}] failed: Output node [${outputNodeId}] not found.`) if (!outputNode) throw new Error(`Creating MovingRenderLink for link [${link.id}] failed: Output node [${outputNodeId}] not found.`)
const outputSlot = outputNode.outputs.at(outputIndex) const outputSlot = outputNode.outputs.at(outputIndex)
if (!outputSlot) throw new Error(`Creating DraggingRenderLink for link [${link.id}] failed: Output slot [${outputIndex}] not found.`) if (!outputSlot) throw new Error(`Creating MovingRenderLink for link [${link.id}] failed: Output slot [${outputIndex}] not found.`)
this.outputNodeId = outputNodeId this.outputNodeId = outputNodeId
this.outputNode = outputNode this.outputNode = outputNode