From 3471b0812792426bf58bd9bab8b7e0ee6d103a7b Mon Sep 17 00:00:00 2001 From: zepumph Date: Fri, 12 May 2017 13:58:35 -0600 Subject: [PATCH] tandemOptional in Property.js, factor Optional/RequiredAndNotSupplied into required and supplied options, https://github.com/phetsims/scenery-phet/issues/26 2 --- js/DerivedProperty.js | 7 +++++-- js/Property.js | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/js/DerivedProperty.js b/js/DerivedProperty.js index b0dae2d2..7bde9ad2 100644 --- a/js/DerivedProperty.js +++ b/js/DerivedProperty.js @@ -16,6 +16,7 @@ define( function( require ) { var axon = require( 'AXON/axon' ); var inherit = require( 'PHET_CORE/inherit' ); var TDerivedProperty = require( 'AXON/TDerivedProperty' ); + var Tandem = require( 'TANDEM/Tandem' ); function equalsFunction( a, b ) { return a === b; @@ -37,7 +38,9 @@ define( function( require ) { */ function DerivedProperty( dependencies, derivation, options ) { - options = options || {}; + options = _.extend( { + tandem: Tandem.tandemOptional() + }, options ); this.dependencies = dependencies; // @private @@ -69,7 +72,7 @@ define( function( require ) { } // If running as phet-io and a tandem is supplied, register with tandem. - options.tandem && options.tandem.addInstance( this, TDerivedProperty( options.phetioValueType ) ); + options.tandem.supplied && options.tandem.addInstance( this, TDerivedProperty( options.phetioValueType ) ); this.disposeDerivedProperty = function() { options.tandem && options.tandem.removeInstance( self ); diff --git a/js/Property.js b/js/Property.js index dd59ae31..b99d4d13 100644 --- a/js/Property.js +++ b/js/Property.js @@ -32,7 +32,7 @@ define( function( require ) { } options = _.extend( { - tandem: null, // {Tandem | null} + tandem: Tandem.tandemOptional(), phetioValueType: null, // {function | null} phet-io type wrapper like TString, TNumber, etc. // {*[]|null} valid values for this Property. Mutually exclusive with options.isValidValue @@ -78,7 +78,7 @@ define( function( require ) { // When running as phet-io, if the tandem is specified, the type must be specified. // This assertion helps in instrumenting code that has the tandem but not type - Tandem.validationEnabled() && options.tandem && assert && assert( !!options.phetioValueType, + Tandem.validationEnabled() && options.tandem.isLegalAndUsable() && assert && assert( !!options.phetioValueType, 'Type passed to Property must be specified. Tandem.id: ' + options.tandem.id ); // @public (read-only) Emitters that indicate the start/end of processing callbacks for a change. Also used for PhET-iO data stream @@ -96,7 +96,7 @@ define( function( require ) { this.changedEmitter = new Emitter(); // If running as phet-io and a tandem is supplied, register with tandem. - options.tandem && options.tandem.addInstance( this, TProperty( options.phetioValueType, { + options.tandem.supplied && options.tandem.addInstance( this, TProperty( options.phetioValueType, { phetioInstanceDocumentation: options.phetioInstanceDocumentation, phetioStateElement: options.phetioStateElement } ) );