Skip to content

Commit

Permalink
Converting DerivedProperty/Multilink to properly parameterized TypeSc…
Browse files Browse the repository at this point in the history
…ript, and usage of IReadOnlyProperty. See phetsims/axon#371
  • Loading branch information
jonathanolson committed Dec 8, 2021
1 parent 15c3a18 commit 7c97ef8
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 11 deletions.
3 changes: 2 additions & 1 deletion js/common/model/ConcentrationModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import NumberIO from '../../../../tandem/js/types/NumberIO.js';
import greenhouseEffect from '../../greenhouseEffect.js';
import LayersModel, { LayersModelOptions } from './LayersModel.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import IReadOnlyProperty from '../../../../axon/js/IReadOnlyProperty.js';

// constants
const SCALE_HEIGHT_OF_ATMOSPHERE: number = 8400; // in meters, taken from a Wikipedia article
Expand Down Expand Up @@ -48,7 +49,7 @@ class ConcentrationModel extends LayersModel {
public readonly dateProperty: EnumerationProperty;
public readonly manuallyControlledConcentrationProperty: NumberProperty;
public readonly concentrationControlModeProperty: EnumerationProperty;
public readonly concentrationProperty: DerivedProperty<number>;
public readonly concentrationProperty: IReadOnlyProperty<number>;

/**
* @param {Tandem} tandem
Expand Down
3 changes: 2 additions & 1 deletion js/common/model/FluxMeter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Vector2 from '../../../../dot/js/Vector2.js';
import Vector2Property from '../../../../dot/js/Vector2Property.js';
import greenhouseEffect from '../../greenhouseEffect.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import IReadOnlyProperty from '../../../../axon/js/IReadOnlyProperty.js';

class FluxMeter {
readonly sunlightInProperty: NumberProperty;
Expand All @@ -23,7 +24,7 @@ class FluxMeter {
readonly sensorBounds: Bounds2;
readonly sensorPositionProperty: Vector2Property;
readonly wireMeterAttachmentPositionProperty: Vector2Property;
readonly wireSensorAttachmentPositionProperty: DerivedProperty<Vector2>;
readonly wireSensorAttachmentPositionProperty: IReadOnlyProperty<Vector2>;

/**
* @param {Tandem} tandem
Expand Down
5 changes: 3 additions & 2 deletions js/common/model/LayersModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import Cloud from './Cloud.js';
import merge from '../../../../phet-core/js/merge.js';
import FluxMeter from './FluxMeter.js';
import { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js';
import IReadOnlyProperty from '../../../../axon/js/IReadOnlyProperty.js';

// constants
const HEIGHT_OF_ATMOSPHERE = 50000; // in meters
Expand All @@ -50,8 +51,8 @@ type LayersModelOptions = {
class LayersModel extends GreenhouseEffectModel {

readonly surfaceTemperatureKelvinProperty: NumberProperty;
readonly surfaceTemperatureCelsiusProperty: DerivedProperty<number>;
readonly surfaceTemperatureFahrenheitProperty: DerivedProperty<number>;
readonly surfaceTemperatureCelsiusProperty: IReadOnlyProperty<number>;
readonly surfaceTemperatureFahrenheitProperty: IReadOnlyProperty<number>;
readonly temperatureUnitsProperty: EnumerationProperty;
readonly surfaceThermometerVisibleProperty: BooleanProperty;
readonly energyBalanceVisibleProperty: BooleanProperty;
Expand Down
3 changes: 2 additions & 1 deletion js/common/view/ConcentrationControlPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import ConcentrationModel from '../model/ConcentrationModel.js';
import ConcentrationDescriber from './describers/ConcentrationDescriber.js';
import EnumerationProperty from '../../../../axon/js/EnumerationProperty.js';
import RadiationDescriber from './describers/RadiationDescriber.js';
import IReadOnlyProperty from '../../../../axon/js/IReadOnlyProperty.js';

// constants
const lotsString = greenhouseEffectStrings.concentrationPanel.lots;
Expand Down Expand Up @@ -190,7 +191,7 @@ class DateControl extends Node {
* @param {Tandem} tandem
*/
constructor( dateProperty: EnumerationProperty,
concentrationProperty: Property<number>,
concentrationProperty: IReadOnlyProperty<number>,
concentrationControlModeProperty: EnumerationProperty,
tandem: Tandem ) {

Expand Down
9 changes: 5 additions & 4 deletions js/common/view/EnergyBalancePanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import IReadOnlyProperty from '../../../../axon/js/IReadOnlyProperty.js';
import Property from '../../../../axon/js/Property.js';
import AxisLine from '../../../../bamboo/js/AxisLine.js';
import ChartRectangle from '../../../../bamboo/js/ChartRectangle.js';
Expand Down Expand Up @@ -67,12 +68,12 @@ class EnergyBalancePanel extends Panel {

// Energy "In" needs to be plotted in the negative y direction to match other graphics related to energy flux
// in this sim
const negatedEnergyInProperty: DerivedProperty<number> = new DerivedProperty(
const negatedEnergyInProperty: IReadOnlyProperty<number> = new DerivedProperty(
[ netEnergyInProperty ],
( netEnergyIn: number ) => -netEnergyIn
);

const netEnergyProperty: DerivedProperty<number> = new DerivedProperty(
const netEnergyProperty: IReadOnlyProperty<number> = new DerivedProperty(
[ negatedEnergyInProperty, netEnergyOutProperty ],
( netIn: number, netOut: number ) => netIn + netOut
);
Expand Down Expand Up @@ -104,9 +105,9 @@ class EnergyBalancePlot extends Node {
* @param {Property.<number>} netEnergyOutProperty - Representing net energy out, read-only
* @param {Property.<number>} netEnergyProperty - Representing net energy of the system, read-only
*/
constructor( netEnergyInProperty: Property<number>,
constructor( netEnergyInProperty: IReadOnlyProperty<number>,
netEnergyOutProperty: Property<number>,
netEnergyProperty: Property<number> ) {
netEnergyProperty: IReadOnlyProperty<number> ) {
super();

// position of each bar, in model coordinates
Expand Down
2 changes: 1 addition & 1 deletion js/common/view/TemperatureSoundGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class TemperatureSoundGenerator extends SoundGenerator {
// relying on the base class to monitor them so that the loops can be turned off if they don't need to be playing.
// This saves processor bandwidth on the audio rendering thread, since the parent class turns down the volume but
// doesn't stop the loops.
Property.multilink(
Property.multilink<any[]>(
[ temperatureProperty, ...options.enableControlProperties as Property<boolean>[] ],
() => { this.updateLoopStates(); }
);
Expand Down
3 changes: 2 additions & 1 deletion js/common/view/ThermometerAndReadout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import GreenhouseEffectUtils from '../GreenhouseEffectUtils.js';
import LayersModel from '../model/LayersModel.js';
import Property from '../../../../axon/js/Property.js';
import Enumeration from '../../../../phet-core/js/Enumeration.js';
import IReadOnlyProperty from '../../../../axon/js/IReadOnlyProperty.js';

// constants
const THERMOMETER_TO_READOUT_DISTANCE = 15; // in screen coordinates
Expand Down Expand Up @@ -173,7 +174,7 @@ class ThermometerAndReadout extends Node {
* @returns {ComboBoxItem}
*/
private static createComboBoxItem( unitsString: string,
property: Property<number>,
property: IReadOnlyProperty<number>,
propertyRange: Range,
propertyValue: Enumeration,
tandemName: string ) {
Expand Down

0 comments on commit 7c97ef8

Please sign in to comment.