diff --git a/src/nub.ts b/src/nub.ts index 6fa4cc738ae0cfc76b99b05fa4f1b52d78b7d7a0..3b8258973cce44be0a04cc5200babf7956984832 100644 --- a/src/nub.ts +++ b/src/nub.ts @@ -257,10 +257,10 @@ export abstract class Nub extends ComputeNode implements IObservable { let res: LinkedValue[] = []; const symbol = src.symbol; - // if parameter comes from the same Nub, no linking is possible at all; - // different Structures in the same parent are different Nubs so they - // can get linked to each other - if (src.nubUid !== this.uid) { + // If parameter comes from the same Nub, its parent or any of its children, + // no linking is possible at all. + // Different Structures in the same parent can get linked to each other. + if (! this.isParentOrChildOf(src.nubUid)) { // 1. parameters for (const p of this._prms) { @@ -312,6 +312,28 @@ export abstract class Nub extends ComputeNode implements IObservable { return res; } + /** + * Returns true if the given Nub UID is either of : + * - the current Nub UID + * - the current Nub's parent Nub UID + * - the UID of any of the current Nub's children + */ + public isParentOrChildOf(uid: string): boolean { + if (this.uid === uid) { + return true; + } + const parent = this.getParent(); + if (parent && parent.uid === uid) { + return true; + } + for (const c of this.getChildren()) { + if (c.uid === uid) { + return true; + } + } + return false; + } + /** * Returns true if * - this Nub