Skip to content

Commit

Permalink
Use Property listener instead of setTimeout, see phetsims/phet-info#59
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Nov 11, 2019
1 parent 0a3aa13 commit 7d773d9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions js/capacitor/PlateChargeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,9 @@ define( require => {
this.parentNode = new Node(); // @private parent node for charges
this.addChild( this.parentNode );

// No disposal required because the capacitor is persistent
// No disposal required because the capacitor exists for the life of the sim
Property.multilink( [
capacitor.plateSizeProperty,
capacitor.plateSeparationProperty, // TODO: Is this needed?
capacitor.plateVoltageProperty, // TODO: Is this needed?
capacitor.plateChargeProperty // TODO: why was this not needed by CLB
], () => self.isVisible() && self.invalidatePaint()
);
Expand Down Expand Up @@ -226,15 +224,20 @@ define( require => {
const x = this.getContactXOrigin() + xOffset + ( column * dx );
const y = 0;
let z = -( gridDepth / 2 ) + ( zMargin / 2 ) + zOffset + ( row * dz );

// #2935, so that single charge is not obscured by wire connected to center of top plate
if ( numberOfCharges === 1 ) {
z -= dz / 6; //#2935, so that single charge is not obscured by wire connected to center of top plate
z -= dz / 6;
}
const centerPosition = this.modelViewTransform.modelToViewXYZ( x, y, z );

// add the signed charge to the grid
this.isPositivelyCharged() ?
addPositiveCharge( centerPosition, context ) :
addNegativeCharge( centerPosition, context, this.orientation );
if ( this.isPositivelyCharged() ) {
addPositiveCharge( centerPosition, context );
}
else {
addNegativeCharge( centerPosition, context, this.orientation );
}
}
}
}
Expand Down

0 comments on commit 7d773d9

Please sign in to comment.