-
Notifications
You must be signed in to change notification settings - Fork 12
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
Instrument HSlider enabledProperty #310
Comments
Yes, the HSlider default enabledProperty should be instrumented, but I don't see a straightforward way to do so. If we add a tandem in the options declaration, it will register the property. Then if the enabledProperty is replaced by the options arguments, we would need to unregister it. Or we could wait until after the options extension to decide whether to create the HSlider enabledProperty, but that would be a bit unconventional and make the options harder to read. @zepumph or @jessegreenberg can you make a recommendation? |
Can tandems and associated properties be set dynamically or do they need to be set up during construction? Would something like this work after the options extension? if ( !this.enabledProperty.tandem ) {
this.enabledProperty.tandem = tandem.createTandem( 'enabledProperty' );
this.enabledProperty.phetioValueType = TBoolean;
} |
Ah, it looks like Node might be the only thing with a getter for tandem. |
As a convention, tandems are provided as constructor arguments and never changed. But we could delay creation of the Emitter until we are sure it is needed. |
I see, so something like this before the options extension? // only create a tandemized Property if we know that it will be needed
var enabledProperty = options.enabledProperty || new Property( true, { /*tandem stuff*/ } );
options = _.extend( {
enabledProperty: enabledProperty
} ); |
Yes, that looks like it would work well, want to give it a try? |
Sure! We will want to do this for |
Seems to be working but @samreid can you please take a look? The "tandem stuff" requires |
Yes, it seems we will need to create TRange. Also, the given implementation seems to be workable (after adding TRange), but these lines will need to be changed: enabledProperty: new Property( true ),
enabledRangeProperty: new Property( range ), // controls the portion of the slider that is enabled Also, it seems unfortunate that the values would have to be set outside of the options declaration, since that is the natural place for developers to look--but I couldn't find a palatable way to do so. Maybe I just need to look further...? |
Also, I'm wondering if should fill in those instrumented properties after the options in order to make sure the tandem gets filled in correctly (in the options extend call). |
I'd love help finding a more elegant solution for this, if one exists, unassigning for now but would be good to collaborate with @jessegreenberg or @zepumph when our time matches up. |
This does seem messy! I committed above a small fix that is a bit more robust. Now I would like to talk through potential solutions. Maybe we could have phet-io have a built in way of overriding something in the tandem registry. Currently we just have this line to protect against this: if ( validateTandems && wrapperMap.hasOwnProperty( phetioID ) ) {
assert && assert( instance === wrapperMap[ phetioID ].instance, 'Cannot register two different instances to the same id: ' + phetioID );
} But if there was a way to opt out of that and say "Hey, I know that this tandem already exists. It was a default and I would quite like to overwrite it." Then we may be able to get away with business as usual. Maybe a flag like I think it is worth mentioning that if we go down this road, it is yet one more phetio option that needs to be kept track of. Possible it would be good to try to organize all of those at some point to make development less confusing. |
I tried to clean up the given implementation. We already know |
It would be nice if we can avoid having to add something like overriding tandems or |
Looks very nice. I am much happier with this solution that where it was an hour ago. I don't think that there are many Types where this will take place, and so I think this is fine, as long as it is well documented. I agree in favor of solutions without adding additional flags like |
From phetsims/forces-and-motion-basics#242. I can optionally pass in an instrumented
enabledProperty
, but should HSlider's defaultenabledProperty
be instrumented?The text was updated successfully, but these errors were encountered: