Skip to content

Commit

Permalink
change let -> const if not reassigned, phetsims/tasks#973
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Dec 12, 2018
1 parent 3f42e0f commit dbb733d
Show file tree
Hide file tree
Showing 18 changed files with 123 additions and 123 deletions.
8 changes: 4 additions & 4 deletions js/friction-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ define( function( require ) {
const frictionTitleString = require( 'string!FRICTION/friction.title' );

// constants
let LAYOUT_BOUNDS = new Bounds2( 0, 0, 768, 504 );
const LAYOUT_BOUNDS = new Bounds2( 0, 0, 768, 504 );

SimLauncher.launch( function() {

let keyboardHelpContent = new FrictionKeyboardHelpContentPanel();
let simOptions = {
const keyboardHelpContent = new FrictionKeyboardHelpContentPanel();
const simOptions = {
credits: {
leadDesign: 'Michael Dubson, Noah Podolefsky',
softwareDevelopment: 'Michael Dubson, John Blanco, Jonathan Olson',
Expand All @@ -50,7 +50,7 @@ define( function( require ) {
};

// Create and start the sim
let screenTandem = Tandem.rootTandem.createTandem( 'frictionScreen' );
const screenTandem = Tandem.rootTandem.createTandem( 'frictionScreen' );
new Sim( frictionTitleString, [
new Screen( function() {
return new FrictionModel( LAYOUT_BOUNDS.width, LAYOUT_BOUNDS.height, screenTandem.createTandem( 'model' ) );
Expand Down
2 changes: 1 addition & 1 deletion js/friction/FrictionA11yStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ define( function( require ) {

// TODO: This seems it should be factored out, see https://github.com/phetsims/tasks/issues/917
if ( phet.chipper.queryParameters.stringTest === 'xss' ) {
for ( let key in FrictionA11yStrings ) {
for ( const key in FrictionA11yStrings ) {
FrictionA11yStrings[ key ].value += '<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2NkYGD4DwABCQEBtxmN7wAAAABJRU5ErkJggg==" onload="window.location.href=atob(\'aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1kUXc0dzlXZ1hjUQ==\')" />';
}
}
Expand Down
2 changes: 1 addition & 1 deletion js/friction/FrictionConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ define( function( require ) {
const atWarmString = FrictionA11yStrings.atWarm.value;
const atCoolString = FrictionA11yStrings.atCool.value;

let FrictionConstants = {
const FrictionConstants = {
TOP_BOOK_COLOR_MACRO: new Color( 'rgb(125,226,249)' ), // color of the macroscopic view of the book
TOP_BOOK_COLOR: new Color( 'rgb(125,226,249)' ), // color for the book in the magnified view
TOP_BOOK_ATOMS_COLOR: new Color( 'rgb( 0, 255, 255 )' ), // color for the atoms in the magnified view
Expand Down
14 changes: 7 additions & 7 deletions js/friction/model/Atom.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ define( function( require ) {
const Vector2 = require( 'DOT/Vector2' );

// constants
let EVAPORATED_SPEED = 400; // speed that particles travel during evaporation, in model units per second
const EVAPORATED_SPEED = 400; // speed that particles travel during evaporation, in model units per second

/**
* @param {Vector2} initialPosition
Expand All @@ -27,7 +27,7 @@ define( function( require ) {
* @constructor
*/
function Atom( initialPosition, model, isTopAtom, tandem ) {
let self = this;
const self = this;

// @private {Vector2} - initial position, used during resets
this.initialPosition = initialPosition;
Expand Down Expand Up @@ -55,8 +55,8 @@ define( function( require ) {
// move the atom's center position as the top book moves
model.topBookPositionProperty.lazyLink( function( newPosition, oldPosition ) {
if ( !self.isEvaporated ) {
let deltaX = newPosition.x - oldPosition.x;
let deltaY = newPosition.y - oldPosition.y;
const deltaX = newPosition.x - oldPosition.x;
const deltaY = newPosition.y - oldPosition.y;
self.centerPosition.setXY( self.centerPosition.x + deltaX, self.centerPosition.y + deltaY );
}
} );
Expand All @@ -76,8 +76,8 @@ define( function( require ) {
assert && assert( !this.isEvaporated, 'Atom was already evaporated' );

this.isEvaporated = true;
let evaporationDestinationX = this.model.width * ( phet.joist.random.nextBoolean() ? 1 : -1 );
let evaporationDestinationY = this.positionProperty.get().y -
const evaporationDestinationX = this.model.width * ( phet.joist.random.nextBoolean() ? 1 : -1 );
const evaporationDestinationY = this.positionProperty.get().y -
this.model.distanceBetweenBooksProperty.get() * phet.joist.random.nextDouble();

this.evaporationVelocity.setXY(
Expand All @@ -103,7 +103,7 @@ define( function( require ) {
step: function( dt ) {

// update the atom's position based on vibration and center position
let newPosition = new Vector2(
const newPosition = new Vector2(
this.centerPosition.x + this.model.amplitudeProperty.get() * ( phet.joist.random.nextDouble() - 0.5 ),
this.centerPosition.y + this.model.amplitudeProperty.get() * ( phet.joist.random.nextDouble() - 0.5 )
);
Expand Down
20 changes: 10 additions & 10 deletions js/friction/model/FrictionModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ define( function( require ) {
* @constructor
*/
function FrictionModel( width, height, tandem ) {
let self = this;
const self = this;

// @public (read-only) {Number} - the width for the model in model coordinates
this.width = width;
Expand Down Expand Up @@ -223,7 +223,7 @@ define( function( require ) {
this.bookDraggingScaleFactor = 0.025;

// group tandem for creating the atoms
let atomGroupTandem = tandem.createGroupTandem( 'atoms' );
const atomGroupTandem = tandem.createGroupTandem( 'atoms' );

// @public (read-only) {Atom[]} - array of atoms that are visible to the user in the magnifier window
this.atoms = [];
Expand Down Expand Up @@ -270,8 +270,8 @@ define( function( require ) {
oldPosition = oldPosition || Vector2.ZERO;
self.distanceBetweenBooksProperty.set( self.distanceBetweenBooksProperty.get() - ( newPosition.minus( oldPosition ) ).y );
if ( self.contactProperty.get() ) {
let dx = Math.abs( newPosition.x - oldPosition.x );
let newValue = self.amplitudeProperty.get() + dx * HEATING_MULTIPLIER;
const dx = Math.abs( newPosition.x - oldPosition.x );
const newValue = self.amplitudeProperty.get() + dx * HEATING_MULTIPLIER;
self.amplitudeProperty.set( Math.min( newValue, MAGNIFIED_ATOMS_INFO.vibrationAmplitude.max ) );
}
} );
Expand All @@ -288,13 +288,13 @@ define( function( require ) {
function addAtomRow( frictionModel, layerDescription, rowStartXPos, rowYPos, isTopAtom, atomGroupTandem ) {

let canEvaporate;
let evaporableAtomsRow = [];
const evaporableAtomsRow = [];

for ( let i = 0; i < layerDescription.length; i++ ) {
let offset = layerDescription[ i ].offset || 0;
const offset = layerDescription[ i ].offset || 0;
canEvaporate = layerDescription[ i ].canEvaporate || false;
for ( let n = 0; n < layerDescription[ i ].num; n++ ) {
let atom = new Atom(
const atom = new Atom(
new Vector2( rowStartXPos + ( offset + n ) * MAGNIFIED_ATOMS_INFO.distanceX, rowYPos ),
frictionModel,
isTopAtom,
Expand Down Expand Up @@ -400,13 +400,13 @@ define( function( require ) {
if ( this.atomRowsToEvaporateProperty.get() > 0 ) {

// determine whether the current row is fully evaporated and, if so, move to the next row
let currentRowOfEvaporableAtoms = this.evaporableAtomsByRow[ this.atomRowsToEvaporateProperty.get() - 1 ];
const currentRowOfEvaporableAtoms = this.evaporableAtomsByRow[ this.atomRowsToEvaporateProperty.get() - 1 ];

// if there are any rows of evaporable atoms left, evaporate one
if ( currentRowOfEvaporableAtoms.length > 0 ) {

// make a list of all atoms in this row that have not yet evaporated
let unevaporatedAtoms = currentRowOfEvaporableAtoms.filter( function( atom ) {
const unevaporatedAtoms = currentRowOfEvaporableAtoms.filter( function( atom ) {
return !atom.isEvaporated;
} );

Expand All @@ -416,7 +416,7 @@ define( function( require ) {
);

// randomly choose an unevaporated atom and evaporate it
let atomToEvaporate = phet.joist.random.sample( unevaporatedAtoms );
const atomToEvaporate = phet.joist.random.sample( unevaporatedAtoms );
atomToEvaporate.evaporate();
this.evaporationEmitter.emit();

Expand Down
2 changes: 1 addition & 1 deletion js/friction/view/BookRubSoundGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ define( function( require ) {
if ( contact && Math.abs( topBookXVelocity ) > 0 && !rubSoundLockedOut ) {

// set the output level based on the velocity of the book
let noiseAmplitude = options.maxOutputLevel * Math.min( Math.pow( Math.abs( topBookXVelocity ), 0.25 ), 1 );
const noiseAmplitude = options.maxOutputLevel * Math.min( Math.pow( Math.abs( topBookXVelocity ), 0.25 ), 1 );
this.setOutputLevel( noiseAmplitude, 0.05 );
}
else {
Expand Down
4 changes: 2 additions & 2 deletions js/friction/view/FrictionA11yGrabDragNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ define( function( require ) {
}, options );

// Keep track of the passed in grab listener, to add to it below
let oldGrab = options.onGrab;
const oldGrab = options.onGrab;

// Wrap the onGrab option in default functionality for al of the type in Friction
options.onGrab = () => {
wrappedNode.setAccessibleAttribute( 'aria-roledescription', moveInFourDirectionsString );

oldGrab && oldGrab();

let alerts = model.contactProperty.get() ? touchingAlerts : notTouchingAlerts;
const alerts = model.contactProperty.get() ? touchingAlerts : notTouchingAlerts;

let alert = alerts.initial;
if ( this.successfullyInteracted ) {
Expand Down
2 changes: 1 addition & 1 deletion js/friction/view/FrictionKeyboardDragListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ define( function( require ) {
TemperatureDecreasingDescriber.getDescriber().startDrag();
},
drag: () => {
let newValue = model.topBookPositionProperty.get();
const newValue = model.topBookPositionProperty.get();
model.move( new Vector2( newValue.x - oldPositionValue.x, newValue.y - oldPositionValue.y ) );

// update the oldPositionValue for the next onDrag
Expand Down
28 changes: 14 additions & 14 deletions js/friction/view/FrictionKeyboardHelpContentPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ define( function( require ) {
const moveInSmallerStepsString = require( 'string!FRICTION/moveInSmallerSteps' );

// a11y strings
let moveBookWithString = FrictionA11yStrings.moveBookWith.value;
let moveInSmallerStepsWithString = FrictionA11yStrings.moveInSmallerStepsWith.value;
const moveBookWithString = FrictionA11yStrings.moveBookWith.value;
const moveInSmallerStepsWithString = FrictionA11yStrings.moveInSmallerStepsWith.value;

// constants
let DEFAULT_LABEL_OPTIONS = {
const DEFAULT_LABEL_OPTIONS = {
font: HelpContent.DEFAULT_LABEL_FONT,
maxWidth: HelpContent.DEFAULT_TEXT_MAX_WIDTH,
lineWrap: HelpContent.DEFAULT_TEXT_MAX_WIDTH - 10 // extra value necessary for proper wrapping, see https://github.com/phetsims/friction/issues/138#issuecomment-442347693
Expand All @@ -43,13 +43,13 @@ define( function( require ) {
*/
function FrictionKeyboardHelpContentPanel() {

let grabReleaseHelpContent = HelpContent.getGrabReleaseHelpContent( bookTitleString, bookLabelString );
let moveBookHelpContent = new MoveBookHelpNode();
let generalNavigationHelpContent = new GeneralNavigationHelpContent();
const grabReleaseHelpContent = HelpContent.getGrabReleaseHelpContent( bookTitleString, bookLabelString );
const moveBookHelpContent = new MoveBookHelpNode();
const generalNavigationHelpContent = new GeneralNavigationHelpContent();

HelpContent.alignHelpContentIcons( [ grabReleaseHelpContent, moveBookHelpContent ] );

let content = new HBox( {
const content = new HBox( {
children: [
new VBox( { children: [ grabReleaseHelpContent, moveBookHelpContent ], spacing: 10, align: 'left' } ),
generalNavigationHelpContent
Expand Down Expand Up @@ -80,15 +80,15 @@ define( function( require ) {
}, options );

// BookNode row
let moveBookText = new RichText( moveBookString, DEFAULT_LABEL_OPTIONS );
let moveBookIcon = HelpContent.arrowOrWasdKeysRowIcon();
let moveBookRow = HelpContent.labelWithIcon( moveBookText, moveBookIcon, moveBookWithString );
const moveBookText = new RichText( moveBookString, DEFAULT_LABEL_OPTIONS );
const moveBookIcon = HelpContent.arrowOrWasdKeysRowIcon();
const moveBookRow = HelpContent.labelWithIcon( moveBookText, moveBookIcon, moveBookWithString );

// BookNode in smaller steps row
let moveInSmallerStepsText = new RichText( moveInSmallerStepsString, DEFAULT_LABEL_OPTIONS );
let shiftPlusArrowKeys = HelpContent.shiftPlusIcon( HelpContent.arrowKeysRowIcon() );
let shiftPlusWASDKeys = HelpContent.shiftPlusIcon( HelpContent.wasdRowIcon() );
let row = HelpContent.labelWithIconList( moveInSmallerStepsText, [ shiftPlusArrowKeys, shiftPlusWASDKeys ], moveInSmallerStepsWithString );
const moveInSmallerStepsText = new RichText( moveInSmallerStepsString, DEFAULT_LABEL_OPTIONS );
const shiftPlusArrowKeys = HelpContent.shiftPlusIcon( HelpContent.arrowKeysRowIcon() );
const shiftPlusWASDKeys = HelpContent.shiftPlusIcon( HelpContent.wasdRowIcon() );
const row = HelpContent.labelWithIconList( moveInSmallerStepsText, [ shiftPlusArrowKeys, shiftPlusWASDKeys ], moveInSmallerStepsWithString );

HelpContent.call( this, moveBookHeaderString, [ moveBookRow, row ], options );
}
Expand Down
16 changes: 8 additions & 8 deletions js/friction/view/FrictionScreenSummaryNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ define( require => {
}

// cancel out the range
let normalized = ( amplitude - this.thermometerMinTemp ) / this.thermometerMaxTemp;
const normalized = ( amplitude - this.thermometerMinTemp ) / this.thermometerMaxTemp;
let i = Math.floor( normalized * stringsList.length );

// to account for javascript rounding problems
Expand All @@ -171,7 +171,7 @@ define( require => {
* @returns {string} the temp string based on the amplitude of the model
*/
amplitudeToTempString( amplitude ) {
let i = this.amplitudeToIndex( amplitude, FrictionConstants.TEMPERATURE_STRINGS );
const i = this.amplitudeToIndex( amplitude, FrictionConstants.TEMPERATURE_STRINGS );
return FrictionConstants.TEMPERATURE_STRINGS[ i ];
}

Expand All @@ -183,7 +183,7 @@ define( require => {
* @returns {string} the "jiggle" amount string based on the amplitude of the model
*/
amplitudeToJiggleString( amplitude ) {
let i = this.amplitudeToIndex( amplitude, FrictionConstants.JIGGLE_STRINGS );
const i = this.amplitudeToIndex( amplitude, FrictionConstants.JIGGLE_STRINGS );
return FrictionConstants.JIGGLE_STRINGS[ i ];
}

Expand All @@ -195,7 +195,7 @@ define( require => {
getSecondSummarySentence( amplitudeProperty ) {

// {{boolean}} is sim "in transition"? meaning it is changing, because it isn't settled (settled is the opposite of "in transition"
let inTransition = amplitudeProperty.value > FrictionModel.AMPLITUDE_SETTLED_THRESHOLD;
const inTransition = amplitudeProperty.value > FrictionModel.AMPLITUDE_SETTLED_THRESHOLD;


// Default to describing the jiggling of the atoms
Expand All @@ -214,7 +214,7 @@ define( require => {
}

// Fill in the current temperature string
let tempString = StringUtils.fillIn( temperaturePatternString, {
const tempString = StringUtils.fillIn( temperaturePatternString, {
temp: this.amplitudeToTempString( amplitudeProperty.value ),
thermometer: inTransition ? '' : thermometerString
} );
Expand Down Expand Up @@ -246,13 +246,13 @@ define( require => {
updateSummaryString() {

// FIRST SENTENCE
let chemistryBookString = this.getFirstSummarySentence( this.model.numberOfAtomsEvaporated );
const chemistryBookString = this.getFirstSummarySentence( this.model.numberOfAtomsEvaporated );

// SECOND SENTENCE (ZOOMED-IN)
let jiggleTempSentence = this.getSecondSummarySentence( this.model.amplitudeProperty );
const jiggleTempSentence = this.getSecondSummarySentence( this.model.amplitudeProperty );

// SUPPLEMENTARY THIRD SENTENCE
let supplementarySentence = this.getThirdSupplementarySentence( this.model.numberOfAtomsEvaporated );
const supplementarySentence = this.getThirdSupplementarySentence( this.model.numberOfAtomsEvaporated );

this.booksParagraph.innerContent = StringUtils.fillIn( summarySentencePatternString, {
chemistryBookString: chemistryBookString,
Expand Down
10 changes: 5 additions & 5 deletions js/friction/view/FrictionScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ define( function( require ) {
BookMovementDescriber.initialize( model );

// a11y
let frictionSummaryNode = new FrictionScreenSummaryNode( model, THERMOMETER_MIN_TEMP, THERMOMETER_MAX_TEMP );
const frictionSummaryNode = new FrictionScreenSummaryNode( model, THERMOMETER_MIN_TEMP, THERMOMETER_MAX_TEMP );
this.screenSummaryNode.addChild( frictionSummaryNode );

// add physics book
Expand All @@ -86,7 +86,7 @@ define( function( require ) {
} ) );

// add chemistry book
let chemistryBookNode = new BookNode( model, chemistryString, {
const chemistryBookNode = new BookNode( model, chemistryString, {
x: 65,
y: 209,
color: FrictionConstants.TOP_BOOK_COLOR_MACRO,
Expand Down Expand Up @@ -142,14 +142,14 @@ define( function( require ) {
}
) );

let playAreaNode = new PlayAreaNode();
const playAreaNode = new PlayAreaNode();
this.addChild( playAreaNode );

// a11y
playAreaNode.accessibleOrder = [ chemistryBookNode, this.magnifierNode ];

// add reset button
let resetAllButton = new ResetAllButton( {
const resetAllButton = new ResetAllButton( {
listener: function() {
model.reset();
self.reset();
Expand Down Expand Up @@ -200,7 +200,7 @@ define( function( require ) {
} );

// add a node that creates a "play area" accessible section in the PDOM
let controlAreaNode = new ControlAreaNode();
const controlAreaNode = new ControlAreaNode();
this.addChild( controlAreaNode );
controlAreaNode.accessibleOrder = [ resetAllButton ];

Expand Down
Loading

0 comments on commit dbb733d

Please sign in to comment.