phetsims / masses-and-springs-basics

"Masses and Springs: Basics" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
0 stars 3 forks source link

duplicated code for Gravity combo box #51

Closed pixelzoom closed 5 years ago

pixelzoom commented 5 years ago

Noted while working on https://github.com/phetsims/sun/issues/428#issuecomment-451622311.

Code that creates the items for the Gravity combo box is duplicated, see GravityAccordionBox and GravityAndDampingControlNode:

    //  Add gravity info for various planets
    var bodyListItems = [];
    var bodies = Body.BODIES;
    Body.BODIES.forEach( function( body ) {
      var bodyLabel = new Text( body.title, {
        font: MassesAndSpringsConstants.LABEL_FONT,
        maxWidth: MAX_WIDTH,
        tandem: tandem.createTandem( 'bodyLabel' )
      } );
      bodyLabel.localBounds = bodyLabel.localBounds.withX( 107 );
      bodyListItems.push( ComboBox.createItem( bodyLabel, body ) );
    } );

So I had to do the same work twice for https://github.com/phetsims/sun/issues/428. Highly recommended to factor out GravityComboBox and use it in both sims.

Denz1994 commented 5 years ago

GravityComboBox.js has been created to remove the code duplication. Any differences in the combo boxes prior to the refactor have been added to the options at the repo-specific call site. Also, some variables have had their exposure made private due to the above changes. Closing.