Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Property validation options #150

Closed
pixelzoom opened this issue Aug 28, 2019 · 3 comments
Closed

use Property validation options #150

pixelzoom opened this issue Aug 28, 2019 · 3 comments

Comments

@pixelzoom
Copy link
Contributor

Related to this item in code review #143:

  • Are Property value validation options (valueType, validValues, etc...) utilized? Is their presence or lack thereof properly documented?

There are currently no usages of validation options in this sim. This info is important for catching programming errors, and for future PhET-iO instrumentation.

For example, in Curve.js:

      // @public {Property.<number>} r^2 deviation value, a number ranging from 0 to 1
      this.rSquaredProperty = new NumberProperty( 0 );

should be:

      // @public {Property.<number>} r^2 deviation value
      this.rSquaredProperty = new NumberProperty( 0, {
        range: new Range( 0, 1 )
      }  );

In Point.js:

      this.isInsideGraphProperty = new DerivedProperty(
        [ this.positionProperty ],
        position => CurveFittingConstants.GRAPH_BACKGROUND_MODEL_BOUNDS.containsPoint( position )
      );

should be:

      this.isInsideGraphProperty = new DerivedProperty(
        [ this.positionProperty ],
        position => CurveFittingConstants.GRAPH_BACKGROUND_MODEL_BOUNDS.containsPoint( position ), {
      valueType: 'boolean'
     } );

So....

  • Take a look at all NumberProperty instances, add range for any that have a range.
  • Take a look at all DerivedProperty instances, add valueType or isValidValue where possible.
@pixelzoom
Copy link
Contributor Author

Using validation options will also make assertions like this in CurveFittingModel unnecessary:

      // validate Property values and update curve fit
      this.orderProperty.link( order => {

        // ensure the order is 1, 2 or 3: linear, quadratic or cubic
        assert && assert( order === 1 || order === 2 || order === 3, `invalid order: ${order}` );
...

SaurabhTotey pushed a commit that referenced this issue Aug 30, 2019
SaurabhTotey pushed a commit that referenced this issue Aug 30, 2019
@SaurabhTotey
Copy link
Member

I have now added more property validation. Assigning to @pixelzoom to review.

@pixelzoom
Copy link
Contributor Author

Looks good, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants