From 81f83e0845088ba9462a37331992c863c25a9dfa Mon Sep 17 00:00:00 2001 From: zepumph Date: Wed, 27 Feb 2019 13:46:15 -0900 Subject: [PATCH] remove emit1(), use emit() instead, https://github.com/phetsims/axon/issues/211 --- js/model/CollectionBox.js | 11 ++++++----- js/model/CollectionList.js | 9 +++++---- js/model/Kit.js | 8 ++++---- js/model/KitCollection.js | 2 +- js/screens/BAMScreen.js | 4 ++-- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/js/model/CollectionBox.js b/js/model/CollectionBox.js index 859b9fb5..81357c3c 100644 --- a/js/model/CollectionBox.js +++ b/js/model/CollectionBox.js @@ -25,9 +25,9 @@ define( function( require ) { this.quantityProperty = new NumberProperty( 0 ); // @public {Emitter} - Called with a single molecule parameter - this.addedMoleculeEmitter = new Emitter(); - this.removedMoleculeEmitter = new Emitter(); - this.acceptedMoleculeCreationEmitter = new Emitter(); // triggered from KitCollection + this.addedMoleculeEmitter = new Emitter( { validationEnabled: false } ); + this.removedMoleculeEmitter = new Emitter( { validationEnabled: false } ); + this.acceptedMoleculeCreationEmitter = new Emitter( { validationEnabled: false } ); // triggered from KitCollection var self = this; this.moleculeType = moleculeType; @@ -41,6 +41,7 @@ define( function( require ) { } } ); } + buildAMolecule.register( 'CollectionBox', CollectionBox ); inherit( Object, CollectionBox, { @@ -75,14 +76,14 @@ define( function( require ) { this.quantityProperty.value++; this.molecules.push( molecule ); - this.addedMoleculeEmitter.emit1( molecule ); + this.addedMoleculeEmitter.emit( molecule ); }, removeMolecule: function( molecule ) { this.quantityProperty.value--; this.molecules.splice( this.molecules.indexOf( molecule ), 1 ); // TODO: remove() instead of splice() - this.removedMoleculeEmitter.emit1( molecule ); + this.removedMoleculeEmitter.emit( molecule ); }, clear: function() { diff --git a/js/model/CollectionList.js b/js/model/CollectionList.js index 5cef3466..9b1dfbba 100644 --- a/js/model/CollectionList.js +++ b/js/model/CollectionList.js @@ -25,8 +25,8 @@ define( function( require ) { this.currentCollectionProperty = new Property( firstCollection ); // @public {Emitter} - Fires single parameter of {KitCollection} - this.addedCollectionEmitter = new Emitter(); - this.removedCollectionEmitter = new Emitter(); + this.addedCollectionEmitter = new Emitter( { validationEnabled: false } ); + this.removedCollectionEmitter = new Emitter( { validationEnabled: false } ); this.layoutBounds = layoutBounds; this.tickEmitter = tickEmitter; @@ -34,6 +34,7 @@ define( function( require ) { this.currentIndex = 0; this.addCollection( firstCollection ); } + buildAMolecule.register( 'CollectionList', CollectionList ); inherit( Object, CollectionList, { @@ -46,7 +47,7 @@ define( function( require ) { this.collections.push( collection ); // TODO: notifications before changing current collection - is this desired? may be - this.addedCollectionEmitter.emit1( collection ); + this.addedCollectionEmitter.emit( collection ); // switch to collection this.currentIndex = this.collections.indexOf( collection ); @@ -57,7 +58,7 @@ define( function( require ) { assert && assert( this.currentCollectionProperty.value !== collection ); this.collections.splice( this.collections.indexOf( collection ), 1 ); // TODO: use remove() instead of splice() - this.removedCollectionEmitter.emit1( collection ); + this.removedCollectionEmitter.emit( collection ); }, reset: function() { diff --git a/js/model/Kit.js b/js/model/Kit.js index 14f2aac2..4a300011 100644 --- a/js/model/Kit.js +++ b/js/model/Kit.js @@ -32,8 +32,8 @@ define( function( require ) { this.hasMoleculesInBoxesProperty = new BooleanProperty( false ); // we record this so we know when the "reset kit" should be shown // @public {Emitter} - Called with a single parameter molecule - this.addedMoleculeEmitter = new Emitter(); - this.removedMoleculeEmitter = new Emitter(); + this.addedMoleculeEmitter = new Emitter( { validationEnabled: false } ); + this.removedMoleculeEmitter = new Emitter( { validationEnabled: false } ); this.buckets = buckets; this.layoutBounds = layoutBounds; @@ -320,13 +320,13 @@ define( function( require ) { addMolecule: function( molecule ) { this.molecules.push( molecule ); - this.addedMoleculeEmitter.emit1( molecule ); + this.addedMoleculeEmitter.emit( molecule ); }, removeMolecule: function( molecule ) { this.molecules.splice( this.molecules.indexOf( molecule ), 1 ); // TODO: remove() instead of splice() - this.removedMoleculeEmitter.emit1( molecule ); + this.removedMoleculeEmitter.emit( molecule ); }, /** diff --git a/js/model/KitCollection.js b/js/model/KitCollection.js index 8d01b9b6..5a5aaef0 100644 --- a/js/model/KitCollection.js +++ b/js/model/KitCollection.js @@ -89,7 +89,7 @@ define( function( require ) { kit.addedMoleculeEmitter.addListener( function( molecule ) { _.each( self.collectionBoxes, function( box ) { if ( box.willAllowMoleculeDrop( molecule ) ) { - box.acceptedMoleculeCreationEmitter.emit1( molecule ); + box.acceptedMoleculeCreationEmitter.emit( molecule ); } } ); } ); diff --git a/js/screens/BAMScreen.js b/js/screens/BAMScreen.js index 9dac77c8..6c2cda1e 100644 --- a/js/screens/BAMScreen.js +++ b/js/screens/BAMScreen.js @@ -30,10 +30,10 @@ define( function( require ) { }, options ); var createModel = function() { - var tickEmitter = new Emitter( { validValues: [ 'number' ] } ); // emits 1 parameter, timeElapsed + var tickEmitter = new Emitter( { validators: [ { valueType: 'number' } ] } ); // emits 1 parameter, timeElapsed var model = new CollectionList( createInitialKitCollection( layoutBounds, tickEmitter ), layoutBounds, tickEmitter ); model.step = function step( timeElapsed ) { - tickEmitter.emit1( timeElapsed ); + tickEmitter.emit( timeElapsed ); }; model.generateKitCollection = function generateKitCollection() { return createKitCollection( layoutBounds, tickEmitter );