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

Improve chain computation

Showing with 33 additions and 9 deletions
+33 -9
......@@ -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;
......
......@@ -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;
......
......@@ -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
......
......@@ -99,7 +99,6 @@ export class LinkedValue {
(this.isExtraResult() || this.isResult())
&& triggerChainComputation
) {
// console.log("-----> triggering chain computation of", this.nub.uid);
this.nub.CalcSerie();
}
......
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