From f018fc112486213805065c11e3c994e5e336b997 Mon Sep 17 00:00:00 2001 From: samreid Date: Fri, 15 Dec 2017 13:21:16 -0700 Subject: [PATCH] Converted to use PhetioObject, see https://github.com/phetsims/tandem/issues/46 --- js/molarity/model/MolarityModel.js | 46 ++++++++++++++++++------------ js/molarity/model/Solute.js | 12 ++++---- js/molarity/view/SoluteComboBox.js | 8 ++---- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/js/molarity/model/MolarityModel.js b/js/molarity/model/MolarityModel.js index 13e4b4a8..fe0875d8 100644 --- a/js/molarity/model/MolarityModel.js +++ b/js/molarity/model/MolarityModel.js @@ -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 diff --git a/js/molarity/model/Solute.js b/js/molarity/model/Solute.js index 2aaf5d47..7b82fd7a 100644 --- a/js/molarity/model/Solute.js +++ b/js/molarity/model/Solute.js @@ -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' ); @@ -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 @@ -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 ); } ); diff --git a/js/molarity/view/SoluteComboBox.js b/js/molarity/view/SoluteComboBox.js index 8516685b..6d60bc96 100644 --- a/js/molarity/view/SoluteComboBox.js +++ b/js/molarity/view/SoluteComboBox.js @@ -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 ); } @@ -70,7 +66,7 @@ define( function( require ) { textNode.centerY = colorNode.centerY; return ComboBox.createItem( node, solute, { - tandemName: solute.tandemName + tandemName: solute.phetioObjectTandem.tail } ); };