From 89f7e89e9edba7f9022f271618e1dce954740351 Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Tue, 23 Jul 2019 17:53:53 +0200 Subject: [PATCH] #98 : smarter detection of depending Nubs --- src/nub.ts | 17 +++++++++++++---- src/param/param-definition.ts | 32 ++++++++++++++++---------------- src/session.ts | 8 ++++++-- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/nub.ts b/src/nub.ts index 61e6f636..d16e9e57 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 a021bc42..3f25cc35 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 fdaed2ed..a3c9427f 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); } } -- GitLab