Skip to content

Commit

Permalink
consolidate parameters to use model. Document why no dispose, #51
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Jun 25, 2017
1 parent a37900d commit 3c8b4f9
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 27 deletions.
1 change: 0 additions & 1 deletion js/ohms-law/model/OhmsLawModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ define( function( require ) {
reset: function() {
this.voltageProperty.reset();
this.resistanceProperty.reset();
this.soundActiveProperty.reset();
}
} );
} );
2 changes: 1 addition & 1 deletion js/ohms-law/view/BatteriesView.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ define( function( require ) {
batteries.push( battery );
}

// Present for the lifetime of the simulation
// Present for the lifetime of the simulation; no need to unlink.
voltageProperty.link( function( voltage ) {

batteries.forEach( function( battery, index ) {
Expand Down
16 changes: 6 additions & 10 deletions js/ohms-law/view/FormulaNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ define( function( require ) {


/**
* @param {Property.<number>} currentProperty
* @param {Property.<number>} voltageProperty
* @param {Property.<number>} resistanceProperty
* @param {OhmsLawModel} model
* @param {Object} options
* @constructor
*/
function FormulaNode( currentProperty, voltageProperty, resistanceProperty, options ) {
function FormulaNode( model, options ) {

Node.call( this );

Expand All @@ -47,7 +45,7 @@ define( function( require ) {
scaleA: 0.2,
scaleB: 0.84,
x: 380,
property: currentProperty,
property: model.currentProperty,
color: PhetColorScheme.RED_COLORBLIND,
maxInitialWidth: 20
},
Expand All @@ -56,7 +54,7 @@ define( function( require ) {
scaleA: 4.5,
scaleB: 2,
x: 150,
property: voltageProperty,
property: model.voltageProperty,
color: OhmsLawConstants.BLUE_COLOR,
maxInitialWidth: 180
},
Expand All @@ -65,7 +63,7 @@ define( function( require ) {
scaleA: 0.04,
scaleB: 2,
x: 560,
property: resistanceProperty,
property: model.resistanceProperty,
color: OhmsLawConstants.BLUE_COLOR,
maxInitialWidth: 175
}
Expand Down Expand Up @@ -113,14 +111,12 @@ define( function( require ) {
var letterNode = new Node( { children: [ antiArtifactRectangle, textNode ] } );
lettersNode.addChild( letterNode );

// Scale the text as the associated value changes
// Scale the text as the associated value changes. Present for the lifetime of the sim; no need to dispose.
textData.property.link( function updateProperty( value ) {

// Since it would potentially reduce the area of SVG that gets repainted (may be browser-specific)
letterNode.matrix = Matrix3.translation( textData.x, CENTER_Y )
.timesMatrix( Matrix3.scale( textData.scaleA * value + textData.scaleB ) );

// TODO: Performance: consider not updating the matrix if it hasn't changed (if textData.x, textData.scaleA, and textData.scaleB haven't changed)
} );
} );

Expand Down
5 changes: 3 additions & 2 deletions js/ohms-law/view/OhmsLawScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ define( function( require ) {
ScreenView.call( this );

// Node of ohm's law equation. Layout is hardwired, see FormulaNode.
var formulaNode = new FormulaNode( model.currentProperty, model.voltageProperty, model.resistanceProperty, {
var formulaNode = new FormulaNode( model, {
pickable: false
} );

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


// Circuit node with readout node
var wireBox = new WireBox( model.voltageProperty, model.resistanceProperty, model.currentProperty, {
var wireBox = new WireBox( model, {
pickable: false,
x: 70, // Layout of the WireBox
y: 380
Expand Down Expand Up @@ -80,6 +80,7 @@ define( function( require ) {
centerY: controlPanel.bottom + buttonCenterYOffset,
listener: function() {
model.reset();
soundActiveProperty.reset();
}
} ) );

Expand Down
2 changes: 1 addition & 1 deletion js/ohms-law/view/ReadoutPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ define( function( require ) {
resize: false
} );

// Present for the lifetime of the simulation, no need to unlink
// Present for the lifetime of the simulation, no need to unlink.
currentProperty.link( function( current ) {
var rightEdgePosition = currentValue.right;
currentValue.text = Util.toFixed( current, 1 );
Expand Down
2 changes: 1 addition & 1 deletion js/ohms-law/view/ResistorNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ define( function( require ) {
Math.PI / 2,
true );

// Set the number of visible dots based on the resistivity
// Set the number of visible dots based on the resistivity. Present for the lifetime of the simulation; no need to unlink.
resistanceProperty.link( function( resistance ) {
var numDotsToShow = RESISTANCE_TO_NUM_DOTS( resistance );
dotGroup.children.forEach( function( dot, index ) {
Expand Down
3 changes: 1 addition & 2 deletions js/ohms-law/view/SliderUnit.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ define( function( require ) {
this.addChild( readout );
this.addChild( unitText );

// No need to unlink, present for the lifetime of the simulation
// update value of the readout
// Update value of the readout. Present for the lifetime of the simulation; no need to unlink.
property.link( function( value ) {
readout.text = Util.toFixed( value, options.numberDecimalPlaces );
readout.right = unitText.left - 10;
Expand Down
16 changes: 7 additions & 9 deletions js/ohms-law/view/WireBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,45 @@ define( function( require ) {
var OFFSET = 10; // position offset for the RightAngleArrow

/**
* @param {Property.<number>} voltageProperty
* @param {Property.<number>} resistanceProperty
* @param {Property.<number>} currentProperty
* @param {OhmsLawModel} model
* @param {Object} options
* @constructor
*/
function WireBox( voltageProperty, resistanceProperty, currentProperty, options ) {
function WireBox( model, options ) {

Node.call( this );

// For positioning, the top left corner of the wireFrame is defined as 0,0
var wireFrame = new Rectangle( 0, 0, WIDTH, HEIGHT, 4, 4, { stroke: '#000', lineWidth: THICKNESS } );
this.addChild( wireFrame );

var batteriesView = new BatteriesView( voltageProperty, {
var batteriesView = new BatteriesView( model.voltageProperty, {
left: 30, // Slightly to the right of the wire
centerY: 0
} );
this.addChild( batteriesView );

var resistorNode = new ResistorNode( resistanceProperty, {
var resistorNode = new ResistorNode( model.resistanceProperty, {
centerX: WIDTH / 2,
centerY: HEIGHT
} );
this.addChild( resistorNode );

var bottomLeftArrow = new RightAngleArrow( currentProperty, {
var bottomLeftArrow = new RightAngleArrow( model.currentProperty, {
x: -OFFSET,
y: HEIGHT + OFFSET,
rotation: Math.PI / 2
} );
this.addChild( bottomLeftArrow );

var bottomRightArrow = new RightAngleArrow( currentProperty, {
var bottomRightArrow = new RightAngleArrow( model.currentProperty, {
x: WIDTH + OFFSET,
y: HEIGHT + OFFSET,
rotation: 0
} );
this.addChild( bottomRightArrow );

var currentReadoutPanel = new ReadoutPanel( currentProperty, {
var currentReadoutPanel = new ReadoutPanel( model.currentProperty, {
centerY: HEIGHT / 2,
centerX: WIDTH / 2
} );
Expand Down

0 comments on commit 3c8b4f9

Please sign in to comment.