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

meanProperty should be a DerivedProperty #75

Closed
pixelzoom opened this issue Jun 28, 2022 · 6 comments
Closed

meanProperty should be a DerivedProperty #75

pixelzoom opened this issue Jun 28, 2022 · 6 comments

Comments

@pixelzoom
Copy link
Contributor

For code review #41 ...

For this checklist item:

  • Are all dependent Properties modeled as DerivedProperty instead of Property?

This is unfortunate in IntroModel.ts, especially since it's arguable the most-important Property in the screen:

    // This value is derived from the water levels in all the cups, but cannot be modeled as a DerivedProperty since
    // the number of cups varies
    this.meanProperty = new NumberProperty( ...

And this unfortunate compromise is due to #60. So to reiterate what I said in that issue, I would reconsider the decision to dynamically allocate pipes and cups. Or investigate other ways of allowing meanProperty to be a DerivedProperty.

@samreid
Copy link
Member

samreid commented Jul 27, 2022

We also used the new feature deriveAny from phetsims/axon#406.

@samreid
Copy link
Member

samreid commented Jul 27, 2022

@marlitas and I collaborated on this, and it seems ready for review. Thanks for the great recommendation!

@pixelzoom
Copy link
Contributor Author

pixelzoom commented Aug 4, 2022

Looks good. A couple of nits...

  • This comment means nothing to me. Maybe say it differently or more verbosely. Is it saying something about the internal implementatioin of DerivedProperty? If so, what if that changes?
    // map() does not preserve a property of .length required for DerivedProperty
    this.meanProperty = DerivedProperty.deriveAny( dependencies,
-         phetioDocumentation: 'The ground truth water level mean.',
+         phetioDocumentation: 'The ground-truth water-level mean.',

@pixelzoom pixelzoom assigned marlitas and unassigned pixelzoom Aug 4, 2022
@pixelzoom
Copy link
Contributor Author

pixelzoom commented Aug 4, 2022

Maybe the comment is trying to explain why dependencies is an array, and not a map? If so, the comment probably belongs above the definition of const dependencies. But even then, you still need to use the spread operator (...) to combine the maps into one array. So maybe the comment is unnecessary?

    const dependencies = [
      ...this.waterCup3DArray.map( waterCup => waterCup.waterLevelProperty ),
      ...this.waterCup3DArray.map( waterCup => waterCup.isActiveProperty )
    ];

    // map() does not preserve a property of .length required for DerivedProperty
    this.meanProperty = DerivedProperty.deriveAny( dependencies,

marlitas added a commit that referenced this issue Aug 9, 2022
@marlitas
Copy link
Contributor

marlitas commented Aug 9, 2022

Documentation updated in above commit. Hopefully this clarifies the comment before meanProperty. I do not fully understand the typing restrictions on derivedProperty, I just know they exist, so if further clarification is needed I'll reach out for assistance.

Assigning back to @pixelzoom for review.

@marlitas marlitas assigned pixelzoom and unassigned marlitas Aug 9, 2022
@pixelzoom
Copy link
Contributor Author

👍🏼 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

3 participants