Skip to content

Commit

Permalink
Converted to use PhetioObject, see phetsims/tandem#46
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Dec 15, 2017
1 parent 236dcd4 commit f018fc1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
46 changes: 28 additions & 18 deletions js/molarity/model/MolarityModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,34 @@ define( function( require ) {

// @public
this.solutes = [
new Solute( drinkMixString, MSymbols.DRINK_MIX, 5.95, new Color( 255, 225, 225 ), Color.RED,
tandem.createTandem( 'drinkMix' ) ),
new Solute( cobaltIINitrateString, MSymbols.COBALT_II_NITRATE, 5.65, new Color( 255, 225, 225 ), Color.RED,
tandem.createTandem( 'cobaltIINitrate' ) ),
new Solute( cobaltChlorideString, MSymbols.COBALT_CHLORIDE, 4.35, new Color( 255, 242, 242 ), new Color( 255, 106, 106 ),
tandem.createTandem( 'cobaltChloride' ) ),
new Solute( potassiumDichromateString, MSymbols.POTASSIUM_DICHROMATE, 0.50, new Color( 255, 232, 210 ), new Color( 255, 127, 0 ),
tandem.createTandem( 'potassiumDichromate' ) ),
new Solute( goldIIIChlorideString, MSymbols.GOLD_III_CHLORIDE, 2.25, new Color( 255, 255, 199 ), new Color( 255, 215, 0 ),
tandem.createTandem( 'goldIIIChloride' ) ),
new Solute( potassiumChromateString, MSymbols.POTASSIUM_CHROMATE, 3.35, new Color( 255, 255, 199 ), Color.YELLOW,
tandem.createTandem( 'potassiumChromate' ) ),
new Solute( nickelIIChlorideString, MSymbols.NICKEL_II_CHLORIDE, 5.2, new Color( 234, 244, 234 ), new Color( 0, 128, 0 ),
tandem.createTandem( 'nickelIIChloride' ) ),
new Solute( copperSulfateString, MSymbols.COPPER_SULFATE, 1.40, new Color( 222, 238, 255 ), new Color( 30, 144, 255 ),
tandem.createTandem( 'copperSulfate' ) ),
new Solute( potassiumPermanganateString, MSymbols.POTASSIUM_PERMANGANATE, 0.50, new Color( 255, 0, 255 ), new Color( 139, 0, 139 ),
tandem.createTandem( 'potassiumPermanganate' ), { particleColor: Color.BLACK } )
new Solute( drinkMixString, MSymbols.DRINK_MIX, 5.95, new Color( 255, 225, 225 ), Color.RED, {
tandem: tandem.createTandem( 'drinkMix' )
} ),
new Solute( cobaltIINitrateString, MSymbols.COBALT_II_NITRATE, 5.65, new Color( 255, 225, 225 ), Color.RED, {
tandem: tandem.createTandem( 'cobaltIINitrate' )
} ),
new Solute( cobaltChlorideString, MSymbols.COBALT_CHLORIDE, 4.35, new Color( 255, 242, 242 ), new Color( 255, 106, 106 ), {
tandem: tandem.createTandem( 'cobaltChloride' )
} ),
new Solute( potassiumDichromateString, MSymbols.POTASSIUM_DICHROMATE, 0.50, new Color( 255, 232, 210 ), new Color( 255, 127, 0 ), {
tandem: tandem.createTandem( 'potassiumDichromate' )
} ),
new Solute( goldIIIChlorideString, MSymbols.GOLD_III_CHLORIDE, 2.25, new Color( 255, 255, 199 ), new Color( 255, 215, 0 ), {
tandem: tandem.createTandem( 'goldIIIChloride' )
} ),
new Solute( potassiumChromateString, MSymbols.POTASSIUM_CHROMATE, 3.35, new Color( 255, 255, 199 ), Color.YELLOW, {
tandem: tandem.createTandem( 'potassiumChromate' )
} ),
new Solute( nickelIIChlorideString, MSymbols.NICKEL_II_CHLORIDE, 5.2, new Color( 234, 244, 234 ), new Color( 0, 128, 0 ), {
tandem: tandem.createTandem( 'nickelIIChloride' )
} ),
new Solute( copperSulfateString, MSymbols.COPPER_SULFATE, 1.40, new Color( 222, 238, 255 ), new Color( 30, 144, 255 ), {
tandem: tandem.createTandem( 'copperSulfate' )
} ),
new Solute( potassiumPermanganateString, MSymbols.POTASSIUM_PERMANGANATE, 0.50, new Color( 255, 0, 255 ), new Color( 139, 0, 139 ), {
tandem: tandem.createTandem( 'potassiumPermanganate' ),
particleColor: Color.BLACK
} )
];

// @public
Expand Down
12 changes: 5 additions & 7 deletions js/molarity/model/Solute.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ define( function( require ) {
'use strict';

// modules
var inherit = require( 'PHET_CORE/inherit' );
var molarity = require( 'MOLARITY/molarity' );
var PhetioObject = require( 'TANDEM/PhetioObject' );

// phet-io modules
var SoluteIO = require( 'ifphetio!MOLARITY/molarity/model/SoluteIO' );
Expand All @@ -22,11 +24,10 @@ define( function( require ) {
* @param {number} saturatedConcentration M (moles/L)
* @param {Color} minColor solution color for smallest non-zero concentration
* @param {Color} maxColor solution color for saturated concentration
* @param {Tandem} tandem
* @param {Object} [options]
* @constructor
*/
function Solute( name, formula, saturatedConcentration, minColor, maxColor, tandem, options ) {
function Solute( name, formula, saturatedConcentration, minColor, maxColor, options ) {

options = _.extend( {
particleColor: maxColor, // the solute's color as a particle
Expand All @@ -41,13 +42,10 @@ define( function( require ) {
this.maxColor = maxColor;
this.particleColor = options.particleColor;

tandem.addInstance( this, options );

// this is used to create the tandem name for ComboBox items
this.tandemName = tandem.tail;
PhetioObject.call( this, options );
}

molarity.register( 'Solute', Solute );

return Solute;
return inherit( PhetioObject, Solute );
} );
8 changes: 2 additions & 6 deletions js/molarity/view/SoluteComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ define( function( require ) {
options.tandem = tandem;

// items
var items = [];
for ( var i = 0; i < solutes.length; i++ ) {
var solute = solutes[ i ];
items[ i ] = createItem( solute );
}
var items = solutes.map( createItem );

ComboBox.call( this, items, selectedSoluteProperty, listParent, options );
}
Expand All @@ -70,7 +66,7 @@ define( function( require ) {
textNode.centerY = colorNode.centerY;

return ComboBox.createItem( node, solute, {
tandemName: solute.tandemName
tandemName: solute.phetioObjectTandem.tail
} );
};

Expand Down

0 comments on commit f018fc1

Please sign in to comment.