diff --git a/js/Property.js b/js/Property.js index 3c6334b8..ffd65728 100644 --- a/js/Property.js +++ b/js/Property.js @@ -54,10 +54,7 @@ define( function( require ) { validateOptionsOnValidateValue: false }, options ); - // @private - this.validatorOptions = Validator.pickOptions( options ); - - assert && Validator.validateOptions( this.validatorOptions ); + assert && Validator.validateOptions( options ); assert && options.units && assert( units.isValidUnits( options.units ), 'invalid units: ' + options.units ); if ( options.units ) { @@ -79,8 +76,13 @@ define( function( require ) { // useDeepEquality: false => Use === for equality test this.useDeepEquality = options.useDeepEquality; + // @private {function|false} - closure over options for validation in set() + this.validate = assert && function( value ) { + Validator.validate( value, options ); + }; + // validate the initial value - assert && Validator.validate( value, this.validatorOptions ); + assert && this.validate( value ); // 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 @@ -148,7 +150,7 @@ define( function( require ) { * @public */ set: function( value ) { - assert && Validator.validate( value, this.validatorOptions ); + this.validate && this.validate( value ); if ( this.isDeferred ) { this.deferredValue = value; this.hasDeferredValue = true; diff --git a/js/Validator.js b/js/Validator.js index 016d31c0..513b2a7d 100644 --- a/js/Validator.js +++ b/js/Validator.js @@ -43,8 +43,6 @@ define( require => { validateOptionsOnValidateValue: true }; - const DEFAULT_OPTIONS_KEYS = _.keys( DEFAULT_OPTIONS ); - const Validator = { /** @@ -128,15 +126,7 @@ define( require => { else { return true; } - }, - - /** - * Get only the options that are used by Validator - * @param {Object} [options] - * @returns {Object} - * @public - */ - pickOptions: options => _.pick( options, DEFAULT_OPTIONS_KEYS ) + } }; Validator.DEFAULT_OPTIONS = DEFAULT_OPTIONS;