Commit a1d1490a authored by Mathias Chouet's avatar Mathias Chouet :spaghetti:
Browse files

Fix nghyd#185 forbid to link parent with child

Showing with 26 additions and 4 deletions
+26 -4
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment