diff --git a/js/input/DOMEventIO.js b/js/input/DOMEventIO.js index 3c9b7fd7b..08d6ea302 100644 --- a/js/input/DOMEventIO.js +++ b/js/input/DOMEventIO.js @@ -37,10 +37,8 @@ define( require => { * Note this is a DOM event, not a scenery.Event * @override * @public - * @param {*} instance - * @returns {boolean} */ - isInstance: function( instance ) { return instance instanceof window.Event; }, + validator: { valueType: window.Event }, /** * Encodes a DOMEvent instance to a state. diff --git a/js/input/EventIO.js b/js/input/EventIO.js index 4dc75f168..a350da456 100644 --- a/js/input/EventIO.js +++ b/js/input/EventIO.js @@ -35,10 +35,8 @@ define( function( require ) { /** * @override * @public - * @param {*} instance - * @returns {boolean} */ - isInstance: function( instance ) { return instance instanceof Event; }, + validator: { valueType: Event }, /** * Encodes a Color into a state object. diff --git a/js/input/Input.js b/js/input/Input.js index 2883d63a8..7bdb40cf9 100644 --- a/js/input/Input.js +++ b/js/input/Input.js @@ -242,8 +242,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'mouseUpEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: Vector2 }, { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'point', type: Vector2IO }, { name: 'event', type: DOMEventIO } @@ -262,8 +260,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'mouseDownEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: Vector2 }, { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'point', type: Vector2IO }, { name: 'event', type: DOMEventIO } @@ -282,8 +278,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'mouseMovedEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: Vector2 }, { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'point', type: Vector2IO }, { name: 'event', type: DOMEventIO } @@ -303,8 +297,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'mouseOverEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: Vector2 }, { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'point', type: Vector2IO }, { name: 'event', type: DOMEventIO } @@ -323,8 +315,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'mouseOutEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: Vector2 }, { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'point', type: Vector2IO }, { name: 'event', type: DOMEventIO } @@ -343,8 +333,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'wheelScrolledEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'event', type: DOMEventIO } ] ), @@ -369,8 +357,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'touchStartedEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: 'number' }, { valueType: Vector2 }, { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'id', type: NumberIO }, { name: 'point', type: Vector2IO }, @@ -390,8 +376,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'touchEndedEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: 'number' }, { valueType: Vector2 }, { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'id', type: NumberIO }, { name: 'point', type: Vector2IO }, @@ -414,8 +398,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'touchMovedEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: 'number' }, { valueType: Vector2 }, { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'id', type: NumberIO }, { name: 'point', type: Vector2IO }, @@ -438,8 +420,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'touchCanceledEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: 'number' }, { valueType: Vector2 }, { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'id', type: NumberIO }, { name: 'point', type: Vector2IO }, @@ -462,8 +442,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'penStartedEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: 'number' }, { valueType: Vector2 }, { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'id', type: NumberIO }, { name: 'point', type: Vector2IO }, @@ -483,8 +461,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'penEndedEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: 'number' }, { valueType: Vector2 }, { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'id', type: NumberIO }, { name: 'point', type: Vector2IO }, @@ -507,8 +483,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'penMovedEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: 'number' }, { valueType: Vector2 }, { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'id', type: NumberIO }, { name: 'point', type: Vector2IO }, @@ -531,8 +505,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'penCanceledEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: 'number' }, { valueType: Vector2 }, { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'id', type: NumberIO }, { name: 'point', type: Vector2IO }, @@ -582,8 +554,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'focusinEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'event', type: DOMEventIO } ] ), @@ -617,8 +587,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'focusoutEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'event', type: DOMEventIO } ] ), @@ -674,8 +642,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'clickEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'event', type: DOMEventIO } ] ), @@ -698,8 +664,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'inputEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'event', type: DOMEventIO } ] ), @@ -722,8 +686,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'changeEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'event', type: DOMEventIO } ] ), @@ -746,8 +708,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'keydownEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'event', type: DOMEventIO } ] ), @@ -770,8 +730,6 @@ define( require => { phetioPlayback: true, tandem: options.tandem.createTandem( 'keyupEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: window.Event } ], phetioType: EmitterIO( [ { name: 'event', type: DOMEventIO } ] ), diff --git a/js/input/SimpleDragHandler.js b/js/input/SimpleDragHandler.js index 3051071fc..a26f0e43d 100644 --- a/js/input/SimpleDragHandler.js +++ b/js/input/SimpleDragHandler.js @@ -95,11 +95,14 @@ define( function( require ) { this.dragStartedEmitter = new Emitter( { tandem: options.tandem.createTandem( 'dragStartedEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ { valueType: Vector2 }, { isValidValue: function( value ) { return value === null || value instanceof Event; } } ], phetioType: EmitterIO( [ { name: 'point', type: Vector2IO, documentation: 'the position of the drag start in view coordinates' }, - { name: 'event', type: VoidIO, documentation: 'the scenery pointer Event' } ] ), + { + name: 'event', + type: VoidIO, + documentation: 'the scenery pointer Event', + validator: { isValidValue: function( value ) { return value === null || value instanceof Event; } } + } ] ), first: function( point, event ) { if ( self.dragging ) { return; } @@ -136,14 +139,14 @@ define( function( require ) { phetioHighFrequency: true, tandem: options.tandem.createTandem( 'draggedEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ - { valueType: Vector2 }, - { isValidValue: function( value ) { return value === null || value instanceof Event; } } - ], phetioType: EmitterIO( [ { name: 'point', type: Vector2IO, documentation: 'the position of the drag in view coordinates' }, - { name: 'event', type: VoidIO, documentation: 'the scenery pointer Event' } ] ), + { + name: 'event', + type: VoidIO, + documentation: 'the scenery pointer Event', + validator: { isValidValue: function( value ) { return value === null || value instanceof Event;} } + } ] ), first: function( point, event ) { if ( !self.dragging || self.isDisposed ) { return; } @@ -192,22 +195,23 @@ define( function( require ) { this.dragEndedEmitter = new Emitter( { tandem: options.tandem.createTandem( 'dragEndedEmitter' ), - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ - { valueType: Vector2 }, - { - isValidValue: function( value ) { - return value === null || value instanceof Event || - - // When interrupted, an object literal is used to signify the interruption, - // see SimpleDragHandler.interrupt - ( value.pointer && value.currentTarget ); - } - } - ], phetioType: EmitterIO( [ { name: 'point', type: Vector2IO, documentation: 'the position of the drag end in view coordinates' }, - { name: 'event', type: VoidIO, documentation: 'the scenery pointer Event' } ] ), + { + name: 'event', + type: VoidIO, + documentation: 'the scenery pointer Event', + validator: { + isValidValue: function( value ) { + return value === null || value instanceof Event || + + // When interrupted, an object literal is used to signify the interruption, + // see SimpleDragHandler.interrupt + ( value.pointer && value.currentTarget ); + } + } + } + ] ), first: function( point, event ) { if ( !self.dragging ) { return; } diff --git a/js/listeners/DragListener.js b/js/listeners/DragListener.js index 9133d8dd9..e0822229d 100644 --- a/js/listeners/DragListener.js +++ b/js/listeners/DragListener.js @@ -43,7 +43,6 @@ define( function( require ) { var Bounds2 = require( 'DOT/Bounds2' ); var Emitter = require( 'AXON/Emitter' ); var EmitterIO = require( 'AXON/EmitterIO' ); - var Event = require( 'SCENERY/input/Event' ); var EventIO = require( 'SCENERY/input/EventIO' ); var inherit = require( 'PHET_CORE/inherit' ); var PhetioObject = require( 'TANDEM/PhetioObject' ); @@ -192,8 +191,6 @@ define( function( require ) { phetioDocumentation: 'Emits whenever a drag occurs with an EventIO argument.', phetioReadOnly: options.phetioReadOnly, phetioEventType: PhetioObject.EventType.USER, - - validators: [ { valueType: Event } ], phetioType: DraggedEmitterIO, first: function( event ) { diff --git a/js/listeners/PressListener.js b/js/listeners/PressListener.js index 87e639dc1..49ef56e6d 100644 --- a/js/listeners/PressListener.js +++ b/js/listeners/PressListener.js @@ -19,11 +19,11 @@ define( function( require ) { var DerivedProperty = require( 'AXON/DerivedProperty' ); var Emitter = require( 'AXON/Emitter' ); var EmitterIO = require( 'AXON/EmitterIO' ); - var Event = require( 'SCENERY/input/Event' ); var EventIO = require( 'SCENERY/input/EventIO' ); var inherit = require( 'PHET_CORE/inherit' ); var Mouse = require( 'SCENERY/input/Mouse' ); var Node = require( 'SCENERY/nodes/Node' ); + var NullableIO = require( 'TANDEM/types/NullableIO' ); var ObservableArray = require( 'AXON/ObservableArray' ); var PhetioObject = require( 'TANDEM/PhetioObject' ); var scenery = require( 'SCENERY/scenery' ); @@ -37,11 +37,26 @@ define( function( require ) { // constants - factored out to reduce memory usage, see https://github.com/phetsims/unit-rates/issues/207 var PressedEmitterIO = EmitterIO( [ { name: 'event', type: EventIO }, - { name: 'targetNode', type: VoidIO }, - { name: 'callback', type: VoidIO } + { + name: 'targetNode', + type: VoidIO, + validator: { isValidValue: function( v ) { return v === null || v instanceof Node; } } + }, + { + name: 'callback', + type: VoidIO, + validator: { isValidValue: function( v ) { return v === null || typeof v === 'function'; } } + } ] ); - var ReleasedEmitterIO = EmitterIO( [ { name: 'callback', type: VoidIO } ] ); + var ReleasedEmitterIO = EmitterIO( [ { + name: 'event', + type: NullableIO( EventIO ) + }, { + name: 'callback', + type: VoidIO, + validator: { isValidValue: function( v ) { return v === null || typeof v === 'function'; } } + } ] ); // Factor out to reduce memory footprint, see https://github.com/phetsims/tandem/issues/71 const truePredicate = _.constant( true ); @@ -225,13 +240,6 @@ define( function( require ) { phetioReadOnly: options.phetioReadOnly, phetioFeatured: options.phetioFeatured, phetioEventType: PhetioObject.EventType.USER, - - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ - { valueType: Event }, - { isValidValue: function( v ) { return v === null || v instanceof Node; } }, - { isValidValue: function( v ) { return v === null || typeof v === 'function'; } } - ], phetioType: PressedEmitterIO, // The main implementation of "press" handling is implemented as a callback to the emitter, so things are nested @@ -247,11 +255,6 @@ define( function( require ) { phetioFeatured: options.phetioFeatured, phetioEventType: PhetioObject.EventType.USER, - // TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194 - validators: [ - { isValidValue: v => v instanceof Event || v === null }, - { isValidValue: function( v ) { return v === null || typeof v === 'function'; } } - ], phetioType: ReleasedEmitterIO, // The main implementation of "release" handling is implemented as a callback to the emitter, so things are nested @@ -423,7 +426,7 @@ define( function( require ) { // handle a11y interrupt if ( this.a11yClickingProperty.value ) { this.interrupted = true; - + if ( timer.hasListener( this._a11yClickingTimeoutListener ) ) { timer.clearTimeout( this._a11yClickingTimeoutListener ); this.a11yClickingProperty.value = false;