diff --git a/js/concentration/model/Particles.js b/js/concentration/model/Particles.js index 210565f6..8c4984bb 100644 --- a/js/concentration/model/Particles.js +++ b/js/concentration/model/Particles.js @@ -28,21 +28,12 @@ define( function( require ) { /** * Adds a particle. * @param {SoluteParticle} particle - * @public called by TParticles and subclasses + * @protected */ addParticle: function( particle ) { this.particles.push( particle ); }, - /** - * Removes all particles. - * @public - * @abstract - */ - removeAllParticles: function() { - throw new Error( 'must be implemented by subtype' ); - }, - /** * Registers a listener that will be called when the collection of particles has changed in some way * (eg, number of particles, particles move, ...) diff --git a/js/concentration/model/Precipitate.js b/js/concentration/model/Precipitate.js index c3872bd3..6b7523de 100644 --- a/js/concentration/model/Precipitate.js +++ b/js/concentration/model/Precipitate.js @@ -16,9 +16,6 @@ define( function( require ) { var PrecipitateParticle = require( 'BEERS_LAW_LAB/concentration/model/PrecipitateParticle' ); var Vector2 = require( 'DOT/Vector2' ); - // phet-io modules - var TPrecipitate = require( 'BEERS_LAW_LAB/concentration/model/TPrecipitate' ); - /** * @param {ConcentrationSolution} solution * @param {Beaker} beaker @@ -49,8 +46,9 @@ define( function( require ) { self.updateParticles(); } ); - // Persists for the life of the sim, no need to be disposed - tandem.addInstance( this, { phetioType: TPrecipitate } ); + // We're not calling tandem.addInstance for Precipitate because it doesn't add any new attributes or methods. + // And individual particles are derived from the model, so restoring individual particles (as part of saved + // state) is problematic. See https://github.com/phetsims/beers-law-lab/issues/213 } beersLawLab.register( 'Precipitate', Precipitate ); diff --git a/js/concentration/model/ShakerParticles.js b/js/concentration/model/ShakerParticles.js index 209a4399..42471800 100644 --- a/js/concentration/model/ShakerParticles.js +++ b/js/concentration/model/ShakerParticles.js @@ -147,7 +147,6 @@ define( function( require ) { /** * @public - * @override */ removeAllParticles: function() { var particles = this.particles.slice( 0 ); diff --git a/js/concentration/model/TParticles.js b/js/concentration/model/TParticles.js deleted file mode 100644 index e994c8ad..00000000 --- a/js/concentration/model/TParticles.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2017, University of Colorado Boulder - -/** - * PhET-iO Type for Particles - * - * @author Sam Reid (PhET Interactive Simulations) - */ -define( function( require ) { - 'use strict'; - - // modules - var assertInstanceOf = require( 'ifphetio!PHET_IO/assertInstanceOf' ); - var beersLawLab = require( 'BEERS_LAW_LAB/beersLawLab' ); - var phetioInherit = require( 'ifphetio!PHET_IO/phetioInherit' ); - var TObject = require( 'ifphetio!PHET_IO/types/TObject' ); - - /** - * @param {Particles} particles - * @param {string} phetioID - * @constructor - */ - function TParticles( particles, phetioID ) { - assert && assertInstanceOf( particles, phet.beersLawLab.Particles ); - TObject.call( this, particles, phetioID ); - } - - phetioInherit( TObject, 'TParticles', TParticles, {}, { - documentation: 'The particles that are shaken from the shaker.', - - /** - * @param {Particles} particles - * @public - called by subclasses - */ - clearChildInstances: function( particles ) { - particles.removeAllParticles(); - - // Particles.step is not called in playback mode, so this needs to be called explicitly to update the view. - particles.fireChanged(); - }, - - /** - * Create a dynamic particle as specified by the phetioID and state. - * @param {Particles} particles - * @param {Particle} particle - * @public - called by subclasses - */ - addParticle: function( particles, particle ) { - particles.addParticle( particle ); - - // Particles.step is not called in playback mode, so this needs to be called explicitly to update the view. - particles.fireChanged(); - } - } ); - - beersLawLab.register( 'TParticles', TParticles ); - - return TParticles; -} ); \ No newline at end of file diff --git a/js/concentration/model/TPrecipitate.js b/js/concentration/model/TPrecipitate.js deleted file mode 100644 index 95e25800..00000000 --- a/js/concentration/model/TPrecipitate.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2017, University of Colorado Boulder - -/** - * - * @author Sam Reid (PhET Interactive Simulations) - * @author Andrew Adare (PhET Interactive Simulations) - */ -define( function( require ) { - 'use strict'; - - // modules - var assertInstanceOf = require( 'ifphetio!PHET_IO/assertInstanceOf' ); - var beersLawLab = require( 'BEERS_LAW_LAB/beersLawLab' ); - var phetioInherit = require( 'ifphetio!PHET_IO/phetioInherit' ); - var TParticles = require( 'BEERS_LAW_LAB/concentration/model/TParticles' ); - var TPrecipitateParticle = require( 'BEERS_LAW_LAB/concentration/model/TPrecipitateParticle' ); - - /** - * - * @param instance - * @param phetioID - * @constructor - */ - function TPrecipitate( instance, phetioID ) { - assert && assertInstanceOf( instance, phet.beersLawLab.Precipitate ); - TParticles.call( this, instance, phetioID ); - } - - phetioInherit( TParticles, 'TPrecipitate', TPrecipitate, {}, { - documentation: 'The precipitate that comes from the solution', - - clearChildInstances: function( precipitate ) { - TParticles.clearChildInstances( precipitate ); - }, - - /** - * Adds a precipitate particle as specified by the phetioID and state. - * @param {Object} precipitate - * @param {Tandem} tandem - * @param {Object} stateObject - */ - addChildInstance: function( precipitate, tandem, stateObject ) { - var value = TPrecipitateParticle.fromStateObject( stateObject ); - TParticles.addParticle( precipitate, new phet.beersLawLab.PrecipitateParticle( - value.solute, - value.location, - value.orientation, - tandem - ) ); - } - } ); - - beersLawLab.register( 'TPrecipitate', TPrecipitate ); - - return TPrecipitate; -} ); - diff --git a/js/concentration/model/TShakerParticles.js b/js/concentration/model/TShakerParticles.js index 9b111cf4..a84525b0 100644 --- a/js/concentration/model/TShakerParticles.js +++ b/js/concentration/model/TShakerParticles.js @@ -14,37 +14,42 @@ define( function( require ) { var phetioInherit = require( 'ifphetio!PHET_IO/phetioInherit' ); var TObject = require( 'ifphetio!PHET_IO/types/TObject' ); var TShakerParticle = require( 'BEERS_LAW_LAB/concentration/model/TShakerParticle' ); - var TParticles = require( 'BEERS_LAW_LAB/concentration/model/TParticles' ); /** * - * @param instance + * @param {ShakerParticles} shakerParticles * @param phetioID * @constructor */ - function TShakerParticles( instance, phetioID ) { - assert && assertInstanceOf( instance, phet.beersLawLab.ShakerParticles ); - TParticles.call( this, instance, phetioID ); + function TShakerParticles( shakerParticles, phetioID ) { + assert && assertInstanceOf( shakerParticles, phet.beersLawLab.ShakerParticles ); + TObject.call( this, shakerParticles, phetioID ); } phetioInherit( TObject, 'TShakerParticles', TShakerParticles, {}, { + documentation: 'Base type for a group of particles.', - clearChildInstances: function( instance ) { - TParticles.clearChildInstances( instance ); + clearChildInstances: function( shakerParticles ) { + shakerParticles.removeAllParticles(); + + // Particles.step is not called in playback mode, so this needs to be called explicitly to update the view. + shakerParticles.fireChanged(); }, /** * Create a dynamic particle as specified by the phetioID and state. - * @param {Object} instance + * @param {ShakerParticles} shakerParticles * @param {Tandem} tandem * @param {Object} stateObject * @returns {ChargedParticle} */ - addChildInstance: function( instance, tandem, stateObject ) { + addChildInstance: function( shakerParticles, tandem, stateObject ) { + var value = TShakerParticle.fromStateObject( stateObject ); assert && assert( value.acceleration instanceof phet.dot.Vector2, 'acceleration should be a Vector2' ); - TParticles.addParticle( instance, new phet.beersLawLab.ShakerParticle( + + shakerParticles.addParticle( new phet.beersLawLab.ShakerParticle( value.solute, value.location, value.orientation, @@ -52,6 +57,9 @@ define( function( require ) { value.acceleration, tandem ) ); + + // Particles.step is not called in playback mode, so this needs to be called explicitly to update the view. + shakerParticles.fireChanged(); } } );