Skip to content

Commit

Permalink
Changed Property to Emitter, see #64
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Feb 13, 2018
1 parent 778d3ca commit daa1412
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
16 changes: 6 additions & 10 deletions js/friction/model/FrictionModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ define( function( require ) {
var MAX_X_DISPLACEMENT = 600; // max allowed distance from center x
var MIN_Y_POSITION = -70; // empirically determined such that top book can't be completely dragged out of frame

// TODO: rename amplitude => temperature throughout the project? Or maybe not?

// atoms of top book (contains 5 rows: 4 of them can evaporate, 1 - can not)
var topAtomsStructure = [
/**
Expand Down Expand Up @@ -157,17 +155,17 @@ define( function( require ) {
}
};

// TODO: docs
// TODO: annotation (and readonly)
// @public (phet-io) Instrumented so that PhET-iO clients can get a message when an atom evaporates
this.evaporationEmitter = new Emitter( {
tandem: tandem.createTandem( 'evaporationEmitter' )
} );

// @public - array of all AtomNodes which able to evaporate, need for resetting game
// TODO: Why does the model have arrays of Nodes?
this.toEvaporateSample = [];

// @public - current set of AtomNodes which may evaporate, but not yet evaporated (generally the lowest row in the
// top book)
// @public (read-only) - current set of AtomNodes which may evaporate, but not yet evaporated (generally the lowest
// row in the top book)
// TODO: it seems incorrect to have a list of Nodes in the model
this.toEvaporate = [];

Expand Down Expand Up @@ -202,7 +200,7 @@ define( function( require ) {

// @public (read-only)- update every step
// TODO: Use an emitter here
this.newStepProperty = new Property( false );
this.stepEmitter = new Emitter();

// @public (read-only) - drag and drop book coordinates conversion coefficient
this.dndScale = 0.025; // TODO: better name
Expand Down Expand Up @@ -248,8 +246,7 @@ define( function( require ) {
return;
}

// TODO: what is happening here?
this.newStepProperty.set( !this.newStepProperty.get() );
this.stepEmitter.emit();

// Cool the atoms.
var amplitude = this.amplitudeProperty.get() - this.scheduledEvaporationAmount;
Expand All @@ -271,7 +268,6 @@ define( function( require ) {
this.atomRowsToEvaporateProperty.reset();
this.contactProperty.reset();
this.hintProperty.reset();
this.newStepProperty.reset();
this.init();
},

Expand Down
10 changes: 5 additions & 5 deletions js/friction/view/magnifier/AtomNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ define( function( require ) {
} );

// update atom's position based on vibration and center position
model.newStepProperty.link( function() {
model.stepEmitter.addListener( function() {
self.currentX = self.x0 + model.amplitudeProperty.get() * ( phet.joist.random.nextDouble() - 0.5 );
self.currentY = self.y0 + model.amplitudeProperty.get() * ( phet.joist.random.nextDouble() - 0.5 );
} );
Expand Down Expand Up @@ -135,14 +135,14 @@ define( function( require ) {

// TODO: memory leak for atoms moving to the left?
if ( self.x0 > 4 * self.model.width ) {
self.model.newStepProperty.unlink( self.handler );
self.model.stepEmitter.removeListener( self.handler );
self.setVisible( false );
}
};

// TODO: why is this linking every time it evaporates? Can it only evaporate once?
// TODO: does this file need a dispose function?
this.model.newStepProperty.link( self.handler );
this.model.stepEmitter.addListener( self.handler );
},

/**
Expand All @@ -162,8 +162,8 @@ define( function( require ) {
this.y0 = this.options.y;

// handler may have been unlinked by itself (see above), so check that we're still registered
if ( this.model.newStepProperty.hasListener( this.handler ) ) {
this.model.newStepProperty.unlink( this.handler );
if ( this.model.stepEmitter.hasListener( this.handler ) ) {
this.model.stepEmitter.removeListener( this.handler );
}
this.setVisible( true );
this.isEvaporated = false;
Expand Down

0 comments on commit daa1412

Please sign in to comment.