From a7fc9a3e6e9d41ab889f4456bedf02fa983aa40d Mon Sep 17 00:00:00 2001 From: pixelzoom Date: Mon, 8 Jan 2024 12:10:23 -0700 Subject: [PATCH] convert to optionize pattern, https://github.com/phetsims/scenery-phet/issues/824 --- .../view/WaveInterferenceStopwatchNode.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/js/common/view/WaveInterferenceStopwatchNode.ts b/js/common/view/WaveInterferenceStopwatchNode.ts index d32bf1a2..5d1969aa 100644 --- a/js/common/view/WaveInterferenceStopwatchNode.ts +++ b/js/common/view/WaveInterferenceStopwatchNode.ts @@ -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()( { + + // 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 ) ) );