diff --git a/src/nub.ts b/src/nub.ts index 5c5449f107fc18a4172c7507e62e0208d6b81cc2..e618ebfa8822746cef0e748331441965dbe2414c 100644 --- a/src/nub.ts +++ b/src/nub.ts @@ -112,6 +112,12 @@ export abstract class Nub extends ComputeNode implements IObservable { // instance de ParamValues utilisée pour le paramètre varié (qui peut être un paramètre référencé (importé)) let variatedValues: IterableValues; + // chain computation + const requiredNubs1stLevel = Session.getInstance().getRequiredNubs(this); + for (const rn of requiredNubs1stLevel) { + rn.CalcSerie(); + } + for (const p of this.parameterIterator) { if (p.valueMode === ParamValueMode.CALCUL) { if (sDonnee === undefined) { @@ -317,8 +323,10 @@ export abstract class Nub extends ComputeNode implements IObservable { * - the result of the given Nub's parent * * (ie. "my family depends on the result of your family") + * + * If followLinksChain is false, will limit the exploration to the first target level only */ - public dependsOnNubResult(uid: string): boolean { + public dependsOnNubResult(uid: string, followLinksChain: boolean = true): boolean { let thisFamily: Nub[] = [this]; const tp = this.getParent(); if (tp) { @@ -344,7 +352,7 @@ export abstract class Nub extends ComputeNode implements IObservable { // look for a parameter linked to the result of any Nub of yourFamily for (const p of t.prms) { if (p.valueMode === ParamValueMode.LINK) { - if (p.isLinkedToResultOfNubs(yourFamily)) { + if (p.isLinkedToResultOfNubs(yourFamily, followLinksChain)) { // dependence found ! depends = true; break outerloop; diff --git a/src/param/param-definition.ts b/src/param/param-definition.ts index 064681c1046fc8c46bdd2d3e972224200e7ede74..b9e7554b3cb30cf831941c26d3f7113228af6d3b 100644 --- a/src/param/param-definition.ts +++ b/src/param/param-definition.ts @@ -203,10 +203,10 @@ export class ParamDefinition implements INamedIterableValues, IObservable { } /** - * Proxy to getValue(); alwais triggers chain computation + * Proxy to getValue(); never triggers chain computation */ get v(): number { - return this.getValue(true); + return this.getValue(); } /** @@ -583,9 +583,10 @@ export class ParamDefinition implements INamedIterableValues, IObservable { /** * Returns true if this parameter is ultimately (after followink links chain) linked - * to a result or extra result of any of the given nubs + * to a result or extra result of any of the given nubs. + * If followLinksChain is false, will limit theexploration to the first target level only */ - public isLinkedToResultOfNubs(nubs: Nub[]): boolean { + public isLinkedToResultOfNubs(nubs: Nub[], followLinksChain: boolean = true): boolean { let linked = false; if (this.valueMode === ParamValueMode.LINK && this.isReferenceDefined()) { const targetNubUid = this.referencedValue.nub.uid; @@ -600,8 +601,10 @@ export class ParamDefinition implements INamedIterableValues, IObservable { } } } else { // target is a parameter - // recursion - linked = (this.referencedValue.element as ParamDefinition).isLinkedToResultOfNubs(nubs); + // recursion ? + if (followLinksChain) { + linked = (this.referencedValue.element as ParamDefinition).isLinkedToResultOfNubs(nubs); + } } } return linked; diff --git a/src/session.ts b/src/session.ts index 4a93e4ccb1e2ed4070a3f1457200922b34acca5f..3f041dc294506844af698de40916927033a1915c 100644 --- a/src/session.ts +++ b/src/session.ts @@ -391,6 +391,20 @@ export class Session { return dependingNubs; } + /** + * Returns all Nubs whose results are required by the given one, + * without following links (1st level only) + */ + public getRequiredNubs(nub: Nub) { + const requiredNubs: Nub[] = []; + for (const n of this._nubs) { + if (n.uid !== nub.uid && nub.dependsOnNubResult(n.uid, false)) { + requiredNubs.push(n); + } + } + return requiredNubs; + } + /** * Returns a list of nub/symbol couples, that can be linked to the given * parameter, amoung all current nubs diff --git a/src/value_ref/object_ref.ts b/src/value_ref/object_ref.ts index a0dd25270cedbb5ebede7ee1a7b06945e3cc5fd9..bb833fc8f74e425603b00221c657aaa9953d5542 100644 --- a/src/value_ref/object_ref.ts +++ b/src/value_ref/object_ref.ts @@ -99,7 +99,6 @@ export class LinkedValue { (this.isExtraResult() || this.isResult()) && triggerChainComputation ) { - // console.log("-----> triggering chain computation of", this.nub.uid); this.nub.CalcSerie(); }