mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-11 02:20:08 +00:00
Optimise positionableItems / empty getters (#373)
* Optimise LGraph.empty() getter * Optimise positionableItems getters - No change to internal functionality - Replaces forced spread of all items on every property access with generator function - Consumers that require an array can very cleanly spread into one
This commit is contained in:
@@ -117,12 +117,15 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
|
||||
|
||||
/** @returns Whether the graph has no items */
|
||||
get empty(): boolean {
|
||||
return this.positionableItems.length === 0
|
||||
return this._nodes.length + this._groups.length + this.reroutes.size === 0
|
||||
}
|
||||
|
||||
/** @returns All items on the canvas that can be selected */
|
||||
get positionableItems(): Positionable[] {
|
||||
return [...this._nodes, ...this._groups, ...this.reroutes.values()]
|
||||
*positionableItems(): Generator<LGraphNode | LGraphGroup | Reroute> {
|
||||
for (const node of this._nodes) yield node
|
||||
for (const group of this._groups) yield group
|
||||
for (const reroute of this.reroutes.values()) yield reroute
|
||||
return
|
||||
}
|
||||
|
||||
#reroutes = new Map<RerouteId, Reroute>()
|
||||
|
||||
@@ -3958,8 +3958,8 @@ export class LGraphCanvas {
|
||||
return this.graph.empty
|
||||
}
|
||||
|
||||
get positionableItems(): Positionable[] {
|
||||
return this.graph.positionableItems
|
||||
get positionableItems() {
|
||||
return this.graph.positionableItems()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -8420,7 +8420,7 @@ export class LGraphCanvas {
|
||||
* If nothing is selected, the view is fitted around all items in the graph.
|
||||
*/
|
||||
fitViewToSelectionAnimated(options: AnimationOptions = {}) {
|
||||
const items: Positionable[] = this.selectedItems.size
|
||||
const items = this.selectedItems.size
|
||||
? Array.from(this.selectedItems)
|
||||
: this.positionableItems
|
||||
this.animateToBounds(createBounds(items), options)
|
||||
|
||||
Reference in New Issue
Block a user