Skip to content

Commit

Permalink
instrument Solution, #92
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Jan 30, 2020
1 parent b8074de commit 2902127
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 6 deletions.
1 change: 1 addition & 0 deletions js/common/model/Dropper.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ define( require => {
// @public
this.soluteProperty = new Property( solute, {
//TODO #92 tandem
//TODO #92 phetioType: SoluteIO
} );

// @public
Expand Down
35 changes: 30 additions & 5 deletions js/common/model/Solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ define( require => {
// modules
const Color = require( 'SCENERY/util/Color' );
const DerivedProperty = require( 'AXON/DerivedProperty' );
const DerivedPropertyIO = require( 'AXON/DerivedPropertyIO' );
const merge = require( 'PHET_CORE/merge' );
const NullableIO = require( 'TANDEM/types/NullableIO' );
const NumberIO = require( 'TANDEM/types/NumberIO' );
const NumberProperty = require( 'AXON/NumberProperty' );
const PHModel = require( 'PH_SCALE/common/model/PHModel' );
const phScale = require( 'PH_SCALE/phScale' );
const PHScaleConstants = require( 'PH_SCALE/common/PHScaleConstants' );
const Tandem = require( 'TANDEM/Tandem' );
const Utils = require( 'DOT/Utils' );
const Water = require( 'PH_SCALE/common/model/Water' );

Expand All @@ -28,14 +33,27 @@ define( require => {
* @param {number} soluteVolume liters
* @param {number} waterVolume liters
* @param {number} maxVolume liters
* @param {Object} [options]
*/
constructor( soluteProperty, soluteVolume, waterVolume, maxVolume ) {
constructor( soluteProperty, soluteVolume, waterVolume, maxVolume, options ) {
assert && assert( soluteVolume + waterVolume <= maxVolume );

options = merge( {

// phet-io
tandem: Tandem.REQUIRED
}, options );

// @public
this.soluteProperty = soluteProperty;
this.soluteVolumeProperty = new NumberProperty( soluteVolume );
this.waterVolumeProperty = new NumberProperty( waterVolume );
this.soluteVolumeProperty = new NumberProperty( soluteVolume, {
tandem: options.tandem.createTandem( 'soluteVolumeProperty' ),
phetioReadOnly: true
} );
this.waterVolumeProperty = new NumberProperty( waterVolume, {
tandem: options.tandem.createTandem( 'waterVolumeProperty' ),
phetioReadOnly: true
} );
this.maxVolume = maxVolume;

/*
Expand All @@ -49,7 +67,10 @@ define( require => {

// @public volume
this.volumeProperty = new DerivedProperty( [ this.soluteVolumeProperty, this.waterVolumeProperty ],
() => ( this.ignoreVolumeUpdate ) ? this.volumeProperty.get() : this.computeVolume()
() => ( this.ignoreVolumeUpdate ) ? this.volumeProperty.get() : this.computeVolume(), {
tandem: options.tandem.createTandem( 'waterVolumeProperty' ),
phetioType: DerivedPropertyIO( NumberIO )
}
);

// @public pH, null if no value
Expand All @@ -65,9 +86,13 @@ define( require => {
}
return pH;
}
} );
}, {
tandem: options.tandem.createTandem( 'pHProperty' ),
phetioType: DerivedPropertyIO( NullableIO( NumberIO ) )
});

// @public color
//TODO #92 does this need to be instrumented?
this.colorProperty = new DerivedProperty(
[ this.soluteProperty, this.soluteVolumeProperty, this.waterVolumeProperty ],
( solute, soluteVolume, waterVolume ) => {
Expand Down
4 changes: 3 additions & 1 deletion js/macro/model/MacroModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ define( require => {
} );

// @public Solution in the beaker
this.solution = new Solution( this.dropper.soluteProperty, 0, 0, this.beaker.volume );
this.solution = new Solution( this.dropper.soluteProperty, 0, 0, this.beaker.volume, {
tandem: tandem.createTandem( 'solution' )
} );

// @public Water faucet at the beaker's top-right
this.waterFaucet = new Faucet(
Expand Down
44 changes: 44 additions & 0 deletions js/phet-io/ph-scale-phet-io-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,50 @@ window.phet.phetio.phetioTypes = assert &&
"supertype": "PropertyIO<BooleanIO>",
"typeName": "DerivedPropertyIO<BooleanIO>"
},
"DerivedPropertyIO<NullableIO<NumberIO>>": {
"documentation": "Like PropertyIO, but not settable. Instead it is derived from other DerivedPropertyIO or PropertyIO instances",
"events": [
"changed"
],
"methodOrder": [],
"methods": {
"setValue": {
"documentation": "Errors out when you try to set a derived property.",
"invocableForReadOnlyElements": false,
"parameterTypes": [
"NullableIO<NumberIO>"
],
"returnType": "VoidIO"
}
},
"parameterTypes": [
"NullableIO<NumberIO>"
],
"supertype": "PropertyIO<NullableIO<NumberIO>>",
"typeName": "DerivedPropertyIO<NullableIO<NumberIO>>"
},
"DerivedPropertyIO<NumberIO>": {
"documentation": "Like PropertyIO, but not settable. Instead it is derived from other DerivedPropertyIO or PropertyIO instances",
"events": [
"changed"
],
"methodOrder": [],
"methods": {
"setValue": {
"documentation": "Errors out when you try to set a derived property.",
"invocableForReadOnlyElements": false,
"parameterTypes": [
"NumberIO"
],
"returnType": "VoidIO"
}
},
"parameterTypes": [
"NumberIO"
],
"supertype": "PropertyIO<NumberIO>",
"typeName": "DerivedPropertyIO<NumberIO>"
},
"DialogIO": {
"documentation": "A dialog panel",
"events": [],
Expand Down

0 comments on commit 2902127

Please sign in to comment.