-
Notifications
You must be signed in to change notification settings - Fork 7
Description
From #78
I think there's a problem with some (many?) usages of RangeWithValue. A typical usage is like this:
// 1. Create range with value
// 2. Create a NumberProperty that has range: rangeWithValue and initialValue: rangeWithValue.defaultValue
Why not create the NumberProperty directly in the first place? Declaring it as a RangeWithValue in one place then picking values out for the NumberProperty redundant? For example, CLBConstants.js declares:
BATTERY_VOLTAGE_RANGE: new RangeWithValue( -1.5, 1.5, 0 ), // VoltsThen the Property is declared like so:
// @public {Property.<number>}
this.voltageProperty = new NumberProperty( voltage, {
tandem: tandem.createTandem( 'voltageProperty' ),
units: 'volts',
range: CLBConstants.BATTERY_VOLTAGE_RANGE
} );And the voltage variable came from:
CLBConstants.BATTERY_VOLTAGE_RANGE.defaultValue,Or is this expected because we sometimes have one range creating many Property instances (say, one per screen?)
Here's the same thing happening in BeersLawSolution:
this.concentrationProperty = new NumberProperty( concentrationRange.defaultValue, {
units: 'moles/liter',
range: concentrationRange,
tandem: options.tandem.createTandem( 'concentrationProperty' )
} );By that token, why aren't the units associated with the range, so we could do something like this?
this.concentrationProperty = new NumberProperty( concentrationRange.defaultValue, {
units: concentrationRange.units,
range: concentrationRange,
tandem: options.tandem.createTandem( 'concentrationProperty' )
} );Or is there a better way to pass RangeWithValue to a NumberProperty?
Leaving self-assigned for now to think it over before discussing with other members of the team.