Skip to content

Commit

Permalink
Use phetioType option, see phetsims/scenery#603
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Feb 8, 2017
1 parent ed9c1fd commit 8f21d76
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 133 deletions.
22 changes: 9 additions & 13 deletions js/ComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ define( function( require ) {

var self = this;

// Register for tandem if possible.
// Allow running with phetioValidateTandems=false though
var type = property.phetioValueType;
if ( phet.phetio && phet.phetio.queryParameters && !phet.phetio.queryParameters.phetioValidateTandems && !type ) {
type = TObject;
}

options = _.extend( {

labelNode: null, // optional label, placed to the left of the combo box
Expand Down Expand Up @@ -72,12 +79,10 @@ define( function( require ) {
itemHighlightLineWidth: 1,

// tandem
tandem: Tandem.tandemRequired()
tandem: Tandem.tandemRequired(),
phetioType: TComboBox( type )
}, options );

var tandem = options.tandem;
options.tandem = options.tandem.createSupertypeTandem();

// validate option values
assert && assert( options.disabledOpacity > 0 && options.disabledOpacity < 1, 'invalid disabledOpacity: ' + options.disabledOpacity );

Expand Down Expand Up @@ -290,7 +295,6 @@ define( function( require ) {
// @private called by dispose
this.disposeComboBox = function() {
self.enabledProperty.unlink( enabledObserver );
tandem.removeInstance( self );

// Unregister itemNode tandems as well
for ( var i = 0; i < listNode.children.length; i++ ) {
Expand All @@ -299,14 +303,6 @@ define( function( require ) {
buttonNode.dispose();
property.unlink( propertyObserver );
};

// Register for tandem if possible.
// Allow running with phetioValidateTandems=false though
var type = property.phetioValueType;
if ( phet.phetio && phet.phetio.queryParameters && !phet.phetio.queryParameters.phetioValidateTandems && !type ) {
type = TObject;
}
tandem.addInstance( this, TComboBox( type ) );
}

sun.register( 'ComboBox', ComboBox );
Expand Down
15 changes: 5 additions & 10 deletions js/HSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,10 @@ define( function( require ) {
constrainValue: function( value ) { return value; }, // called before valueProperty is set

// phet-io
tandem: Tandem.tandemRequired()
tandem: Tandem.tandemRequired(),
phetioType: THSlider
}, options );

var tandem = options.tandem;
options.tandem = options.tandem.createSupertypeTandem();

// @public
this.enabledProperty = options.enabledProperty;
this.enabledRangeProperty = options.enabledRangeProperty;
Expand Down Expand Up @@ -137,7 +135,7 @@ define( function( require ) {
constrainValue: options.constrainValue,

// phet-io
tandem: tandem.createTandem( 'track' )
tandem: options.tandem.createTandem( 'track' )
} );
this.track.centerX = this.valueToPosition( ( range.max + range.min ) / 2 );
this.addChild( this.track );
Expand All @@ -153,7 +151,7 @@ define( function( require ) {
stroke: options.thumbStroke,
lineWidth: options.thumbLineWidth,
centerLineStroke: options.thumbCenterLineStroke,
tandem: tandem.createTandem( 'thumb' )
tandem: options.tandem.createTandem( 'thumb' )
} );

// do this outside of options hash, so that it applied to both default and custom thumbs
Expand All @@ -174,7 +172,7 @@ define( function( require ) {
var clickXOffset = 0; // x-offset between initial click and thumb's origin
var thumbInputListener = new TandemSimpleDragHandler( {

tandem: tandem.createTandem( 'thumbInputListener' ),
tandem: options.tandem.createTandem( 'thumbInputListener' ),

allowTouchSnag: true,

Expand Down Expand Up @@ -268,13 +266,10 @@ define( function( require ) {
self.enabledRangeProperty.unlink( enabledRangeObserver );
self.enabledProperty.unlink( enabledObserver );

tandem.removeInstance( self );
thumbInputListener.dispose();
};

this.mutate( options );

tandem.addInstance( this, THSlider );
}

sun.register( 'HSlider', HSlider );
Expand Down
14 changes: 4 additions & 10 deletions js/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ define( function( require ) {
align: 'left',

minWidth: 0, // minimum width of the panel
tandem: Tandem.tandemRequired()
tandem: Tandem.tandemRequired(),
phetioType: TPanel
};
assert && Object.freeze( DEFAULT_OPTIONS );

Expand All @@ -56,10 +57,6 @@ define( function( require ) {

var self = this;

// substitute supertype tandem because Panel provides TPanel instrumentation
var tandem = options.tandem;
options.tandem = options.tandem.createSupertypeTandem();

assert && assert( _.includes( ALIGN_VALUES, options.align ), 'invalid align: ' + options.align );

Node.call( this );
Expand Down Expand Up @@ -129,17 +126,14 @@ define( function( require ) {
}
updateBackground();

// Apply options after the layout is done, so that options that use the bounds will work properly.
this.mutate( options );

this.disposePanel = function() {
tandem.removeInstance( self );
if ( options.resize ) {
content.off( 'bounds', updateBackground );
}
};

tandem.addInstance( this, TPanel );
// Apply options after the layout is done, so that options that use the bounds will work properly.
this.mutate( options );
}

sun.register( 'Panel', Panel );
Expand Down
8 changes: 2 additions & 6 deletions js/VerticalCheckBoxGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ define( function( require ) {
checkBoxColor: 'black',
align: 'left',
boxWidth: 21,
tandem: Tandem.tandemRequired()
tandem: Tandem.tandemRequired(),
phetioType: TVerticalCheckBoxGroup
}, options );

var tandem = options.tandem;
options.tandem = options.tandem.createSupertypeTandem();

// compute max width of the items
var maxWidth = 0;
for ( var i = 0; i < items.length; i++ ) {
Expand Down Expand Up @@ -82,8 +80,6 @@ define( function( require ) {

options.children = children; //TODO bad form, if options.children was already set, then this will blow it away
VBox.call( this, options );

tandem.addInstance( this, TVerticalCheckBoxGroup );
}

sun.register( 'VerticalCheckBoxGroup', VerticalCheckBoxGroup );
Expand Down
25 changes: 4 additions & 21 deletions js/buttons/RadioButtonGroupMember.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,11 @@ define( function( require ) {
buttonAppearanceStrategy: RadioButtonGroupAppearance.defaultRadioButtonsAppearance,
contentAppearanceStrategy: RadioButtonGroupAppearance.contentAppearanceStrategy,

tandem: Tandem.tandemRequired()
tandem: Tandem.tandemRequired(),
phetioType: TRadioButtonGroupMember( property.phetioValueType )
}, options );

var self = this;

assert && assert( !options.hasOwnProperty( 'phetioValueType' ),
'phetioValueType should be provided by the property and not through options.' );

var tandem = options.tandem;
options.tandem = options.tandem.createSupertypeTandem();
assert && assert( !options.hasOwnProperty( 'phetioValueType' ), 'phetioValueType should be provided by the property and not through options.' );

// @public (phet-io)
this.radioButtonGroupMemberModel = new RadioButtonGroupMemberModel( property, value );
Expand All @@ -79,21 +74,9 @@ define( function( require ) {
this.interactionStateProperty = new RadioButtonInteractionStateProperty( this.radioButtonGroupMemberModel );

RectangularButtonView.call( this, this.radioButtonGroupMemberModel, this.interactionStateProperty, options );

this.disposeRadioButtonGroupMember = function() {
tandem.removeInstance( self );
};
tandem.addInstance( this, TRadioButtonGroupMember( property.phetioValueType ) );
}

sun.register( 'RadioButtonGroupMember', RadioButtonGroupMember );

return inherit( RectangularButtonView, RadioButtonGroupMember, {

// @public
dispose: function() {
RectangularButtonView.prototype.dispose.call( this );
this.disposeRadioButtonGroupMember();
}
} );
return inherit( RectangularButtonView, RadioButtonGroupMember );
} );
19 changes: 2 additions & 17 deletions js/buttons/RectangularPushButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,15 @@ define( function( require ) {
function RectangularPushButton( options ) {

options = _.extend( {
tandem: Tandem.tandemRequired() // {Tandem|null}
tandem: Tandem.tandemRequired(), // {Tandem|null}
phetioType: TPushButton
}, options );

var self = this;

// Safe to pass through options to the PushButtonModel like "fireOnDown". Other scenery options will be safely ignored.
this.buttonModel = new PushButtonModel( options ); // @public, listen only

// Store a reference to the true tandem which will be used to register the instance
var tandem = options.tandem;

// Supply a supertype tandem before Node is called, since we register our own instance
options.tandem = options.tandem.createSupertypeTandem();

// Call the parent type
RectangularButtonView.call( this, this.buttonModel, new PushButtonInteractionStateProperty( this.buttonModel ), options );

this.disposeRectangularPushButton = function() {
tandem.removeInstance( self );
};

// Tandem support
tandem.addInstance( this, TPushButton );
}

sun.register( 'RectangularPushButton', RectangularPushButton );
Expand All @@ -62,7 +48,6 @@ define( function( require ) {
dispose: function() {
this.buttonModel.dispose(); //TODO this fails when assertions are enabled, see sun#212
RectangularButtonView.prototype.dispose.call( this );
this.disposeRectangularPushButton();
},

// @public
Expand Down
15 changes: 3 additions & 12 deletions js/buttons/RectangularToggleButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,16 @@ define( function( require ) {
function RectangularToggleButton( valueOff, valueOn, property, options ) {

options = _.extend( {
tandem: Tandem.tandemRequired()
tandem: Tandem.tandemRequired(),
phetioType: TToggleButton( property.phetioValueType )
}, options );

// @public (phet-io)
var tandem = options.tandem;
options.tandem = options.tandem.createSupertypeTandem();
this.toggleButtonModel = new ToggleButtonModel( valueOff, valueOn, property, options );
RectangularButtonView.call( this, this.toggleButtonModel, new ToggleButtonInteractionStateProperty( this.toggleButtonModel ), options );

tandem.addInstance( this, TToggleButton( property.phetioValueType ) );
}

sun.register( 'RectangularToggleButton', RectangularToggleButton );

return inherit( RectangularButtonView, RectangularToggleButton, {

// @public
dispose: function() {
//TODO implement this, see sun#212
}
} );
return inherit( RectangularButtonView, RectangularToggleButton );
} );
20 changes: 5 additions & 15 deletions js/buttons/RoundMomentaryButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,13 @@ define( function( require ) {
* @constructor
*/
function RoundMomentaryButton( valueOff, valueOn, property, options ) {

var self = this;
options = _.extend( { tandem: Tandem.tandemRequired() }, options );

var tandem = options.tandem;
options.tandem = options.tandem.createSupertypeTandem();
options = _.extend( {
tandem: Tandem.tandemRequired(),
phetioType: TMomentaryButton
}, options );

this.buttonModel = new MomentaryButtonModel( valueOff, valueOn, property );
RoundButtonView.call( this, this.buttonModel, new MomentaryButtonInteractionStateProperty( this.buttonModel ), options );

// @private
this.disposeRoundMomentaryButton = function() {
self.buttonModel.dispose(); //TODO fails with assertions enable, see sun#212
tandem.removeInstance( self );
};

tandem.addInstance( this, TMomentaryButton );
}

sun.register( 'RoundMomentaryButton', RoundMomentaryButton );
Expand All @@ -53,8 +43,8 @@ define( function( require ) {

// @public
dispose: function() {
this.buttonModel.dispose(); //TODO fails with assertions enable, see sun#212
RoundButtonView.prototype.dispose.call( this );
this.disposeRoundMomentaryButton();
}
} );
} );
18 changes: 5 additions & 13 deletions js/buttons/RoundStickyToggleButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,16 @@ define( function( require ) {
*/
function RoundStickyToggleButton( valueUp, valueDown, property, options ) {

options = _.extend( { tandem: Tandem.tandemRequired() }, options );

var tandem = options.tandem;
options.tandem = options.tandem.createSupertypeTandem();
options = _.extend( {
tandem: Tandem.tandemRequired(),
phetioType: TToggleButton( property.phetioValueType )
}, options );

var buttonModel = new StickyToggleButtonModel( valueUp, valueDown, property );
RoundButtonView.call( this, buttonModel, new StickyToggleButtonInteractionStateProperty( buttonModel ), options );

tandem.addInstance( this, TToggleButton( property.phetioValueType ) );
}

sun.register( 'RoundStickyToggleButton', RoundStickyToggleButton, {

// @public
dispose: function() {
//TODO implement this, see sun#212
}
} );
sun.register( 'RoundStickyToggleButton', RoundStickyToggleButton );

return inherit( RoundButtonView, RoundStickyToggleButton );
} );
21 changes: 5 additions & 16 deletions js/buttons/RoundToggleButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,14 @@ define( function( require ) {
*/
function RoundToggleButton( valueOff, valueOn, property, options ) {

var self = this;

// Tandem support
options = _.extend( { tandem: Tandem.tandemRequired() }, options );

var tandem = options.tandem;
options.tandem = options.tandem.createSupertypeTandem();
options = _.extend( {
tandem: Tandem.tandemRequired(),
phetioType: TToggleButton( property.phetioValueType )
}, options );

this.toggleButtonModel = new ToggleButtonModel( valueOff, valueOn, property ); // @public, listen only
RoundButtonView.call( this, this.toggleButtonModel, new ToggleButtonInteractionStateProperty( this.toggleButtonModel ), options );

// Tandem support
tandem.addInstance( this, TToggleButton( property.phetioValueType ) );

// @private - disposal for listener above
this.disposeRoundToggleButton = function() {
tandem.removeInstance( self );
self.toggleButtonModel.dispose();
};
}

sun.register( 'RoundToggleButton', RoundToggleButton );
Expand All @@ -56,7 +45,7 @@ define( function( require ) {

// @public
dispose: function() {
this.disposeRoundToggleButton(); //TODO this fails with assertions enabled, see sun#212
this.toggleButtonModel.dispose(); //TODO this fails with assertions enabled, see sun#212
}
} );
} );

0 comments on commit 8f21d76

Please sign in to comment.