From 3d5f7b42febc25626a308400723bdc16753a101d Mon Sep 17 00:00:00 2001 From: samreid Date: Tue, 26 Feb 2019 20:27:18 -0700 Subject: [PATCH] Simplify logic for checking phetioType and validators, see https://github.com/phetsims/axon/issues/204 --- js/Emitter.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/js/Emitter.js b/js/Emitter.js index f57b4fd2..8d662d5a 100644 --- a/js/Emitter.js +++ b/js/Emitter.js @@ -29,6 +29,9 @@ define( require => { class Emitter extends PhetioObject { constructor( options ) { + const phetioTypeSupplied = options && options.hasOwnProperty( 'phetioType' ); + const validatorsSupplied = options && options.hasOwnProperty( 'validators' ); + options = _.extend( { // {Array.|null} - array of "validators" as defined by ValidatorDef.js @@ -61,10 +64,11 @@ define( require => { // keep track of if we get the validators from options, or the phetioType let validatorsFromTypeIO = false; - // important to be before super call - const phetioTypeSupplied = options.phetioType !== EmitterIOWithNoArgs; - assert && assert( !( phetioTypeSupplied && options.validators.length > 0 ), - 'use either phetioType or validators, not both, see EmitterIO to set validators on an instrumented Emitter' ); + // important to be before super call. OK to supply neither or one or the other, but not both. That is a NAND. + assert && assert( + !( phetioTypeSupplied && validatorsSupplied ), + 'use either phetioType or validators, not both, see EmitterIO to set validators on an instrumented Emitter' + ); // use the phetioType's validators if provided, we know we aren't overwriting here because of the above assertion if ( phetioTypeSupplied ) { @@ -74,7 +78,7 @@ define( require => { super( options ); - validate( options.validators, { valueType: Array } ); + assert && validate( options.validators, { valueType: Array } ); if ( assert ) {