phetsims / scenery-phet

Reusable components based on Scenery that are specific to PhET simulations.
MIT License
8 stars 6 forks source link

StopwatchNode does not update immediately when associated StringProperties are changed. #781

Closed pixelzoom closed 8 months ago

pixelzoom commented 1 year ago

Related to https://github.com/phetsims/scenery-phet/issues/780 ...

If the value formatter for StopwatchNode is created using StopwatchNode.createRichTextNumberFormatter, the displayed value is not immediately updated when the associated StringProperties are changed. As noted in StopwatchNode.ts:

  /**
   * Creates a custom value for options.numberDisplayOptions.numberFormatter, passed to NumberDisplay.
   *
   * TODO https://github.com/phetsims/scenery-phet/issues/781
   * Because this is called by NumberDisplay when its valueProperty changes, there's no way to make
   * this API update immediately when options.valueUnitsPattern or options.units changes. The NumberDisplay
   * will not show changes to those strings until the value changes. If this is a problem, we'll need to
   * come up with a new API for updating the NumberDisplay when associated StringProperties change.
   */
  public static createRichTextNumberFormatter( providedOptions?: FormatterOptions ): ( time: number ) => string {
pixelzoom commented 8 months ago

Where createRichTextNumberFormatter is used, this should be addressed using strictAxonDependencies. It's not ideal, but here's an example from WaveInterferenceStopwatchNode.ts:

        numberFormatter: StopwatchNode.createRichTextNumberFormatter( {
          showAsMinutesAndSeconds: false,
          units: unitsProperty
        } ),
        numberFormatterDependencies: [
          SceneryPhetStrings.stopwatchValueUnitsPatternStringProperty, // used by StopwatchNode.createRichTextNumberFormatter
          unitsProperty
        ],
phet-dev commented 8 months ago

Reopening because there is a TODO marked for this issue.