Commit 20914ef4 authored by Mathias Chouet's avatar Mathias Chouet :spaghetti:
Browse files

Notify observers when completely replacng props

Showing with 36 additions and 18 deletions
+36 -18
......@@ -17,6 +17,22 @@ import { ResultElement } from "./util/resultelement";
*/
export abstract class Nub extends ComputeNode implements IObservable {
protected static concatPrms(p1: ParamsEquation[], p2: ParamsEquation[]): ParamsEquation[] {
const p3: ParamsEquation[] = p1;
for (const p of p2) {
p3.push(p);
}
return p3;
}
private static progressPercentageAccordedToChainCalculation = 50;
/** paramétrage de la dichotomie */
public dichoStartIntervalMaxSteps: number = 100;
/** pointer to parent Nub */
public parent: Nub;
/** type of children elements, used by GUI for translation */
protected _childrenType: string = "";
......@@ -51,10 +67,16 @@ export abstract class Nub extends ComputeNode implements IObservable {
public set properties(props: Props) {
// copy observers
const observers = this._props.getObservers();
this._props = props.clone();
// empty props
this._props.reset();
// restore observers
for (const obs of observers) {
this._props.addObserver(obs);
}
// set new props values
for (const p of Object.keys(props.props)) {
this._props.setPropValue(p, props.getPropValue(p));
}
}
/**
......@@ -159,22 +181,6 @@ export abstract class Nub extends ComputeNode implements IObservable {
}
}
protected static concatPrms(p1: ParamsEquation[], p2: ParamsEquation[]): ParamsEquation[] {
const p3: ParamsEquation[] = p1;
for (const p of p2) {
p3.push(p);
}
return p3;
}
private static progressPercentageAccordedToChainCalculation = 50;
/** paramétrage de la dichotomie */
public dichoStartIntervalMaxSteps: number = 100;
/** pointer to parent Nub */
public parent: Nub;
/** parameter that is to be computed by default - to be overloaded by child classes */
protected _defaultCalculatedParam: ParamDefinition;
......@@ -207,7 +213,7 @@ export abstract class Nub extends ComputeNode implements IObservable {
public constructor(prms: ParamsEquation, dbg: boolean = false) {
super(prms, dbg);
this._children = [];
this.deleteAllChildren();
this._observable = new Observable();
this._defaultCalculatedParam = this.getFirstAnalyticalParameter();
this.resetDefaultCalculatedParam();
......@@ -1166,6 +1172,11 @@ export abstract class Nub extends ComputeNode implements IObservable {
}
}
/** Removes all children */
public deleteAllChildren() {
this._children = [];
}
/**
* Returns the position or the current structure (starting at 0)
* in the parent Nub
......
......@@ -59,6 +59,13 @@ export class Props implements IObservable {
return this._observable.getObservers();
}
/**
* Remove all properties, does not notify of any change
*/
public reset() {
this._props = {};
}
/**
* Clones properties into a new Props object
*/
......
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