Skip to content

Commit

Permalink
tandemOptional in Property.js, factor Optional/RequiredAndNotSupplied…
Browse files Browse the repository at this point in the history
… into required and supplied options, phetsims/scenery-phet#26 2
  • Loading branch information
zepumph committed May 12, 2017
1 parent 7b0852e commit 3471b08
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions js/DerivedProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,7 +38,9 @@ define( function( require ) {
*/
function DerivedProperty( dependencies, derivation, options ) {

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

this.dependencies = dependencies; // @private

Expand Down Expand Up @@ -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 );
Expand Down
6 changes: 3 additions & 3 deletions js/Property.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
} ) );
Expand Down

0 comments on commit 3471b08

Please sign in to comment.