Skip to content

Optionize3 should allow some defaults from the first arg #118

@zepumph

Description

@zepumph

@pixelzoom and I were talking over in phetsims/utterance-queue#81 (comment) (in a zoom call), and it would be so very nice if we could have this code working in FocalLengthControl:

Details
Index: js/common/view/FocalLengthControl.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/common/view/FocalLengthControl.ts b/js/common/view/FocalLengthControl.ts
--- a/js/common/view/FocalLengthControl.ts	(revision 64361330d8e6eebc21fc027b54db129af1b5ac95)
+++ b/js/common/view/FocalLengthControl.ts	(date 1652466527269)
@@ -17,9 +17,11 @@
 import IReadOnlyProperty from '../../../../axon/js/IReadOnlyProperty.js';
 import { NodeOptions } from '../../../../scenery/js/imports.js';
 import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
-import optionize, { combineOptions3 } from '../../../../phet-core/js/optionize.js';
+import { combineOptions3, optionize3 } from '../../../../phet-core/js/optionize.js';
 
-type SelfOptions = {};
+type SelfOptions = {
+  bar?: number;
+};
 
 type FocalLengthControlOptions = SelfOptions & PickRequired<NodeOptions, 'tandem'>;
 
@@ -66,8 +68,9 @@
     } );
 
     // Now add providedOptions to the defaults.
-    const options = optionize<FocalLengthControlOptions, SelfOptions, NumberControlOptions>()(
-      numberControlDefaults, providedOptions );
+    const options = optionize3<FocalLengthControlOptions, SelfOptions, NumberControlOptions>()( {
+      bar: 6
+    }, numberControlDefaults, providedOptions );
 
     super( textProperty.value, focalLengthMagnitudeProperty, range, options );
 

@samreid, it actually doesn't seem like too much of an issue to & the first two args to gether to make the defaults happen. If that occurs inside of Optionize, then we are in luck and won't need too many duplicate lines calling optionize.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions