phetsims / unit-rates

"Unit Rates" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
0 stars 2 forks source link

factor out common options #205

Closed pixelzoom closed 6 years ago

pixelzoom commented 6 years ago

Noted by @samreid in 3/15/18 dev meeting...

Do a search for ".numeratorOptions = _.extend". Note the default options for numeratorOptions and denominatorOptions are often identical, or at least have significant overlap. Factor these out into constants.

Example in DoubleNumberLine, line 45:

    // @public (read-only) options for the numerator (top) number line
    this.numeratorOptions = _.extend( {
      axisLabel: '', // {string} label for the axis
      maxDecimals: 1, // {number} maximum number of decimal places
      trimZeros: false // {boolean} whether to trim trailing zeros from decimal places
    }, options.numeratorOptions );

    // @public (read-only) options for the denominator (bottom) number line
    this.denominatorOptions = _.extend( {
      axisLabel: '', // {string} label for the axis
      maxDecimals: 1, // {number} maximum number of decimal places
      trimZeros: false // {boolean} whether to trim trailing zeros from decimal places
    }, options.denominatorOptions );

The above would change to something like:

    var SHARED_OPTIONS =  {
      axisLabel: '', // {string} label for the axis
      maxDecimals: 1, // {number} maximum number of decimal places
      trimZeros: false // {boolean} whether to trim trailing zeros from decimal places
    };

    // @public (read-only) options for the numerator (top) number line
    this.numeratorOptions = _.extend( {}, SHARED_OPTIONS, options.numeratorOptions );

    // @public (read-only) options for the denominator (bottom) number line
    this.denominatorOptions = _.extend( {}, SHARED_OPTIONS, options.denominatorOptions );
pixelzoom commented 6 years ago

This occurred in 4 source files, all related to nested options numeratorOptions and denominatorOptions. Tested and fixed in the above commit. Closing.