From 3adf78661ece1029fa943f5a0aa889155dca4bab Mon Sep 17 00:00:00 2001 From: David Dorchies <david.dorchies@irstea.fr> Date: Tue, 19 Jun 2018 14:51:56 +0200 Subject: [PATCH] lint --- src/base.ts | 4 +- src/compute-node.ts | 25 +++--- src/cond_distri.ts | 78 +++++++++------- src/jalhyd_object.ts | 11 +-- src/lechaptcalmon.ts | 70 ++++++++------- src/session_nub.ts | 147 +++++++++++++++++-------------- src/structure/structure_props.ts | 12 +-- src/util/message.ts | 31 ++++--- src/util/observer.ts | 23 ++--- src/util/pair.ts | 10 +-- 10 files changed, 231 insertions(+), 180 deletions(-) diff --git a/src/base.ts b/src/base.ts index 7ab2bd59..068ce95c 100644 --- a/src/base.ts +++ b/src/base.ts @@ -5,9 +5,11 @@ */ export interface IDebug { - debug(s: any): void; readonly DBG: boolean; + + debug(s: any): void; + } // tslint:disable-next-line:max-classes-per-file diff --git a/src/compute-node.ts b/src/compute-node.ts index 88ff3470..96b19a75 100644 --- a/src/compute-node.ts +++ b/src/compute-node.ts @@ -1,8 +1,7 @@ import { Debug, IDebug } from "./base"; -import { ParamsEquation, IParamDefinitionIterator } from "./param/params-equation"; -import { ParamDefinition } from "./param/param-definition"; -import { ParamValueMode } from "./param/param-values"; import { JalhydObject } from "./jalhyd_object"; +import { ParamDefinition } from "./param/param-definition"; +import { IParamDefinitionIterator, ParamsEquation } from "./param/params-equation"; /** * type de calculette @@ -51,16 +50,20 @@ export abstract class ComputeNode extends JalhydObject implements IDebug { } public getParameter(name: string): ParamDefinition { - for (const p of this.parameterIterator) - if (p.symbol === name) + for (const p of this.parameterIterator) { + if (p.symbol === name) { return p; + } + } return undefined; } public getFirstAnalyticalParameter(): ParamDefinition { - for (const p of this.parameterIterator) - if (p.isAnalytical()) + for (const p of this.parameterIterator) { + if (p.isAnalytical()) { return p; + } + } return undefined; } @@ -68,15 +71,15 @@ export abstract class ComputeNode extends JalhydObject implements IDebug { return this._prms.iterator; } - protected abstract setParametersCalculability(): void; - // interface IDebug - - debug(s: any) { + public debug(s: any) { this._debug.debug(s); } public get DBG(): boolean { return this._debug.DBG; } + + protected abstract setParametersCalculability(): void; + } diff --git a/src/cond_distri.ts b/src/cond_distri.ts index f88c8229..f1ab56df 100644 --- a/src/cond_distri.ts +++ b/src/cond_distri.ts @@ -1,35 +1,37 @@ -import { Result } from "./util/result"; -import { ParamsEquation } from "./param/params-equation"; -import { ParamDefinition, ParamCalculability } from "./param/param-definition"; -import { ParamDomainValue } from "./param/param-domain"; import { Nub } from "./nub"; +import { ParamCalculability, ParamDefinition } from "./param/param-definition"; +import { ParamDomainValue } from "./param/param-domain"; +import { ParamsEquation } from "./param/params-equation"; +import { Result } from "./util/result"; /** * paramètres pour la conduite distributrice */ export class ConduiteDistribParams extends ParamsEquation { /** Débit */ - Q: ParamDefinition; + public Q: ParamDefinition; /** Diamètre */ - D: ParamDefinition; + public D: ParamDefinition; /** Perte de charge */ - J: ParamDefinition; + public J: ParamDefinition; /** Longueur de la conduite */ - Lg: ParamDefinition; + // tslint:disable-next-line:variable-name + public Lg: ParamDefinition; /** Viscosité dynamique nu */ - Nu: ParamDefinition; + // tslint:disable-next-line:variable-name + public Nu: ParamDefinition; constructor(rQ: number, rD: number, rJ: number, rLg: number, rNu: number) { super(); - this.Q = new ParamDefinition('Q', ParamDomainValue.POS, rQ); - this.D = new ParamDefinition('D', ParamDomainValue.POS, rD); - this.J = new ParamDefinition('J', ParamDomainValue.POS, rJ); - this.Lg = new ParamDefinition('Lg', ParamDomainValue.POS, rLg); - this.Nu = new ParamDefinition('Nu', ParamDomainValue.POS, rNu); + this.Q = new ParamDefinition("Q", ParamDomainValue.POS, rQ); + this.D = new ParamDefinition("D", ParamDomainValue.POS, rD); + this.J = new ParamDefinition("J", ParamDomainValue.POS, rJ); + this.Lg = new ParamDefinition("Lg", ParamDomainValue.POS, rLg); + this.Nu = new ParamDefinition("Nu", ParamDomainValue.POS, rNu); this.addParamDefinition(this.Q); this.addParamDefinition(this.D); @@ -42,27 +44,18 @@ export class ConduiteDistribParams extends ParamsEquation { /** * classe de calcul sur la conduite distributrice */ +// tslint:disable-next-line:max-classes-per-file export class ConduiteDistrib extends Nub { + constructor(prms: ConduiteDistribParams, dbg: boolean = false) { super(prms, dbg); } - /** - * paramétrage de la calculabilité des paramètres - */ - protected setParametersCalculability() { - this.prms.J.calculability = ParamCalculability.EQUATION; - this.prms.D.calculability = ParamCalculability.EQUATION; - this.prms.Q.calculability = ParamCalculability.EQUATION; - this.prms.Lg.calculability = ParamCalculability.EQUATION; - this.prms.Nu.calculability = ParamCalculability.EQUATION; - } - /** * paramètres castés au bon type */ get prms(): ConduiteDistribParams { - return <ConduiteDistribParams>this._prms; + return this._prms as ConduiteDistribParams; } /** @@ -70,36 +63,53 @@ export class ConduiteDistrib extends Nub { * @param sVarCalc nom du paramètre * @return valeur calculée */ - Equation(sVarCalc: string): Result { + public Equation(sVarCalc: string): Result { let v: number; - let K = 0.3164 * Math.pow(4, 1.75) / (5.5 * 9.81 * Math.pow(3.1415, 1.75)); // Constante de la formule + const K = 0.3164 * Math.pow(4, 1.75) / (5.5 * 9.81 * Math.pow(3.1415, 1.75)); // Constante de la formule switch (sVarCalc) { case "J": - v = K * Math.pow(this.prms.Nu.v, 0.25) * Math.pow(this.prms.Q.v, 1.75) * this.prms.Lg.v / Math.pow(this.prms.D.v, 4.75); + v = K * Math.pow(this.prms.Nu.v, 0.25) * Math.pow(this.prms.Q.v, 1.75) + * this.prms.Lg.v / Math.pow(this.prms.D.v, 4.75); break; case "D": - v = Math.pow(this.prms.J.v / (K * Math.pow(this.prms.Nu.v, 0.25) * Math.pow(this.prms.Q.v, 1.75) * this.prms.Lg.v), 1 / 4.75); + v = Math.pow(this.prms.J.v / (K * Math.pow(this.prms.Nu.v, 0.25) + * Math.pow(this.prms.Q.v, 1.75) * this.prms.Lg.v), 1 / 4.75); break; case "Q": - v = Math.pow(this.prms.J.v / (K * Math.pow(this.prms.Nu.v, 0.25) * this.prms.Lg.v / Math.pow(this.prms.D.v, 4.75)), 1 / 1.75) + v = Math.pow(this.prms.J.v / (K * Math.pow(this.prms.Nu.v, 0.25) + * this.prms.Lg.v / Math.pow(this.prms.D.v, 4.75)), 1 / 1.75); break; case "Lg": - v = this.prms.J.v / (K * Math.pow(this.prms.Nu.v, 0.25) * Math.pow(this.prms.Q.v, 1.75) / Math.pow(this.prms.D.v, 4.75)); + v = this.prms.J.v / (K * Math.pow(this.prms.Nu.v, 0.25) + * Math.pow(this.prms.Q.v, 1.75) / Math.pow(this.prms.D.v, 4.75)); break; case "Nu": - v = Math.pow(this.prms.J.v / (K * Math.pow(this.prms.Q.v, 1.75) * this.prms.Lg.v / Math.pow(this.prms.D.v, 4.75)), 1 / 0.25); + v = Math.pow(this.prms.J.v / (K * Math.pow(this.prms.Q.v, 1.75) + * this.prms.Lg.v / Math.pow(this.prms.D.v, 4.75)), 1 / 0.25); break; default: - throw 'ConduiteDistrib.Equation() : invalid parameter name ' + sVarCalc; + throw new Error("ConduiteDistrib.Equation() : invalid parameter name " + sVarCalc); } return new Result(v); } + + /** + * paramétrage de la calculabilité des paramètres + */ + protected setParametersCalculability() { + this.prms.J.calculability = ParamCalculability.EQUATION; + this.prms.D.calculability = ParamCalculability.EQUATION; + this.prms.Q.calculability = ParamCalculability.EQUATION; + this.prms.Lg.calculability = ParamCalculability.EQUATION; + this.prms.Nu.calculability = ParamCalculability.EQUATION; + } + } diff --git a/src/jalhyd_object.ts b/src/jalhyd_object.ts index 8c01127d..eb7c2c31 100644 --- a/src/jalhyd_object.ts +++ b/src/jalhyd_object.ts @@ -1,14 +1,15 @@ export abstract class JalhydObject { - /** - * id numérique unique - */ - private _uid: number; /** * générateur d'id */ private static _uidSequence: number = 0; + /** + * id numérique unique + */ + private _uid: number; + constructor() { this._uid = JalhydObject.nextUID; } @@ -18,7 +19,7 @@ export abstract class JalhydObject { } public static get nextUID(): number { - let res = this._uidSequence; + const res = this._uidSequence; this._uidSequence++; return res; } diff --git a/src/lechaptcalmon.ts b/src/lechaptcalmon.ts index d59753b3..6e2c1122 100644 --- a/src/lechaptcalmon.ts +++ b/src/lechaptcalmon.ts @@ -1,8 +1,8 @@ -import { Result } from "./util/result"; -import { ParamsEquation } from "./param/params-equation"; -import { ParamDefinition, ParamCalculability } from "./param/param-definition"; -import { ParamDomainValue } from "./param/param-domain"; import { Nub } from "./nub"; +import { ParamCalculability, ParamDefinition } from "./param/param-definition"; +import { ParamDomainValue } from "./param/param-domain"; +import { ParamsEquation } from "./param/params-equation"; +import { Result } from "./util/result"; /** * paramètres pour le calcul Lechapt et Calmon @@ -31,13 +31,13 @@ export class LechaptCalmonParams extends ParamsEquation { constructor(rQ: number, rD: number, rJ: number, rLg: number, rL: number, rM: number, rN: number) { super(); - this._Q = new ParamDefinition('Q', ParamDomainValue.POS, rQ); - this._D = new ParamDefinition('D', ParamDomainValue.POS, rD); - this._J = new ParamDefinition('J', ParamDomainValue.POS, rJ); - this._Lg = new ParamDefinition('Lg', ParamDomainValue.POS, rLg); - this._L = new ParamDefinition('L', ParamDomainValue.POS, rL); - this._M = new ParamDefinition('M', ParamDomainValue.POS, rM); - this._N = new ParamDefinition('N', ParamDomainValue.POS, rN); + this._Q = new ParamDefinition("Q", ParamDomainValue.POS, rQ); + this._D = new ParamDefinition("D", ParamDomainValue.POS, rD); + this._J = new ParamDefinition("J", ParamDomainValue.POS, rJ); + this._Lg = new ParamDefinition("Lg", ParamDomainValue.POS, rLg); + this._L = new ParamDefinition("L", ParamDomainValue.POS, rL); + this._M = new ParamDefinition("M", ParamDomainValue.POS, rM); + this._N = new ParamDefinition("N", ParamDomainValue.POS, rN); this.addParamDefinition(this._Q); this.addParamDefinition(this._D); @@ -80,55 +80,61 @@ export class LechaptCalmonParams extends ParamsEquation { /** * Calcul des pertes de charge dans un tube à partir des tables de Lechapt et Calmon */ +// tslint:disable-next-line:max-classes-per-file export class LechaptCalmon extends Nub { constructor(prms: LechaptCalmonParams, dbg: boolean = false) { super(prms, dbg); } - /** - * paramétrage de la calculabilité des paramètres - */ - protected setParametersCalculability() { - this.prms.Q.calculability = ParamCalculability.EQUATION; - this.prms.D.calculability = ParamCalculability.EQUATION; - this.prms.J.calculability = ParamCalculability.EQUATION; - this.prms.Lg.calculability = ParamCalculability.EQUATION; - this.prms.L.calculability = ParamCalculability.FREE; - this.prms.M.calculability = ParamCalculability.FREE; - this.prms.N.calculability = ParamCalculability.FREE; - } - /** * paramètres castés au bon type */ get prms(): LechaptCalmonParams { - return <LechaptCalmonParams>this._prms; + return this._prms as LechaptCalmonParams; } - Equation(sVarCalc: string): Result { + public Equation(sVarCalc: string): Result { let v: number; switch (sVarCalc) { case "Q": - v = Math.pow((((this.prms.J.v * Math.pow(this.prms.D.v, this.prms.N.v)) / this.prms.L.v) * (1000 / this.prms.Lg.v)), 1 / this.prms.M.v); + v = Math.pow((((this.prms.J.v * Math.pow(this.prms.D.v, this.prms.N.v)) / this.prms.L.v) + * (1000 / this.prms.Lg.v)), 1 / this.prms.M.v); break; case "D": - v = Math.pow((((this.prms.L.v * Math.pow(this.prms.Q.v, this.prms.M.v)) / this.prms.J.v) * (this.prms.Lg.v / 1000)), 1 / this.prms.N.v); - break + v = Math.pow((((this.prms.L.v * Math.pow(this.prms.Q.v, this.prms.M.v)) / this.prms.J.v) + * (this.prms.Lg.v / 1000)), 1 / this.prms.N.v); + break; case "J": - v = ((this.prms.L.v * Math.pow(this.prms.Q.v, this.prms.M.v)) / Math.pow(this.prms.D.v, this.prms.N.v)) * (this.prms.Lg.v / 1000); + v = ((this.prms.L.v * Math.pow(this.prms.Q.v, this.prms.M.v)) / Math.pow(this.prms.D.v, this.prms.N.v)) + * (this.prms.Lg.v / 1000); break; case "Lg": - v = ((this.prms.J.v * Math.pow(this.prms.D.v, this.prms.N.v)) / (this.prms.L.v * Math.pow(this.prms.Q.v, this.prms.M.v))) * 1000; + v = ((this.prms.J.v * Math.pow(this.prms.D.v, this.prms.N.v)) + / (this.prms.L.v * Math.pow(this.prms.Q.v, this.prms.M.v))) * 1000; break; default: - throw "LechaptCalmon.Equation() : invalid variable name " + sVarCalc; + throw new Error("LechaptCalmon.Equation() : invalid variable name " + sVarCalc); } return new Result(v); } + + /** + * paramétrage de la calculabilité des paramètres + */ + protected setParametersCalculability() { + this.prms.Q.calculability = ParamCalculability.EQUATION; + this.prms.D.calculability = ParamCalculability.EQUATION; + this.prms.J.calculability = ParamCalculability.EQUATION; + this.prms.Lg.calculability = ParamCalculability.EQUATION; + this.prms.L.calculability = ParamCalculability.FREE; + this.prms.M.calculability = ParamCalculability.FREE; + this.prms.N.calculability = ParamCalculability.FREE; + } + } diff --git a/src/session_nub.ts b/src/session_nub.ts index 781bd7ec..a8ce1687 100644 --- a/src/session_nub.ts +++ b/src/session_nub.ts @@ -1,5 +1,5 @@ import { Nub } from "./nub"; -import { IObservable, Observer, Observable } from "./util/observer"; +import { IObservable, IObserver, Observable } from "./util/observer"; /** * gestion d'un ensemble de propriétés (clé/valeur) @@ -19,9 +19,11 @@ export class Props implements IObservable { // if (keys.length != Object.keys(p).length) // return false; - for (const k of keys) - if (this._props[k] !== p[k]) + for (const k of keys) { + if (this._props[k] !== p[k]) { return false; + } + } return true; } @@ -30,30 +32,6 @@ export class Props implements IObservable { return this._props[key]; } - /** - * notification de changement de la valeur d'une propriété - * @param prop nom de la propriété modifiée - * @param val nouvelle valeur - * @param sender objet ayant changé la valeur - */ - private notifyPropChange(prop: string, val: any, sender: any) { - this.notifyObservers({ - "action": "propertyChange", - "name": prop, - "value": val - }, sender); - } - - /** - * notification de changement de la valeur de toutes les propriétés - * @param sender objet ayant changé les valeurs - */ - private notifyPropsChange(sender: any) { - this.notifyObservers({ - "action": "propertiesChange", - }, sender); - } - public setPropValue(key: string, val: any, sender?: any): boolean { const oldValue = this._props[key]; const changed = oldValue !== val; @@ -64,47 +42,26 @@ export class Props implements IObservable { return changed; } - /** - * compare 2 objets (clés et valeurs) - * @return true s'il existe une différence - */ - private compareObjects(o1: { [key: string]: any }, o2: { [key: string]: any }) { - const oldKeys: string[] = Object.keys(o1).sort(); - const newKeys: string[] = Object.keys(o2).sort(); - - // nombre de clés - let changed = oldKeys.length !== newKeys.length; - if (changed) - return true; - - // nom des clés - for (const i in oldKeys) - if (oldKeys[i] !== newKeys[i]) - return true; - - // valeurs - for (const i in o1) - if (o1[i] != o2[i]) - return true; - - return false; - } - /** * fixe la valeur de toutes les propriétés * @param props nouvelles valeurs * @param sender objet modificateur */ public setProps(props: {}, sender?: any) { - if (props instanceof Props) - var p = props._props; - else + let p; + if (props instanceof Props) { + p = props._props; + } else { p = props; + } const changed = this.compareObjects(this._props, p); if (changed) { this._props = {}; - for (const k in p) - this._props[k] = p[k]; + for (const k in p) { + if (p.hasOwnProperty(k)) { + this._props[k] = p[k]; + } + } this.notifyPropsChange(sender); } @@ -116,16 +73,18 @@ export class Props implements IObservable { public clone(): Props { const res = new Props(); - for (const k in this._props) + for (const k in this._props) { res._props[k] = this._props[k]; + } return res; } public toString(): string { let res = "["; for (const k in this._props) { - if (res != "[") + if (res !== "[") { res += ", "; + } res += `${k}:${this._props[k]}`; } res += "]" @@ -137,14 +96,14 @@ export class Props implements IObservable { /** * ajoute un observateur à la liste */ - public addObserver(o: Observer) { + public addObserver(o: IObserver) { this._observable.addObserver(o); } /** * supprime un observateur de la liste */ - public removeObserver(o: Observer) { + public removeObserver(o: IObserver) { this._observable.removeObserver(o); } @@ -154,6 +113,62 @@ export class Props implements IObservable { public notifyObservers(data: any, sender?: any) { this._observable.notifyObservers(data, sender); } + + /** + * notification de changement de la valeur de toutes les propriétés + * @param sender objet ayant changé les valeurs + */ + private notifyPropsChange(sender: any) { + this.notifyObservers({ + action: "propertiesChange", + }, sender); + } + + /** + * notification de changement de la valeur d'une propriété + * @param prop nom de la propriété modifiée + * @param val nouvelle valeur + * @param sender objet ayant changé la valeur + */ + private notifyPropChange(prop: string, val: any, sender: any) { + this.notifyObservers({ + action: "propertyChange", + name: prop, + value: val + }, sender); + } + + /** + * compare 2 objets (clés et valeurs) + * @return true s'il existe une différence + */ + private compareObjects(o1: { [key: string]: any }, o2: { [key: string]: any }) { + const oldKeys: string[] = Object.keys(o1).sort(); + const newKeys: string[] = Object.keys(o2).sort(); + + // nombre de clés + const changed = oldKeys.length !== newKeys.length; + if (changed) { + return true; + } + + // nom des clés + for (const i in oldKeys) { + if (oldKeys[i] !== newKeys[i]) { + return true; + } + } + + // valeurs + for (const i in o1) { + if (o1[i] !== o2[i]) { + return true; + } + } + + return false; + } + } /** @@ -163,13 +178,15 @@ export class SessionNub { private _props: Props; constructor(private _nub: Nub, props: Props | {}) { - if (this._nub == undefined) + if (this._nub === undefined) { throw new Error(`NgNub.constructor() : argument invalide`); + } - if (props instanceof Props) + if (props instanceof Props) { this._props = props.clone(); - else + } else { this._props = new Props(props); + } } public get nub() { diff --git a/src/structure/structure_props.ts b/src/structure/structure_props.ts index aa0b73f1..114be3ac 100644 --- a/src/structure/structure_props.ts +++ b/src/structure/structure_props.ts @@ -50,10 +50,12 @@ export class StructureProperties { */ public static findCompatibleStructure(loi: LoiDebit): StructureType { for (const st in loiAdmissibles) { - const lds: LoiDebit[] = loiAdmissibles[st]; - for (const ld of lds) - if (ld === loi) - return (<any>StructureType)[st]; + if (loiAdmissibles.hasOwnProperty(st)) { + const lds: LoiDebit[] = loiAdmissibles[st]; + for (const ld of lds) { + if (ld === loi) { return (StructureType as any)[st]; } + } + } } return undefined; } @@ -65,4 +67,4 @@ export class StructureProperties { const sst: string = StructureType[struct]; return loiAdmissibles[sst][0]; } -} \ No newline at end of file +} diff --git a/src/util/message.ts b/src/util/message.ts index f30b1fa0..5224ca5a 100644 --- a/src/util/message.ts +++ b/src/util/message.ts @@ -114,7 +114,8 @@ export enum MessageCode { INFO_REMOUS_CALCUL_FLUVIAL, /** - * courbe de remous : Condition limite amont <= Hauteur critique : calcul de la partie torrentielle à partir de l'amont + * courbe de remous : Condition limite amont <= Hauteur critique : + * calcul de la partie torrentielle à partir de l'amont */ INFO_REMOUS_CALCUL_TORRENTIEL, @@ -174,12 +175,14 @@ export enum MessageCode { ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCONJUG, /** - * section : Non convergence du calcul de la hauteur correspondante (Méthode de Newton) pour le calcul de la hauteur fluviale + * section : Non convergence du calcul de la hauteur correspondante (Méthode de Newton) + * pour le calcul de la hauteur fluviale */ ERROR_SECTION_NON_CONVERGENCE_NEWTON_HFLU, /** - * section : Non convergence du calcul de la hauteur correspondante (Méthode de Newton) pour le calcul de la hauteur torrentielle + * section : Non convergence du calcul de la hauteur correspondante (Méthode de Newton) + * pour le calcul de la hauteur torrentielle */ ERROR_SECTION_NON_CONVERGENCE_NEWTON_HTOR, @@ -240,17 +243,18 @@ export enum MessageSeverity { * Résultat de calcul comprenant la valeur du résultat et des calculs annexes (flag, calculs intermédiaires...) */ export class Message { + + /** Variables intermédiaires, flags d'erreur */ + public extraVar: { [key: string]: any }; + /** * code du message */ private _code: MessageCode; - /** Variables intermédiaires, flags d'erreur */ - public extraVar: { [key: string]: any }; - constructor(c: MessageCode) { this._code = c; - this.extraVar = {} + this.extraVar = {}; } get code() { return this._code; } @@ -259,12 +263,15 @@ export class Message { * retourne le niveau de criticité (erreur, warning, info) du message */ public getSeverity(): MessageSeverity { - let m: string = MessageCode[this._code]; - let prefix: string = m.split("_")[0]; - for (let s in MessageSeverity) // pas nécessaire, mais permet d'avoir un contrôle de validité - if (MessageSeverity[s] == prefix) + const m: string = MessageCode[this._code]; + const prefix: string = m.split("_")[0]; + for (const s in MessageSeverity) { // pas nécessaire, mais permet d'avoir un contrôle de validité + if (MessageSeverity[s] === prefix) { + // tslint:disable-next-line:no-eval return eval("MessageSeverity." + prefix); - throw "Message.getSeverity() : valeur de code '" + this._code + "' invalide"; + } + } + throw new Error("Message.getSeverity() : valeur de code '" + this._code + "' invalide"); } public toString(): string { diff --git a/src/util/observer.ts b/src/util/observer.ts index 6a17beb9..fb9b0237 100644 --- a/src/util/observer.ts +++ b/src/util/observer.ts @@ -1,4 +1,4 @@ -export interface Observer { +export interface IObserver { update(sender: any, data: any): void; } @@ -6,12 +6,12 @@ export interface IObservable { /** * ajoute un observateur à la liste */ - addObserver(o: Observer): void; + addObserver(o: IObserver): void; /** * supprime un observateur de la liste */ - removeObserver(o: Observer): void; + removeObserver(o: IObserver): void; /** * notifie un événement aux observateurs @@ -20,7 +20,7 @@ export interface IObservable { } export class Observable implements IObservable { - private _observers: Observer[]; + private _observers: IObserver[]; constructor() { this._observers = []; @@ -29,25 +29,28 @@ export class Observable implements IObservable { /** * ajoute un observateur à la liste */ - public addObserver(o: Observer) { - if (this._observers.indexOf(o) == -1) + public addObserver(o: IObserver) { + if (this._observers.indexOf(o) === -1) { this._observers.push(o); + } } /** * supprime un observateur de la liste */ - public removeObserver(o: Observer) { - this._observers = this._observers.filter(a => a !== o); + public removeObserver(o: IObserver) { + this._observers = this._observers.filter((a) => a !== o); } /** * notifie un événement aux observateurs */ public notifyObservers(data: any, sender?: any) { - if (sender == undefined) + if (sender === undefined) { sender = this; - for (let o of this._observers) + } + for (const o of this._observers) { o.update(sender, data); + } } } diff --git a/src/util/pair.ts b/src/util/pair.ts index ab9c56b1..1ea1b6b3 100644 --- a/src/util/pair.ts +++ b/src/util/pair.ts @@ -17,16 +17,16 @@ export class Pair { return this._val2; } - setValues(v1: number, v2: number) { + public setValues(v1: number, v2: number) { this._val1 = v1; this._val2 = v2; } - setPair(p: Pair) { + public setPair(p: Pair) { this.setValues(p._val1, p._val2); } - undefine() { + public undefine() { this._val1 = undefined; this._val2 = undefined; } @@ -39,11 +39,11 @@ export class Pair { return Math.max(this._val1, this._val2); } - intervalHasValue(v: number) { + public intervalHasValue(v: number) { return this.min <= v && v <= this.max; } - toString(): string { + public toString(): string { return "[" + this.min + "," + this.max + "]"; } } -- GitLab