Skip to content

Commit

Permalink
remove emit3(), use emit() instead, #204 #211
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Feb 27, 2019
1 parent cfbac52 commit 439613c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
30 changes: 11 additions & 19 deletions js/Emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,22 @@ define( require => {
// {Array.<Object>|null} - array of "validators" as defined by ValidatorDef.js
validators: EMPTY_ARRAY,

tandem: Tandem.optional,
phetioState: false,
phetioType: EmitterIOWithNoArgs, // subtypes can override with EmitterIO([...]), see EmitterIO.js
// {boolean} @deprecated, only to support legacy emit1, emit2, emit3 calls.
validationEnabled: true,

// {function|null} [first] optional listener which will be added as the first listener.
// Can be removed via removeListener.
first: null,

// {function|null} [last] optional listener which will be added as the last listener.
// Can be removed via removeListener.
last: null
last: null,

// phet-io
tandem: Tandem.optional,
phetioState: false,
phetioType: EmitterIOWithNoArgs // subtypes can override with EmitterIO([...]), see EmitterIO.js

}, options );

assert && assert( !options.hasOwnProperty( 'listener' ), 'listener option no longer supported, please use first' );
Expand Down Expand Up @@ -78,8 +83,8 @@ define( require => {
// @private - Note: one test indicates stripping this out via assert && in builds may save around 300kb heap
this.validators = options.validators;

// @private - short circuit for emit1, emit2, emit3. Can be removed when those are gone.
this.validationEnabled = true;
// @private - opt out of validation. Can be removed when deprecated emit functions are gone.
this.validationEnabled = options.validationEnabled;

if ( assert ) {

Expand Down Expand Up @@ -300,19 +305,6 @@ define( require => {
this.emit( arg0, arg1 );
}

/**
* Emits a single event with three arguments.
* @param {*} arg0
* @param {*} arg1
* @param {*} arg2
* @public
* @deprecated - please use emit()
*/
emit3( arg0, arg1, arg2 ) {
this.validationEnabled = false; // Disable validation until emit() is used properly
this.emit( arg0, arg1, arg2 );
}

/**
* Checks whether a listener is registered with this Emitter
* @param {function} listener
Expand Down
6 changes: 3 additions & 3 deletions js/EmitterTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ define( require => {

QUnit.test( 'Test emit timing Emitter', assert => {

const e = new Emitter();
const e = new Emitter( { validationEnabled: false } );
let x = 0;
e.addListener( () => {x++;} );
e.addListener( () => {x++;} );
Expand All @@ -78,7 +78,7 @@ define( require => {

assert.ok( x === 5, 'fired all listeners' );

const e1 = new Emitter();
const e1 = new Emitter( { validationEnabled: false } );
e1.addListener( () => {} );

const testEmitter = ( e, numberOfLoopings ) => {
Expand All @@ -87,7 +87,7 @@ define( require => {

for ( let i = 0; i < numberOfLoopings; i++ ) {
// e.emit();
e.emit3( 'blarg', 'fdsa', 344738291043 );
e.emit( 'blarg', 'fdsa', 344738291043 );
}
const end = Date.now();
const totalTime = end - start;
Expand Down
6 changes: 3 additions & 3 deletions js/Property.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ define( require => {

// @private (unit-tests) - emit1 is called when the value changes (or on link)
// Also used in ShapePlacementBoard.js at the moment
this.changedEmitter = new Emitter();
this.changedEmitter = new Emitter( { validationEnabled: false } );

// @private whether we are in the process of notifying listeners
this.notifying = false;
Expand Down Expand Up @@ -242,7 +242,7 @@ define( require => {
assert && assert( !this.notifying || this.reentrant,
'reentry detected, value=' + this.get() + ', oldValue=' + oldValue );
this.notifying = true;
this.changedEmitter.emit3( this.get(), oldValue, this );
this.changedEmitter.emit( this.get(), oldValue, this );
this.notifying = false;

this.isPhetioInstrumented() && this.phetioEndEvent();
Expand All @@ -257,7 +257,7 @@ define( require => {
* @public
*/
notifyListenersStatic() {
this.changedEmitter.emit3( this.get(), undefined, this );
this.changedEmitter.emit( this.get(), undefined, this );
}

/**
Expand Down

0 comments on commit 439613c

Please sign in to comment.