Skip to content

Commit

Permalink
Pass model properties instead of model, see #290
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Jan 1, 2019
1 parent 139e258 commit 36f41ea
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
57 changes: 30 additions & 27 deletions js/slits/view/SlitsControlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@ define( require => {

/**
* @param {AlignGroup} alignGroup
* @param {SlitsModel} model
* @param {Property.<Scene>} sceneProperty
* @param {Scene} waterScene
* @param {Scene} soundScene
* @param {Scene} lightScene
* @param {Node} comboBoxParent
*/
constructor( alignGroup, model, comboBoxParent ) {
constructor( alignGroup, sceneProperty, waterScene, soundScene, lightScene, comboBoxParent ) {

const barrierTypeDynamicProperty = new DynamicProperty( model.sceneProperty, {
const barrierTypeDynamicProperty = new DynamicProperty( sceneProperty, {
derive: 'barrierTypeProperty',
bidirectional: true
} );

const comboBox = new ComboBox( [
ComboBox.createItem( new WaveInterferenceText( noBarrierString ), BarrierTypeEnum.NO_BARRIER ),
ComboBox.createItem( new WaveInterferenceText( oneSlitString ), BarrierTypeEnum.ONE_SLIT ),
Expand All @@ -65,32 +68,32 @@ define( require => {
// Slit width controls. Ranges, values and deltas specified in
// https://github.com/phetsims/wave-interference/issues/177
const waterSlitWidthControl = new NumberControl(
slitWidthString, model.waterScene.slitWidthProperty, model.waterScene.slitWidthProperty.range, _.extend( {
slitWidthString, waterScene.slitWidthProperty, waterScene.slitWidthProperty.range, _.extend( {
delta: 0.1, // cm
decimalPlaces: 1,
valuePattern: cmValueString,
majorTicks: createTicks( model.waterScene.slitWidthProperty )
majorTicks: createTicks( waterScene.slitWidthProperty )
}, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) );

const soundSlitWidthControl = new NumberControl(
slitWidthString, model.soundScene.slitWidthProperty, model.soundScene.slitWidthProperty.range, _.extend( {
slitWidthString, soundScene.slitWidthProperty, soundScene.slitWidthProperty.range, _.extend( {
delta: 1, // cm
constrainValue: value => Util.roundToInterval( value, 10 ),
valuePattern: cmValueString,
majorTicks: createTicks( model.soundScene.slitWidthProperty )
majorTicks: createTicks( soundScene.slitWidthProperty )
}, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) );

const lightSlitWidthControl = new NumberControl(
slitWidthString, model.lightScene.slitWidthProperty, model.lightScene.slitWidthProperty.range, _.extend( {
slitWidthString, lightScene.slitWidthProperty, lightScene.slitWidthProperty.range, _.extend( {
delta: 10, // nm
constrainValue: value => Util.roundToInterval( value, 50 ),
valuePattern: nmValueString,
majorTicks: createTicks( model.lightScene.slitWidthProperty )
majorTicks: createTicks( lightScene.slitWidthProperty )
}, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) );
const slitWidthControl = new ToggleNode( model.sceneProperty, [
{ value: model.waterScene, node: waterSlitWidthControl },
{ value: model.soundScene, node: soundSlitWidthControl },
{ value: model.lightScene, node: lightSlitWidthControl }
const slitWidthControl = new ToggleNode( sceneProperty, [
{ value: waterScene, node: waterSlitWidthControl },
{ value: soundScene, node: soundSlitWidthControl },
{ value: lightScene, node: lightSlitWidthControl }
] );
barrierTypeDynamicProperty.link( barrierType => {
const enabled = barrierType === BarrierTypeEnum.ONE_SLIT || barrierType === BarrierTypeEnum.TWO_SLITS;
Expand All @@ -103,40 +106,40 @@ define( require => {
// https://github.com/phetsims/wave-interference/issues/177
const waterSeparationControl = new NumberControl(
slitSeparationString,
model.waterScene.slitSeparationProperty,
model.waterScene.slitSeparationProperty.range,
waterScene.slitSeparationProperty,
waterScene.slitSeparationProperty.range,
_.extend( {
decimalPlaces: 1,
delta: 0.1, // cm
valuePattern: cmValueString,
majorTicks: createTicks( model.waterScene.slitSeparationProperty )
majorTicks: createTicks( waterScene.slitSeparationProperty )
}, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) );

const soundSeparationControl = new NumberControl(
slitSeparationString,
model.soundScene.slitSeparationProperty,
model.soundScene.slitSeparationProperty.range,
soundScene.slitSeparationProperty,
soundScene.slitSeparationProperty.range,
_.extend( {
delta: 1, // cm
constrainValue: value => Util.roundToInterval( value, 10 ),
valuePattern: cmValueString,
majorTicks: createTicks( model.soundScene.slitSeparationProperty )
majorTicks: createTicks( soundScene.slitSeparationProperty )
}, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) );

const lightSeparationControl = new NumberControl(
slitSeparationString,
model.lightScene.slitSeparationProperty,
model.lightScene.slitSeparationProperty.range,
lightScene.slitSeparationProperty,
lightScene.slitSeparationProperty.range,
_.extend( {
delta: 10, // nm
constrainValue: value => Util.roundToInterval( value, 50 ),
valuePattern: nmValueString,
majorTicks: createTicks( model.lightScene.slitSeparationProperty )
majorTicks: createTicks( lightScene.slitSeparationProperty )
}, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) );
const slitSeparationControl = new ToggleNode( model.sceneProperty, [
{ value: model.waterScene, node: waterSeparationControl },
{ value: model.soundScene, node: soundSeparationControl },
{ value: model.lightScene, node: lightSeparationControl }
const slitSeparationControl = new ToggleNode( sceneProperty, [
{ value: waterScene, node: waterSeparationControl },
{ value: soundScene, node: soundSeparationControl },
{ value: lightScene, node: lightSeparationControl }
] );

barrierTypeDynamicProperty.link( barrierType => {
Expand Down
4 changes: 3 additions & 1 deletion js/slits/view/SlitsScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ define( require => {
} );

// The Slits screen has an additional control panel below the main control panel, which controls the barrier/slits
const slitControlPanel = new SlitsControlPanel( alignGroup, model, this );
const slitControlPanel = new SlitsControlPanel(
alignGroup, model.sceneProperty, model.waterScene, model.soundScene, model.lightScene, this
);

// When the alignGroup changes the size of the slitsControlPanel, readjust its positioning. Should only happen
// during startup. Use the same pattern as required in WavesScreenView for consistency.
Expand Down

0 comments on commit 36f41ea

Please sign in to comment.