Skip to content

Commit

Permalink
Emitter to use argumentTypes with Validator validation, see phetsims/…
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Jan 5, 2019
1 parent ba988b5 commit 1021233
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 9 deletions.
63 changes: 63 additions & 0 deletions js/input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ define( require => {
this.mouseUpEmitter = new Emitter( {
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
argumentTypes: [ { valueType: Vector2 }, { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'point', type: Vector2IO },
{ name: 'event', type: DOMEventIO }
Expand All @@ -257,6 +260,9 @@ define( require => {
this.mouseDownEmitter = new Emitter( {
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
argumentTypes: [ { valueType: Vector2 }, { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'point', type: Vector2IO },
{ name: 'event', type: DOMEventIO }
Expand All @@ -274,6 +280,9 @@ define( require => {
this.mouseMovedEmitter = new Emitter( {
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
argumentTypes: [ { valueType: Vector2 }, { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'point', type: Vector2IO },
{ name: 'event', type: DOMEventIO }
Expand All @@ -292,6 +301,9 @@ define( require => {
this.mouseOverEmitter = new Emitter( {
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
argumentTypes: [ { valueType: Vector2 }, { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'point', type: Vector2IO },
{ name: 'event', type: DOMEventIO }
Expand All @@ -309,6 +321,9 @@ define( require => {
this.mouseOutEmitter = new Emitter( {
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
argumentTypes: [ { valueType: Vector2 }, { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'point', type: Vector2IO },
{ name: 'event', type: DOMEventIO }
Expand All @@ -326,6 +341,9 @@ define( require => {
this.wheelScrolledEmitter = new Emitter( {
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
argumentTypes: [ { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'event', type: DOMEventIO }
] ),
Expand All @@ -349,6 +367,9 @@ define( require => {
this.touchStartedEmitter = new Emitter( {
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
argumentTypes: [ { valueType: 'number' }, { valueType: Vector2 }, { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'id', type: NumberIO },
{ name: 'point', type: Vector2IO },
Expand All @@ -367,6 +388,9 @@ define( require => {
this.touchEndedEmitter = new Emitter( {
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
argumentTypes: [ { valueType: 'number' }, { valueType: Vector2 }, { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'id', type: NumberIO },
{ name: 'point', type: Vector2IO },
Expand All @@ -388,6 +412,9 @@ define( require => {
this.touchMovedEmitter = new Emitter( {
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
argumentTypes: [ { valueType: 'number' }, { valueType: Vector2 }, { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'id', type: NumberIO },
{ name: 'point', type: Vector2IO },
Expand All @@ -409,6 +436,9 @@ define( require => {
this.touchCanceledEmitter = new Emitter( {
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
argumentTypes: [ { valueType: 'number' }, { valueType: Vector2 }, { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'id', type: NumberIO },
{ name: 'point', type: Vector2IO },
Expand All @@ -430,6 +460,9 @@ define( require => {
this.penStartedEmitter = new Emitter( {
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
argumentTypes: [ { valueType: 'number' }, { valueType: Vector2 }, { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'id', type: NumberIO },
{ name: 'point', type: Vector2IO },
Expand All @@ -448,6 +481,9 @@ define( require => {
this.penEndedEmitter = new Emitter( {
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
argumentTypes: [ { valueType: 'number' }, { valueType: Vector2 }, { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'id', type: NumberIO },
{ name: 'point', type: Vector2IO },
Expand All @@ -469,6 +505,9 @@ define( require => {
this.penMovedEmitter = new Emitter( {
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
argumentTypes: [ { valueType: 'number' }, { valueType: Vector2 }, { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'id', type: NumberIO },
{ name: 'point', type: Vector2IO },
Expand All @@ -490,6 +529,9 @@ define( require => {
this.penCanceledEmitter = new Emitter( {
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
argumentTypes: [ { valueType: 'number' }, { valueType: Vector2 }, { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'id', type: NumberIO },
{ name: 'point', type: Vector2IO },
Expand Down Expand Up @@ -533,6 +575,9 @@ define( require => {
this.focusinEmitter = new Emitter( {
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
argumentTypes: [ { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'event', type: DOMEventIO }
] ),
Expand All @@ -554,6 +599,9 @@ define( require => {
this.focusoutEmitter = new Emitter( {
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
argumentTypes: [ { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'event', type: DOMEventIO }
] ),
Expand Down Expand Up @@ -582,6 +630,9 @@ define( require => {
this.clickEmitter = new Emitter( {
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
argumentTypes: [ { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'event', type: DOMEventIO }
] ),
Expand All @@ -603,6 +654,9 @@ define( require => {
this.inputEmitter = new Emitter( {
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
argumentTypes: [ { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'event', type: DOMEventIO }
] ),
Expand All @@ -624,6 +678,9 @@ define( require => {
this.changeEmitter = new Emitter( {
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
argumentTypes: [ { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'event', type: DOMEventIO }
] ),
Expand All @@ -645,6 +702,9 @@ define( require => {
this.keydownEmitter = new Emitter( {
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
argumentTypes: [ { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'event', type: DOMEventIO }
] ),
Expand All @@ -666,6 +726,9 @@ define( require => {
this.keyupEmitter = new Emitter( {
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
argumentTypes: [ { valueType: window.Event } ],
phetioType: EmitterIO( [
{ name: 'event', type: DOMEventIO }
] ),
Expand Down
16 changes: 13 additions & 3 deletions js/input/SimpleDragHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ define( function( require ) {
'use strict';

// modules
var BooleanProperty = require( 'AXON/BooleanProperty' );
var Emitter = require( 'AXON/Emitter' );
var EmitterIO = require( 'AXON/EmitterIO' );
var Vector2IO = require( 'DOT/Vector2IO' );
var VoidIO = require( 'TANDEM/types/VoidIO' );
var BooleanProperty = require( 'AXON/BooleanProperty' );
var Event = require( 'SCENERY/input/Event' );
var inherit = require( 'PHET_CORE/inherit' );
var Mouse = require( 'SCENERY/input/Mouse' );
var PhetioObject = require( 'TANDEM/PhetioObject' );
var scenery = require( 'SCENERY/scenery' );
var Tandem = require( 'TANDEM/Tandem' );
var Touch = require( 'SCENERY/input/Touch' );
var Vector2 = require( 'DOT/Vector2' );
var Vector2IO = require( 'DOT/Vector2IO' );
var VoidIO = require( 'TANDEM/types/VoidIO' );

/**
* @param {Object} [options]
Expand Down Expand Up @@ -96,6 +97,9 @@ define( function( require ) {
// @private
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
argumentTypes: [ { 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' } ] ),
Expand All @@ -110,6 +114,9 @@ define( function( require ) {
this.draggedEmitter = new Emitter( {
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
argumentTypes: [ { valueType: Vector2 }, { 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' },
{
Expand Down Expand Up @@ -146,6 +153,9 @@ define( function( require ) {
// @private
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
argumentTypes: [ { valueType: Vector2 }, { isValidValue: function( value ) { return value === null || value instanceof Event; } } ],
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' } ] ),
Expand Down
3 changes: 3 additions & 0 deletions js/listeners/DragListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ 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 @@ -191,6 +192,8 @@ define( function( require ) {
phetioDocumentation: 'Emits whenever a drag occurs with an EventIO argument.',
phetioReadOnly: options.phetioReadOnly,
phetioEventType: 'user',

argumentTypes: [ { valueType: Event } ],
phetioType: DraggedEmitterIO,
listener: function( event ) {

Expand Down
22 changes: 16 additions & 6 deletions js/listeners/PressListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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' );
Expand All @@ -28,22 +29,19 @@ define( function( require ) {
var scenery = require( 'SCENERY/scenery' );
var Tandem = require( 'TANDEM/Tandem' );
var timer = require( 'PHET_CORE/timer' );
var TypeDef = require( 'AXON/TypeDef' );
var VoidIO = require( 'TANDEM/types/VoidIO' );

// global
var globalID = 0;

var nullOrFunctionPredicate = TypeDef.getNullOrTypeofPredicate( 'function' );

// 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, predicate: TypeDef.getNullOrInstanceOfPredicate( Node ) },
{ name: 'callback', type: VoidIO, predicate: nullOrFunctionPredicate }
{ name: 'targetNode', type: VoidIO },
{ name: 'callback', type: VoidIO }
] );

var ReleasedEmitterIO = EmitterIO( [ { name: 'callback', type: VoidIO, predicate: nullOrFunctionPredicate } ] );
var ReleasedEmitterIO = EmitterIO( [ { name: 'callback', type: VoidIO } ] );

// Factor out to reduce memory footprint, see https://github.com/phetsims/tandem/issues/71
const truePredicate = _.constant( true );
Expand Down Expand Up @@ -225,6 +223,13 @@ define( function( require ) {
phetioReadOnly: options.phetioReadOnly,
phetioFeatured: options.phetioFeatured,
phetioEventType: 'user',

// TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194
argumentTypes: [
{ 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 @@ -239,6 +244,11 @@ define( function( require ) {
phetioReadOnly: options.phetioReadOnly,
phetioFeatured: options.phetioFeatured,
phetioEventType: 'user',

// TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194
argumentTypes: [
{ 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

0 comments on commit 1021233

Please sign in to comment.