[API] Add reroute convenience methods (#812)

Adds `LGraph.getReroute`, which accepts null & undefined IDs. Interface
overloads result in `never` when given a _known_ `undefined` or `null`
value.
This commit is contained in:
filtered
2025-03-22 05:58:07 +11:00
committed by GitHub
parent cdbc0fa5e5
commit a043e7a72e
3 changed files with 18 additions and 0 deletions

View File

@@ -1398,6 +1398,17 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
}
}
/**
* Returns a reroute by ID, or `undefined` if the ID is `null` or `undefined`.
* @param id ID of reroute to return
* @returns The reroute with the provided {@link id}, otherwise `undefined`. Always returns `undefined` if `id` is `null` or `undefined`.
*/
getReroute(id: null | undefined): undefined
getReroute(id: RerouteId | null | undefined): Reroute | undefined
getReroute(id: RerouteId | null | undefined): Reroute | undefined {
return id == null ? undefined : this.reroutes.get(id)
}
/**
* Configures a reroute on the graph where ID is already known (probably deserialisation).
* Creates the object if it does not exist.