[API] Add LLink.resolve static / instance methods (#974)

- `LLink.resolve`: Resolves all IDs on the link to their respective
objects (node IDs, slot indexes)
- `LinkNetwork.getLink`: a more concise pattern to resolve links
This commit is contained in:
filtered
2025-04-27 06:51:41 +10:00
committed by GitHub
parent 8e8818c24d
commit b3d030e36b
3 changed files with 70 additions and 1 deletions

View File

@@ -1174,6 +1174,17 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
}
}
/**
* Finds the link with the provided ID.
* @param id ID of link to find
* @returns The link with the provided {@link id}, otherwise `undefined`. Always returns `undefined` if `id` is nullish.
*/
getLink(id: null | undefined): undefined
getLink(id: LinkId | null | undefined): LLink | undefined
getLink(id: LinkId | null | undefined): LLink | undefined {
return id == null ? undefined : this._links.get(id)
}
/**
* Returns a reroute by ID, or `undefined` if the ID is `null` or `undefined`.
* @param id ID of reroute to return