Skip to content

Commit

Permalink
convert to optionize pattern, phetsims/scenery-phet#824
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Jan 8, 2024
1 parent 380b4bc commit a7fc9a3
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions js/common/view/WaveInterferenceStopwatchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,44 @@

import StringProperty from '../../../../axon/js/StringProperty.js';
import Range from '../../../../dot/js/Range.js';
import merge from '../../../../phet-core/js/merge.js';
import StopwatchNode, { StopwatchNodeOptions } from '../../../../scenery-phet/js/StopwatchNode.js';
import waveInterference from '../../waveInterference.js';
import WavesModel from '../../waves/model/WavesModel.js';
import WaveInterferenceConstants from '../WaveInterferenceConstants.js';
import WaveInterferenceText from './WaveInterferenceText.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';

type SelfOptions = EmptySelfOptions;

type WaveInterferenceStopwatchNodeOtions = SelfOptions & StopwatchNodeOptions;

class WaveInterferenceStopwatchNode extends StopwatchNode {

public constructor( model: WavesModel, config?: StopwatchNodeOptions ) {
public constructor( model: WavesModel, providedOptions?: WaveInterferenceStopwatchNodeOtions ) {

// Construct the StopwatchNode with the unitsNode reserving the max amount of space it will need
const widestScene = _.maxBy( model.scenes, scene => new WaveInterferenceText( scene.timeUnits ).width )!;

const unitsProperty = new StringProperty( widestScene.timeUnits );

const createNumberFormatter = ( units: string ) => StopwatchNode.createRichTextNumberFormatter( {
showAsMinutesAndSeconds: false,
units: units
} );
config = merge( {

const options = optionize<WaveInterferenceStopwatchNodeOtions, SelfOptions, StopwatchNodeOptions>()( {

// StopwatchNodeOptions
numberDisplayRange: new Range( 0, 999.99 ),
numberDisplayOptions: {
numberFormatter: createNumberFormatter( unitsProperty.value ),
maxWidth: WaveInterferenceConstants.MAX_WIDTH
}
}, config );
}, providedOptions );

assert && assert( !!config.dragListenerOptions, 'end is a required argument' );
assert && assert( !!config.dragBoundsProperty, 'dragBoundsProperty is a required argument' );
assert && assert( !!options.dragListenerOptions, 'end is a required argument' );
assert && assert( !!options.dragBoundsProperty, 'dragBoundsProperty is a required argument' );

super( model.stopwatch, config );
super( model.stopwatch, options );

unitsProperty.link( units => this.setNumberFormatter( createNumberFormatter( units ) ) );

Expand Down

0 comments on commit a7fc9a3

Please sign in to comment.