Skip to content

Commit

Permalink
prefer Map.forEach to for...of, remove debugging names, #316
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Aug 27, 2020
1 parent e52271c commit d96cb12
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions js/PropertyStateHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,9 @@ class PropertyStateHandler {
* @returns {OrderDependencyMapPair}
*/
getMapPairFromPhases( beforePhase, afterPhase ) {
for ( let i = 0; i < this.mapPairs.length; i++ ) {
const mapPair = this.mapPairs[ i ];
if ( beforePhase === mapPair.beforePhase && afterPhase === mapPair.afterPhase ) {
return mapPair;
}
}
const matchedPairs = this.mapPairs.filter( mapPair => beforePhase === mapPair.beforePhase && afterPhase === mapPair.afterPhase );
assert && assert( matchedPairs.length === 1, 'one and only one map should match the provided phases' );
return matchedPairs[ 0 ];
}

/**
Expand Down Expand Up @@ -187,10 +184,10 @@ class PropertyStateHandler {
// Look through every dependency and make sure the phetioID to remove has been completely removed.
assertSlow && this.mapPairs.forEach( mapPair => {
[ mapPair.beforeMap, mapPair.afterMap ].forEach( map => {
for ( const [ key, valuePhetioIDs ] of map ) {
map.forEach( ( valuePhetioIDs, key ) => {
assertSlow && assertSlow( key !== phetioIDToRemove, 'should not be a key' );
assertSlow && assertSlow( !valuePhetioIDs.has( phetioIDToRemove ), 'should not be in a value list' );
}
} );
} );
} );
}
Expand Down Expand Up @@ -284,9 +281,7 @@ class PropertyStateHandler {
getNumberOfOrderDependencies() {
let count = 0;
this.mapPairs.forEach( mapPair => {
for ( const [ , valueSet ] of mapPair.afterMap ) { // either map would work here.
count += valueSet.size;
}
mapPair.afterMap.forEach( valueSet => { count += valueSet.size; } );
} );
return count;
}
Expand Down Expand Up @@ -416,10 +411,6 @@ class OrderDependencyMapPair {
this.beforeMap.otherMap = this.afterMap;
this.afterMap.otherMap = this.beforeMap;

// Can be helpful while debugging
this.beforeMap.varName = `${beforePhase}Before${afterPhase}Map`;
this.afterMap.varName = `${afterPhase}After${beforePhase}Map`;

this.beforePhase = beforePhase;
this.afterPhase = afterPhase;
}
Expand Down

0 comments on commit d96cb12

Please sign in to comment.