-
Notifications
You must be signed in to change notification settings - Fork 12
Slider PhET-iO problems custom thumbNode and trackNode #694
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
Comments
Sam Reid 9:58 AM Chris Malley 9:58 AM Sam Reid 9:59 AM Chris Malley 9:59 AM |
Search for |
This issue seems to be a great example of how poorly phet-io works with dependency injection. Above is what I was forced to do in order to fix the assertion error in a CL usage. This is a really really awkward example, perhaps some of the worst we may find for this case. A common code type (ISLCObjectControlPanel) composes a NumberControl, and then a subtype of that panel (ChargeControl) provides a custom thumb to the slider in said NumberControl. Since the parent defines the Perhaps we have too strict a constraint? On the other hand, if the Slider tandem/default thumb tandem ever changes out from under this, that will fail the assertion too, so while it is more maintenance, the above commit is still always a loud error upon failure. @samreid do you have any recommendations about how this could be better. |
Instead of options // {function(option:Object):Node
createThumbNode: null,
createTrackNode: null, On second thought, I don't like that either. It really limits the constructor signture for these custom nodes. For example, in Fourier AmplitudeSlider.js, I have these nested classes for custom thumb and track: class GrippyThumb extends Node {
constructor( thumbSize, harmonic ) {
class BarTrack extends SliderTrack {
constructor( trackSize, harmonic, amplitudeRange ) { |
We discussed creating functions that take a tandem and return a component in https://github.com/phetsims/phet-io/issues/1617 and it was not among our favorites (for that problem). |
In the commits, I changed the names, added documentation to indicate the required tandem names, and I visited the instrumented cases at thumbNode:, trackNode:, options.thumbNode =, and options.trackNode =. @zepumph can you please review? |
Two things:
I'll fix these things and assign back to @samreid for review. |
Fixed in the above commits. Over to @samreid for review. |
This still seems unacceptable to me, @samreid by closing this issue are you recommending that we keep this line because even though there is duplication we still have an assertion letting us know when it needs to be updated? If you still feel good about it please re-close. |
Yeah, I agree with @zepumph. ChargeControl.js is awful. Again: 83 tandem: options.tandem.createTandem( 'numberControl' ).createTandem( 'slider' ).createTandem( Slider.THUMB_NODE_TANDEM_NAME ) Besides the verbose grossness... That 150 tandem: options.tandem.createTandem( 'slider' ) So the code in ChargeControl.js is relying on internal (private) details of NumberControl. If that ever changes in NumberControl, someone must know to change 'slider' in ChargeControl. That's just not going to happen, and is going to break the tandem hierarchy. |
Is the proposal to factor out |
No, not quite. There's no need to factor out Promoting NumberControl.SLIDER_TANDEM_NAME = 'slider'; After that, we end up with this in ChargeControl.js: 83 tandem: options.tandem.createTandem( 'numberControl' ).createTandem( NumberControl.SLIDER_TANDEM_NAME ).createTandem( Slider.THUMB_NODE_TANDEM_NAME ) This addresses the possibility of breaking things because of relying on internal details of NumberControl. It does not address the original concern, which @zepumph summarized nicely in #694 (comment):
I don't know how to address that problem. |
Yikes. Things are even worse than I thought in ChargeControl.js. Again: 83 tandem: options.tandem.createTandem( 'numberControl' ).createTandem( NumberControl.SLIDER_TANDEM_NAME ).createTandem( Slider.THUMB_NODE_TANDEM_NAME ) That 111 tandem: tandem.createTandem( 'numberControl' ) Change one of these and the tandem hierachy is broken. There are 3 problems here:
|
Yes but it is a loud error, because we are testing for equality in places like Lines 201 to 205 in 1c65b74
Anything else here? Feel free to close @pixelzoom. |
Yes. Please summarize what you did so that I don't have to deduce from comments and multiple commits. |
The commits above factored out duplicated tandem names into constants to fix the gross line in ChargeControl. It used the same pattern that you used for Slider tandem names (like the second checkbox in #694 (comment)). |
Thanks for clarifying. So we went from this: tandem: options.tandem.createTandem( 'numberControl' ).createTandem( 'slider' ).createTandem( 'thumb' ) to this: tandem: options.tandem.createTandem( ISLCObjectControlPanel.NUMBER_CONTROL_TANDEM_NAME )
.createTandem( NumberControl.SLIDER_TANDEM_NAME ).createTandem( Slider.THUMB_NODE_TANDEM_NAME ) This likely does not address your comment in #694 (comment), but I don't have any other suggestions. It's still gross, but less likely to get broken now that you're using constants. I don't see anything else that needs to be done here, so closing. |
Broken by afbfeab.
If you pass in a custom
trackNode
orthumbNode
via options, they must now have standard tandem names.Problems:
trackNode
orthumbNode
.trackNode
andthumbNode
options.'track'
and 'thumb
' literals?The text was updated successfully, but these errors were encountered: