Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undesirable '{0}' replacement #344

Closed
pixelzoom opened this issue Feb 5, 2019 · 6 comments
Closed

undesirable '{0}' replacement #344

pixelzoom opened this issue Feb 5, 2019 · 6 comments

Comments

@pixelzoom
Copy link
Contributor

Noted in phetsims/scenery-phet#446.

NumberControl requires either '{{value}}' or '{0}' in the string pattern. The former is preferred, the latter is deprecated in new code.

These 2 strings are used with NumberControl:

  "gravityValue": {
    "value": "{{gravity}} m/s<sup>2</sup>"
  },

  "massValue": {
    "value": "{{mass}} g"
  },

If '{{value}}' had been used in those strings, these replacements would be unnecessary:

// GravityDampingControlNode
          valuePattern: StringUtils.fillIn( gravityValueString, {
            gravity: '{0}'
          } ),

// MassValueControlPanel
    var valuePattern = StringUtils.fillIn( massValueString, { mass: '{0}' }, {

Since these strings have been released and translated, it's probably too late (and too much work) to change them. But there's still room for improvement here.

Since NumberControl supports '{{value}}', replacement with '{0}' should be avoided. And proliferation of the string literals '{{value}}' and '{0}' should also be avoided. So recommended to replace '{0}' in the above with NumberDisplay.NAMED_PLACEHOLDER.

@Denz1994
Copy link
Contributor

Denz1994 commented Feb 6, 2019

I made the refactor as suggested above and testing with several stringTest={TEST} query parameters. This looks good and should be cherry-picked into the RC branch of MASB. Labeling as such and referencing in RC Test issue.

@Denz1994
Copy link
Contributor

@KatieWoe Reported that stringTest=long seems to be giving an issue on startup.

Exception: Error: Assertion failed: missing value placeholder in options.valuePattern: 12345678901234567890123456789012345678901234567890 at window.assertions.assertFunction (http://phettest.colorado.edu/assert/js/assert.js:22:13) at new NumberDisplay (http://phettest.colorado.edu/scenery-phet/js/NumberDisplay.js?bust=1551220939676:78:15) at new NumberControl (http://phettest.colorado.edu/scenery-phet/js/NumberControl.js?bust=1551220939676:179:25) at new GravityAndDampingControlNode (http://phettest.colorado.edu/masses-and-springs/js/common/view/GravityAndDampingControlNode.js?bust=1551220939676:79:32) at StretchScreenView.SpringScreenView [as constructor] (http://phettest.colorado.edu/masses-and-springs/js/common/view/SpringScreenView.js?bust=1551220939676:163:41) at new TwoSpringScreenView (http://phettest.colorado.edu/masses-and-springs/js/common/view/TwoSpringScreenView.js?bust=1551220939676:37:22) at new StretchScreenView (http://phettest.colorado.edu/masses-and-springs-basics/js/stretch/view/StretchScreenView.js?bust=1551220939676:33:7) at StretchScreen.model [as createView] (http://phettest.colorado.edu/masses-and-springs-basics/js/stretch/StretchScreen.js?bust=1551220939676:54:27) at StretchScreen.initializeView (http://phettest.colorado.edu/joist/js/Screen.js?bust=1551220939676:261:25) at Array. (http://phettest.colorado.edu/joist/js/Sim.js?bust=1551220939676:788:18)
logMessage: "Assertion failed: missing value placeholder in options.valuePattern: 12345678901234567890123456789012345678901234567890"
message: "missing value placeholder in options.valuePattern: 12345678901234567890123456789012345678901234567890"
predicate: false
this: undefined

@pixelzoom
Copy link
Contributor Author

In phetsims/sun#472 (comment), it was suggested that we add an assertion to NumberDisplay and NumberSpinner, to verify that the required {{value}} placeholder is in options.formatPattern. Unfortunately, stringTest is rather dumb when it comes to string replacement, and blows away the entire string. So that's why this assertion is failing only with stringTest.

I think the solution is to skip the assertion in NumberDisplay and NumberSpinner if phet.chipper.queryParameters.stringTest is defined. I'll handle this.

@pixelzoom
Copy link
Contributor Author

pixelzoom commented Feb 27, 2019

Fixed in the above commits. Tested masses-and-springs with and without stringTest.

@Denz1994 please verify.

@Denz1994
Copy link
Contributor

Thanks for looking into this. String test is looking good.

@Denz1994 Denz1994 removed their assignment Feb 27, 2019
Denz1994 added a commit to phetsims/sun that referenced this issue Mar 13, 2019
…asses-and-springs#344 masses-and-springs-basics-1.0 branch. The masses-and-springs-basics-1.0 branch was created for this fix.
Denz1994 added a commit to phetsims/masses-and-springs-basics that referenced this issue Mar 13, 2019
@Denz1994
Copy link
Contributor

These changes have been applied to the masses-and-springs-basics-1.0 branch in the masses-and-springs repo. A branch inSun (`masses-and-springs-basics-1.0) was created to also handle these changes. MASB 1.0 sim dependencies have been updated.

Closing this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants