Commit 44c8c73e authored by Mathias Chouet's avatar Mathias Chouet :spaghetti:
Browse files

ResultElement : add ordered keys() getter

Showing with 18 additions and 17 deletions
+18 -17
......@@ -47,23 +47,6 @@ export class ResultElement {
* for ex. with SectionParametree
*/
get vCalc(): number {
/* if (this.parent && this.parent.symbol) {
if (this.parent.symbol in this._values) {
return this._values[this.parent.symbol];
} else {
// required symbol not found; if only the empty key "" is present,
// return its value (@WARNING clodo rustine)
if (this.count() > 1) {
// throw new Error("clodo rustine failed");
return undefined;
} else {
return this.firstValue;
}
}
}
// default retrocompatible pseudo-symbol for cases like `new ResultElement(42);`
return this._values[""]; */
return this._values[this.vCalcSymbol];
}
......@@ -99,6 +82,24 @@ export class ResultElement {
this._values = { ...this._values, ...values };
}
/**
* Returns an array of all the keys in the local values map,
* where vCalcSymbol is always in first position (used by
* GUI to iterate on displayable results)
*/
public get keys(): string[] {
const keys = Object.keys(this._values);
// make sure vCalc symbol is always first
if (this.vCalcSymbol) { // sometimes empty (ex: SectionParametree)
const index = keys.indexOf(this.vCalcSymbol);
if (index > -1) {
keys.splice(index, 1);
}
keys.unshift(this.vCalcSymbol);
}
return keys;
}
/**
* @returns the result value associated to the given symbol, or undefined if the given
* symbol was not found in the local values map
......
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