Skip to content

Commit

Permalink
implement nested options pattern, see phetsims/coulombs-law#89 and #448
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarlow12 committed Dec 20, 2018
1 parent 09afbe3 commit 4ab02c8
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions js/NumberControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ define( function( require ) {
* @constructor
*/
function NumberControl( title, numberProperty, numberRange, options ) {

options = _.extend( {

// General Callbacks
Expand Down Expand Up @@ -118,9 +117,16 @@ define( function( require ) {
phetioType: NumberControlIO,

// a11y
groupFocusHighlight: true
groupFocusHighlight: true,

arrowButtonOptions: null
}, options );

options.arrowButtonOptions = _.extend( {
scale: options.arrowButtonScale,
delta: options.delta
},
options.arrowButtonOptions );

// highlight color for thumb defaults to a brighter version of the thumb color
if ( options.thumbFillEnabled && !options.thumbFillHighlighted ) {
Expand Down Expand Up @@ -150,7 +156,7 @@ define( function( require ) {

var self = this;

var delta = options.delta; // to improve readability
var delta = options.arrowButtonOptions.delta; // to improve readability

var titleNode = new Text( title, {
font: options.titleFont,
Expand All @@ -175,11 +181,6 @@ define( function( require ) {
tandem: options.tandem.createTandem( 'numberDisplay' )
} );

var arrowButtonOptions = {
delta: options.delta,
scale: options.arrowButtonScale
};

var leftArrowButton = new ArrowButton( 'left', function() {
var value = numberProperty.get() - delta;
value = Util.roundToInterval( value, delta ); // constrain to multiples of delta, see #384
Expand All @@ -190,7 +191,7 @@ define( function( require ) {
startCallback: options.leftArrowStartCallback || options.startCallback,
endCallback: options.leftArrowEndCallback || options.endCallback,
focusable: false
}, arrowButtonOptions ) );
}, options.arrowButtonOptions ) );

var rightArrowButton = new ArrowButton( 'right', function() {
var value = numberProperty.get() + delta;
Expand All @@ -202,7 +203,7 @@ define( function( require ) {
startCallback: options.rightArrowStartCallback || options.startCallback,
endCallback: options.rightArrowEndCallback || options.endCallback,
focusable: false
}, arrowButtonOptions ) );
}, options.arrowButtonOptions ) );

var arrowEnabledListener = function( value ) {
leftArrowButton.enabled = ( value > numberRange.min );
Expand Down

0 comments on commit 4ab02c8

Please sign in to comment.