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 ce93653 commit 5b8debd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
8 changes: 3 additions & 5 deletions js/common/model/BodyIO.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,27 @@ define( function( require ) {
var massesAndSprings = require( 'MASSES_AND_SPRINGS/massesAndSprings' );
var ObjectIO = require( 'TANDEM/types/ObjectIO' );
var phetioInherit = require( 'TANDEM/phetioInherit' );

// ifphetio
var assertInstanceOf = require( 'ifphetio!PHET_IO/assertInstanceOf' );
var validate = require( 'AXON/validate' );

/**
* @param {Body} body
* @param {string} phetioID
* @constructor
*/
function BodyIO( body, phetioID ) {
assert && assertInstanceOf( body, Body );
ObjectIO.call( this, body, phetioID );
}

phetioInherit( ObjectIO, 'BodyIO', BodyIO, {}, {
validator: { valueType: Body },
/**
* Encodes a Body instance to a state.
*
* @param body
* @returns {*}
*/
toStateObject: function( body ) {
assert && assertInstanceOf( body, Body );
validate( body, this.validator );
if ( body === null ) {
return null;
}
Expand Down
8 changes: 3 additions & 5 deletions js/common/model/MassIO.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,27 @@ define( function( require ) {
var massesAndSprings = require( 'MASSES_AND_SPRINGS/massesAndSprings' );
var ObjectIO = require( 'TANDEM/types/ObjectIO' );
var phetioInherit = require( 'TANDEM/phetioInherit' );

// ifphetio
var assertInstanceOf = require( 'ifphetio!PHET_IO/assertInstanceOf' );
var validate = require( 'AXON/validate' );

/**
* @param {Mass} mass
* @param {string} phetioID
* @constructor
*/
function MassIO( mass, phetioID ) {
assert && assertInstanceOf( mass, Mass );
ObjectIO.call( this, mass, phetioID );
}

phetioInherit( ObjectIO, 'MassIO', MassIO, {}, {
validator: { valueType: Mass },
/**
* Encodes a Mass instance to a state.
*
* @param mass
* @returns {*}
*/
toStateObject: function( mass ) {
assert && assertInstanceOf( mass, Mass );
validate( mass, this.validator );
if ( mass === null ) {
return null;
}
Expand Down
9 changes: 4 additions & 5 deletions js/common/model/SpringIO.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,28 @@ define( function( require ) {
var ObjectIO = require( 'TANDEM/types/ObjectIO' );
var phetioInherit = require( 'TANDEM/phetioInherit' );
var Spring = require( 'MASSES_AND_SPRINGS/common/model/Spring' );

// ifphetio
var assertInstanceOf = require( 'ifphetio!PHET_IO/assertInstanceOf' );
var validate = require( 'AXON/validate' );

/**
* @param {Spring} spring
* @param {string} phetioID
* @constructor
*/
function SpringIO( spring, phetioID ) {
assert && assertInstanceOf( spring, Spring );
ObjectIO.call( this, spring, phetioID );
}

phetioInherit( ObjectIO, 'SpringIO', SpringIO, {}, {

validator: { valueType: Spring },
/**
* Encodes a Spring instance to a state.
*
* @param spring
* @returns {*}
*/
toStateObject: function( spring ) {
assert && assertInstanceOf( spring, Spring );
validate( spring, this.validator );
if ( spring === null ) {
return null;
}
Expand Down

0 comments on commit 5b8debd

Please sign in to comment.