diff --git a/src/index.ts b/src/index.ts index 67bf8be63d14f736f14cafe00f5b81fe70bdb152..403096993d54d6829bcf371bddf48cfbef4a5b56 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,6 +30,6 @@ export * from "./structure/structure"; export * from "./structure/structure_params"; export * from "./structure/factory_structure"; export * from "./structure/structure_props"; -export * from "./value_ref/object_ref"; +export * from "./linked-value"; export * from "./jalhyd_object"; export * from "./date_revision"; diff --git a/src/value_ref/object_ref.ts b/src/linked-value.ts similarity index 80% rename from src/value_ref/object_ref.ts rename to src/linked-value.ts index c8c1ed26341c708d0d49353a2c3b0af44879d0e2..b98069ff0f8077fad850f35a03491e439527ec4f 100644 --- a/src/value_ref/object_ref.ts +++ b/src/linked-value.ts @@ -1,9 +1,9 @@ -import { Nub } from "../nub"; -import { ParamDefinition } from "../param/param-definition"; -import { INamedIterableValues } from "../param/param-value-iterator"; -import { ParamValueMode } from "../param/param-value-mode"; -import { ParamValues } from "../param/param-values"; -import { Message, MessageCode } from "../util/message"; +import { Nub } from "./nub"; +import { ParamDefinition } from "./param/param-definition"; +import { INamedIterableValues } from "./param/param-value-iterator"; +import { ParamValueMode } from "./param/param-value-mode"; +import { ParamValues } from "./param/param-values"; +import { Message, MessageCode } from "./util/message"; export class LinkedValue { /** linked value metadata (ex: calculator title for GUI) */ @@ -18,6 +18,9 @@ export class LinkedValue { /** parameter / result symbol (ex: "Q") */ private _symbol: string; + /** magic param values: proxy to target when target is a not a result, handcrafted fake object otherwise */ + private _paramValues: ParamValues; + constructor(nub: Nub, element: INamedIterableValues, symbol: string, meta: any = {}) { this._nub = nub; this._element = element; @@ -109,14 +112,21 @@ export class LinkedValue { if (targetParam.valueMode === ParamValueMode.CALCUL) { // if already computed, expose handmade fake param values for iterability if (this.nub.result) { - ret = new ParamValues(); + if (! this._paramValues) { + this._paramValues = new ParamValues(); + } if (targetParam.hasMultipleValues) { const multipleRes = this.nub.result.getCalculatedValues(); - ret.setValues(multipleRes); + this._paramValues.setValues(multipleRes); + if (this._paramValues.currentValue === undefined) { + this._paramValues.currentValue = multipleRes[0]; // or else isDefined() will return false + } } else { const singleRes = this.nub.result.vCalc; - ret.setSingleValue(singleRes); + this._paramValues.setSingleValue(singleRes); } + // return local cache + ret = this._paramValues; } else { // else simple parameter proxy (see below) ret = targetParam.paramValues; @@ -133,21 +143,29 @@ export class LinkedValue { // is result available ? if (this.nub.result) { // expose handmade fake param values for iterability - ret = new ParamValues(); + if (! this._paramValues) { + this._paramValues = new ParamValues(); + } if (this.nub.resultHasMultipleValues()) { const multipleExtraRes = this.nub.result.getExtraResults(this.symbol); - ret.setValues(multipleExtraRes); + this._paramValues.setValues(multipleExtraRes); + if (this._paramValues.currentValue === undefined) { + this._paramValues.currentValue = multipleExtraRes[0]; // or else isDefined() will return false + } } else { const singleExtraRes = this.nub.result.getExtraResult(this.symbol); - ret.setSingleValue(singleExtraRes); + this._paramValues.setSingleValue(singleExtraRes); } + // return local cache + ret = this._paramValues; } else { throw new Error("LinkedValue.getParamValues() - result not available"); } } else { throw new Error("LinkedValue.getParamValues() - cannot determine nature of target"); } + return ret; } diff --git a/src/nub.ts b/src/nub.ts index 9fcc23e3587d9b729443a188de64adbae9c27850..f5712beb13a4c34628810de1255aa28af316ed36 100644 --- a/src/nub.ts +++ b/src/nub.ts @@ -1,12 +1,12 @@ import { ParamDefinition, ParamsEquation, Session, Structure } from "."; import { ComputeNode } from "./compute-node"; import { Dichotomie } from "./dichotomie"; +import { LinkedValue } from "./linked-value"; import { ParamValueMode } from "./param/param-value-mode"; import { ParamValues } from "./param/param-values"; import { Props } from "./props"; import { IObservable, Observable, Observer } from "./util/observer"; import { Result } from "./util/result"; -import { LinkedValue } from "./value_ref/object_ref"; /** * Classe abstraite de Noeud de calcul dans une session : diff --git a/src/param/param-definition.ts b/src/param/param-definition.ts index 63c87b85f8c62ef150cf60d0f3e843100755d884..e14b8e4d58432c20c09b9fe39a792f3c7996c9a9 100644 --- a/src/param/param-definition.ts +++ b/src/param/param-definition.ts @@ -1,9 +1,9 @@ import { CalculatorType, ComputeNode } from "../compute-node"; +import { LinkedValue } from "../linked-value"; import { Nub } from "../nub"; import { Interval } from "../util/interval"; import { Message, MessageCode } from "../util/message"; import { IObservable, Observable, Observer } from "../util/observer"; -import { LinkedValue } from "../value_ref/object_ref"; import { ParamDomain, ParamDomainValue } from "./param-domain"; import { INamedIterableValues, INumberIterator } from "./param-value-iterator"; import { ParamValueMode } from "./param-value-mode"; diff --git a/src/session.ts b/src/session.ts index 3f041dc294506844af698de40916927033a1915c..6f78e25ce2a8bb5a93cc7e3dd90cef33ca20f176 100644 --- a/src/session.ts +++ b/src/session.ts @@ -23,11 +23,11 @@ import { cSnTrapez, ParamsSectionTrapez } from "./section/section_trapez"; import { acSection } from "./section/section_type"; // Classes relatives aux structures +import { LinkedValue } from "./linked-value"; import { ParamDefinition } from "./param/param-definition"; import { CreateStructure } from "./structure/factory_structure"; import { Structure } from "./structure/structure"; import { LoiDebit, StructureType } from "./structure/structure_props"; -import { LinkedValue } from "./value_ref/object_ref"; export class Session {