diff --git a/DEVELOPERS.md b/DEVELOPERS.md index dc88947ee05a50ac270702f0ef0936427e9bf656..1445aaa321f27fa6222c85339e7a656a979afff6 100644 --- a/DEVELOPERS.md +++ b/DEVELOPERS.md @@ -19,7 +19,7 @@ JaLHyd offers **calculation modules** also called **Nub**s, that are each respon #### calculator type -Each Nub must have a **calculator type**, that is an item of the `CalculatorType` enum. It is stored in `this._calcType` and must be defined in the Nub's constructor. +Each Nub must have a **calculator type**, that is an item of the `CalculatorType` enum. It is stored in the `calcType` property and must be defined in the properties passed to the Nub `setProperties` method. #### calculated parameter @@ -51,7 +51,7 @@ To be calculated, a Nub might require the results of one or more other Nubs. See Parameters are objects that represent the input/outputs of a Nub's equation. All the parameters of a given Nub must be grouped in an object derived from `ParamsEquation`, (ex: `CloisonsParams` for Nub `Cloisons`). Only one parameter at a time may be the **calculated parameter** of its Nub; its value is computed based on the fixed values of other parameters. -A parameter is characterized by a **symbol** (ex: "Q"), a **definition domain** (from the `ParamDomainValue` enum, or a free interval), a **unit** (for display purposes only, ex: "m³/s"), an **initial value**, a **family** (see "Links" below), and a **visibility** (for display purposes only). +A parameter is characterized by a **symbol** (ex: "Q"), a **definition domain** (from the `ParamDomainValue` enum, or a free interval), a **unit** (for display purposes only, ex: "m³/s"), an **initial value**, a **family** (see "Links" below), its **calculability**, a **mode** and a **visibility** (for display purposes only). #### calculability @@ -103,7 +103,7 @@ Parameters are grouped into **families**, indicating that they may be linked to A **property** is an attribute of a Nub that is not numerical and/or accepts only values from a limited set. It is thus distinct from a **parameter**. Usually they are bound to enums, through `Session.enumFromProperty`. Example: "trigoOperation" in `Trigo` that only accepts items from `TrigoOperation` enum. -Properties are stored in `this.properties`. Not all Nubs have properties. Those who do should set a default value for each property in their constructor, through a call to `this.properties.setPropValue()`. +Properties are stored in `this._props_` and accessed by client code through `getPropValue`/`setPropValue` methods. Not all Nubs have properties. Those who do should set a default value for each property in their constructor, through a call to `this.setPropValue()`. Properties are **observable** objects: subscribing to a Nub's properties through `addObserver()` method guarantees to be informed of a property value change through the `update()` method of the `Observer` interface. @@ -119,9 +119,9 @@ Otherwise, when no parameter is varying there is exactly one result element, and #### result elements -A `ResultElement` is an object that contains a main calculated value `.vCalc`, optional additional calculated values stored as key-value pairs in `.values` (often referred to as "extra results"), and a calculation log concerning this calculation step only. +A `ResultElement` is an object that contains a main calculated value `vCalc`, optional additional calculated values stored as key-value pairs in `values` (often referred to as "extra results"), and a calculation log concerning this calculation step only. -A result element is `.ok` if it has a value and no error-level message. +The result element state (returned by `ok` getter) is true if it has a value and no error-level message. #### families @@ -129,13 +129,13 @@ Results families allow results to be linked to parameters of the same **family** ### Log -A **log** is a collection of `Messages` objects used to inform about events during the calculation process. +A **log** is a collection of `Message` objects used to inform about events during the calculation process. -Every result element has a log, and the `Result` object has an additional `.globalLog`. +Every result element has a log, and the `Result` object has an additional `globalLog`. #### messages -A **message** is an object containing a `MessageCode` that describes the issue, along with optional key-value pairs stored in `.extraVars`. The message severity `INFO`, `WARNING` or `ERROR` is inferred from the message code string prefix. +A **message** is an object containing a `MessageCode` that describes the issue, along with optional key-value pairs stored in `extraVars`. The message severity `INFO`, `WARNING` or `ERROR` is inferred from the message code string prefix. ### Links @@ -215,7 +215,7 @@ Note the **mandatory** call to `this.addParamDefinition()` and getter method for #### Nub class -In `addition.ts`, create and export a new class named `Addition`: +In `addition.ts`, create and export a new class named `Addition` that extends Nub class: ```typescript import { CalculatorType } from "../compute-node"; import { Nub } from "../nub"; @@ -361,6 +361,8 @@ export * from "./addition"; export * from "./addition_params"; ``` +Also add exports in `internal_modules.ts` for the new classes, as index.ts should not be used in JalHyd to avoid the "TypeError: Class extends value undefined is not a constructor or null" error (internal module pattern). + ## Further considerations for adding more complex modules ### properties @@ -371,7 +373,7 @@ If the module uses **properties**, one should add a default value in the Nub's c constructor(prms: TrigoParams, dbg: boolean = false) { … this._props.addObserver(this); - this.properties.setPropValue("trigoOperation", TrigoOperation.COS); + this.setPropValue("trigoOperation", TrigoOperation.COS); } ``` @@ -387,12 +389,12 @@ public update(sender: any, data: any) { } ``` -Update property-enum associations list in `src/app/formulaire/elements/select-field.ts` (example for operation property in Trigo module) +Update property-enum associations list in `src/props.ts` (example for operation property in Trigo module) ```typescript public static enumFromProperty = { … - "trigoOperation": TrigoOperation + trigoOperation: TrigoOperation }; ``` @@ -415,12 +417,12 @@ function setRandomTrigoOperation(sn: Trigo) { ### Nubs with children -If a module has children, the `childrenType` attribute should be set in the Nub's constructor. This attribute is used for translation in GUIs, notably ngHyd. Example from `MacroRugoCompound`: +If a module has children, the `intlType` attribute should be set in the Nub's constructor. This attribute is used for translation in GUIs, notably ngHyd. Example from `MacroRugoCompound`: ```typescript constructor(prms: MacrorugoCompoundParams, dbg: boolean = false) { … - this._childrenType = "MacroRugo"; + this._intlType = "MacroRugo"; ``` When implementing parent's `Equation()` method, children should be calculated using `Calc()` and not `Equation()` or `Solve()`, so that their logs and results are properly attached to them.