diff --git a/src/nub.ts b/src/nub.ts index 61e6f6360030a048d4bf67a28e8105dffdb713c3..d16e9e57ea962980f36a86d806c2bba1718655dc 100644 --- a/src/nub.ts +++ b/src/nub.ts @@ -750,15 +750,24 @@ export abstract class Nub extends ComputeNode implements IObservable { * included) directly requires (1st level only), anything (parameter or result) * from the given Nub UID "uid", its parent or any of its children * @param uid + * @param symbol symbol of the target parameter whose value change triggered this method; + * if current Nub targets this symbol, it will be considered dependent + * @param includeValuesLinks if true, even if this Nub targets only non-calculated non-modified + * parameters, it will be considered dependent @see jalhyd#98 */ - public resultDependsOnNub(uid: string, visited: string[] = []): boolean { + public resultDependsOnNub( + uid: string, + visited: string[] = [], + symbol?: string, + includeValuesLinks: boolean = false + ): boolean { if (uid !== this.uid && ! visited.includes(this.uid)) { visited.push(this.uid); // does any of our parameters depend on the target Nub ? for (const p of this._prms) { if (p.valueMode === ParamValueMode.LINK) { - if (p.dependsOnNubFamily(uid)) { + if (p.dependsOnNubFamily(uid, symbol, includeValuesLinks)) { return true; } } @@ -766,13 +775,13 @@ export abstract class Nub extends ComputeNode implements IObservable { // does any of our parent's parameters depend on the target Nub ? const parent = this.getParent(); if (parent) { - if (parent.resultDependsOnNub(uid, visited)) { + if (parent.resultDependsOnNub(uid, visited, symbol, includeValuesLinks)) { return true; } } // does any of our children' parameters depend on the target Nub ? for (const c of this.getChildren()) { - if (c.resultDependsOnNub(uid, visited)) { + if (c.resultDependsOnNub(uid, visited, symbol, includeValuesLinks)) { return true; } } diff --git a/src/param/param-definition.ts b/src/param/param-definition.ts index a021bc428904cd068f303a7ba892c42ce8facf66..3f25cc35016cbe1a49cea013d6d10f4bde170404 100644 --- a/src/param/param-definition.ts +++ b/src/param/param-definition.ts @@ -930,27 +930,27 @@ export class ParamDefinition implements INamedIterableValues, IObservable { * Returns true if the current parameter is directly linked to the * Nub having UID "uid", its parent or any of its children * @param uid + * @param symbol symbol of the target parameter whose value change triggered this method; + * if current Parameter targets this symbol, Nub will be considered dependent + * @param includeValuesLinks if true, even if this Parameter targets a non-calculated non-modified + * parameter, Nub will be considered dependent @see jalhyd#98 */ - public dependsOnNubFamily(uid: string): boolean { + public dependsOnNubFamily(uid: string, symbol?: string, includeValuesLinks: boolean = false): boolean { let linked = false; if (this._valueMode === ParamValueMode.LINK && this.isReferenceDefined()) { const ref = this._referencedValue; - // direct reference ? - if (ref.nub.uid === uid) { - linked = true; - - // parent ? - } else if (ref.nub.getParent() && ref.nub.getParent().uid === uid) { - linked = true; - - // children ? - } else if (ref.nub.getChildren().map( - (c) => { - return c.uid; - }).includes(uid)) { - linked = true; - + // direct, parent or children reference ? + if ( + (ref.nub.uid === uid) + || (ref.nub.getParent() && ref.nub.getParent().uid === uid) + || (ref.nub.getChildren().map((c) => c.uid).includes(uid)) + ) { + linked = ( + (symbol !== undefined && symbol === ref.symbol) + || ref.isCalculated() + || includeValuesLinks + ); } // else no recursion, checking level 1 only } return linked; diff --git a/src/session.ts b/src/session.ts index fdaed2ed6dc928138a2fea1f798d015bcb306eb9..a3c9427f4011dc22be9a60fc614fc54f2ca6570e 100644 --- a/src/session.ts +++ b/src/session.ts @@ -427,11 +427,15 @@ export class Session { /** * Returns all Nubs depending on the given one (parameter or result), * without following links (1st level only) + * @param symbol symbol of the parameter whose value change triggered this method; if specified, + * Nubs targetting this symbol will be considered dependent + * @param includeValuesLinks if true, even Nubs targetting non-calculated non-modified parameters + * will be considered dependent @see jalhyd#98 */ - public getDependingNubs(uid: string) { + public getDependingNubs(uid: string, symbol?: string, includeValuesLinks: boolean = false) { const dependingNubs: Nub[] = []; for (const n of this._nubs) { - if (n.uid !== uid && n.resultDependsOnNub(uid)) { + if (n.uid !== uid && n.resultDependsOnNub(uid, [], symbol, includeValuesLinks)) { dependingNubs.push(n); } }