Skip to content

Commit

Permalink
Use validate instead of assertInstanceOf, see phetsims/axon#226
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Feb 26, 2019
1 parent f3f8b83 commit ec4fdf2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions js/LinkedElementIO.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ define( function( require ) {

phetioInherit( ObjectIO, 'LinkedElementIO', LinkedElementIO, {}, {
documentation: 'A LinkedElement',
validator: { isValidValue: () => true },

/**
* @param {LinkedElement} linkedElement
Expand Down
9 changes: 3 additions & 6 deletions js/phetioInherit.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ define( function( require ) {

inherit( supertype, subtype, methods, staticProperties );

staticProperties = staticProperties || {};
assert && assert( staticProperties, 'static properties must be defined' );
assert && assert( staticProperties.validator, 'validator must be provided' );
ValidatorDef.validateValidator( staticProperties.validator );

if ( staticProperties.parameterTypes ) {
assert && assert( Array.isArray( staticProperties.parameterTypes ), 'parameterTypes expected to be array' );
Expand All @@ -38,11 +40,6 @@ define( function( require ) {
.join( ', ' ) + '>';
}

// TODO: isn't this field required? see https://github.com/phetsims/axon/issues/204
if( staticProperties.validator){
ValidatorDef.validateValidator( staticProperties.validator);
}

// The method order is used to determine the ordering of the documentation for a type's methods, see Studio for usage.
subtype.methodOrder = staticProperties.methodOrder || [];
subtype.methodOrder.forEach( function( methodName ) {
Expand Down
4 changes: 4 additions & 0 deletions js/types/ObjectIO.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ define( function( require ) {
// modules
var phetioInherit = require( 'TANDEM/phetioInherit' );
var tandemNamespace = require( 'TANDEM/tandemNamespace' );
var validate = require( 'AXON/validate' );

/**
* Main constructor for ObjectIO base IO type.
Expand All @@ -30,6 +31,9 @@ define( function( require ) {

// @public (read-only)
this.phetioID = phetioID;

// Use the validator defined on the constructor to make sure the instance is valid
assert && validate( instance, this.constructor.validator );
}

// ObjectIO inherits from window.Object because it starts with its prototype in phetioInherit.inheritBase
Expand Down

0 comments on commit ec4fdf2

Please sign in to comment.