Skip to content

Commit

Permalink
Some review changes, see #29
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Jan 4, 2019
1 parent afb82e6 commit 4afbd45
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 30 deletions.
2 changes: 2 additions & 0 deletions js/building/model/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ define( require => {

// Keep our hover target up-to-date
// REVIEW: Does this need an unlink?
// REVIEW*: I don't believe so. Since we "own" the Property, any reference to this is going to also reference the
// REVIEW*: Property (and vice versa).
this.hoveringTargetProperty.lazyLink( ( newTarget, oldTarget ) => {
oldTarget && oldTarget.hoveringGroups.remove( this );
newTarget && newTarget.hoveringGroups.push( this );
Expand Down
3 changes: 1 addition & 2 deletions js/building/model/NumberGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ define( require => {
*/
updateAllowedSpots() {
if ( this.isMixedNumber ) {
// REVIEW: 'let' instead of 'var'?
var range = this.activeNumberRangeProperty.value;
const range = this.activeNumberRangeProperty.value;

this.numeratorSpot.showNotAllowedProperty.value = range === null ? false : !this.canPlaceNumberInSpot( range.min, this.numeratorSpot );
this.denominatorSpot.showNotAllowedProperty.value = range === null ? false : !this.canPlaceNumberInSpot( range.max, this.denominatorSpot );
Expand Down
7 changes: 3 additions & 4 deletions js/building/model/NumberSpot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
define( require => {
'use strict';

//REVIEW: `const` instead of `var`?
// modules
var BooleanProperty = require( 'AXON/BooleanProperty' );
var fractionsCommon = require( 'FRACTIONS_COMMON/fractionsCommon' );
var Property = require( 'AXON/Property' );
const BooleanProperty = require( 'AXON/BooleanProperty' );
const fractionsCommon = require( 'FRACTIONS_COMMON/fractionsCommon' );
const Property = require( 'AXON/Property' );

class NumberSpot {
/**
Expand Down
1 change: 1 addition & 0 deletions js/building/model/NumberStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ define( require => {
*/
// REVIEW: Could you respond in #29 about this notation/syntax "isMutable = true" in the constructor arguements?
// REVIEW: If 'isMutable' is always true why is it a parameter and not a const?
// REVIEW*: It's a default value for a parameter (that it gets if not provided). BuildingLabModel provides false.
constructor( number, layoutQuantity, isMutable = true ) {
super( BuildingType.NUMBER, layoutQuantity, isMutable );

Expand Down
3 changes: 1 addition & 2 deletions js/building/model/ShapeContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ define( require => {
const Util = require( 'DOT/Util' );
const Vector2 = require( 'DOT/Vector2' );

// REVIEW: Please add doc about how this is used.
const scratchVector = new Vector2();
const scratchVector = new Vector2(); // Used as a shared Vector2 so that we can avoid allocating vectors dynamically.

class ShapeContainer {
/**
Expand Down
6 changes: 2 additions & 4 deletions js/building/model/ShapeGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ define( require => {
* @returns {boolean}
*/
hasAnyPieces() {
// REVIEW: Are we still using 'var' in for loops?
for ( var i = 0; i < this.shapeContainers.length; i++ ) {
for ( let i = 0; i < this.shapeContainers.length; i++ ) {
if ( this.shapeContainers.get( i ).shapePieces.length ) {
return true;
}
Expand All @@ -121,8 +120,7 @@ define( require => {
* @public
*/
increaseContainerCount() {
// REVIEW: 'let' instead of 'var'?
var offset = new Vector2( this.shapeContainers.length * ( FractionsCommonConstants.SHAPE_SIZE + FractionsCommonConstants.SHAPE_CONTAINER_PADDING ), 0 );
const offset = new Vector2( this.shapeContainers.length * ( FractionsCommonConstants.SHAPE_SIZE + FractionsCommonConstants.SHAPE_CONTAINER_PADDING ), 0 );
this.shapeContainers.push( new ShapeContainer( this, this.partitionDenominatorProperty, this.representation, this.changedEmitter, offset ) );
}

Expand Down
23 changes: 12 additions & 11 deletions js/building/model/ShapePiece.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ define( require => {
const NumberProperty = require( 'AXON/NumberProperty' );
const Property = require( 'AXON/Property' );
const Vector2 = require( 'DOT/Vector2' );
// REVIEW: Added doc about how this is used would be helpful

// globals
// Used for unique identifiers for every ShapePiece (so we can efficiently store a map from piece ID to other objects.
let globalID = 0;

class ShapePiece {
Expand Down Expand Up @@ -88,6 +90,7 @@ define( require => {
this.trueTargetRotation = 0;

// REVIEW: Does this property need an unlink?
// REVIEW*: Shouldn't need it, since they have the same lifetimes.
this.isUserControlledProperty.link( isUserControlled => {
if ( isUserControlled ) {
this.shadowProperty.value = 1;
Expand All @@ -96,16 +99,15 @@ define( require => {

// Handle rotational animation towards a target (if any)
// REVIEW: Does this need a dispose?
// REVIEW*: Shouldn't need it, since they have the same lifetimes.
Property.multilink( [ this.isUserControlledProperty, this.targetRotationProperty ], ( isUserControlled, targetRotation ) => {
if ( isUserControlled ) {
// REVIEW: 'let' instead of 'var'
var currentRotation = this.rotationProperty.value;
const currentRotation = this.rotationProperty.value;
this.trueTargetRotation = Animator.modifiedEndAngle( currentRotation, this.targetRotationProperty.value );

// REVIEW: 'let' instead of 'var'
// REVIEW: Documentation for these variables would be helpful, being they are only used below.
var damping = 1;
var force = 50;
// Constants tweaked to give the damped harmonic a pleasing behavior.
const damping = 1;
const force = 50;
this.dampedHarmonicTimeElapsed = 0;
this.dampedHarmonic = new DampedHarmonic( 1, Math.sqrt( 4 * force ) * damping, force, currentRotation - this.trueTargetRotation, this.angularVelocityProperty.value );
}
Expand Down Expand Up @@ -162,12 +164,11 @@ define( require => {
return Vector2.ZERO;
}
else {
// REVIEW: 'let' instead of 'var'
var positiveAngle = fraction.value * 2 * Math.PI;
const positiveAngle = fraction.value * 2 * Math.PI;

// Compute the centroid for a circular sector
var radius = FractionsCommonConstants.SHAPE_SIZE / 2;
var distanceFromCenter = 4 / 3 * radius * Math.sin( positiveAngle / 2 ) / positiveAngle;
const radius = FractionsCommonConstants.SHAPE_SIZE / 2;
const distanceFromCenter = 4 / 3 * radius * Math.sin( positiveAngle / 2 ) / positiveAngle;
return Vector2.createPolar( distanceFromCenter, -positiveAngle / 2 );
}
}
Expand Down
1 change: 1 addition & 0 deletions js/building/view/NumberGroupNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ define( require => {

// Keep the group in the drag bounds (when they change)
// REVIEW: Does this need an unlink?
// REVIEW*: Shouldn't need it, these have the same lifetime.
this.dragBoundsProperty.lazyLink( dragBounds => {
numberGroup.positionProperty.value = dragBounds.closestPointTo( numberGroup.positionProperty.value );
} );
Expand Down
1 change: 1 addition & 0 deletions js/building/view/NumberPieceNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ define( require => {
} );

// REVIEW: Does this need an unlink?
// REVIEW*: Shouldn't need it, the two objects have the same lifetime.
this.dragListener.isUserControlledProperty.link( controlled => {
numberPiece.isUserControlledProperty.value = controlled;
} );
Expand Down
1 change: 1 addition & 0 deletions js/building/view/ShapePieceNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ define( require => {
}
} );
// REVIEW: Does this need an unlink?
// REVIEW*: Shouldn't need it, the two objects have the same lifetime.
this.dragListener.isUserControlledProperty.link( controlled => {
shapePiece.isUserControlledProperty.value = controlled;
} );
Expand Down
13 changes: 6 additions & 7 deletions js/common/FractionsCommonConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
define( require => {
'use strict';

// REVEIW: 'let' instead of 'var'
// modules
var fractionsCommon = require( 'FRACTIONS_COMMON/fractionsCommon' );
var PhetFont = require( 'SCENERY_PHET/PhetFont' );
const fractionsCommon = require( 'FRACTIONS_COMMON/fractionsCommon' );
const PhetFont = require( 'SCENERY_PHET/PhetFont' );

//REVIEW: Missing "// constants" notation
var WHOLE_FRACTIONAL_SIZE_RATIO = 2;
var SHAPE_RADIUS = 50;
// constants
const WHOLE_FRACTIONAL_SIZE_RATIO = 2;
const SHAPE_RADIUS = 50;

var FractionsCommonConstants = {
const FractionsCommonConstants = {
// {number}
PANEL_MARGIN: 10,

Expand Down

0 comments on commit 4afbd45

Please sign in to comment.