Skip to content

Impedance mismatch between RangeWithValue and NumberProperty? #79

@samreid

Description

@samreid

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 ), // Volts

Then 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions