Skip to content

Commit

Permalink
use EmitterIO for validators in instrumented Emitters, phetsims/axon#204
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Feb 23, 2019
1 parent 59bab6c commit 2077a2b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 91 deletions.
4 changes: 1 addition & 3 deletions js/input/DOMEventIO.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions js/input/EventIO.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
42 changes: 0 additions & 42 deletions js/input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 }
Expand All @@ -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 }
Expand All @@ -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 }
Expand All @@ -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 }
Expand All @@ -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 }
] ),
Expand All @@ -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 },
Expand All @@ -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 },
Expand All @@ -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 },
Expand All @@ -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 },
Expand All @@ -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 },
Expand All @@ -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 },
Expand All @@ -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 },
Expand All @@ -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 },
Expand Down Expand Up @@ -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 }
] ),
Expand Down Expand Up @@ -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 }
] ),
Expand Down Expand Up @@ -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 }
] ),
Expand All @@ -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 }
] ),
Expand All @@ -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 }
] ),
Expand All @@ -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 }
] ),
Expand All @@ -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 }
] ),
Expand Down
50 changes: 27 additions & 23 deletions js/input/SimpleDragHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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; }
Expand Down
3 changes: 0 additions & 3 deletions js/listeners/DragListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down Expand Up @@ -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 ) {

Expand Down
37 changes: 20 additions & 17 deletions js/listeners/PressListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand All @@ -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 );
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2077a2b

Please sign in to comment.