phetsims / axon

Axon provides powerful and concise models for interactive simulations, based on observable Properties and related patterns.
MIT License
11 stars 8 forks source link

ReadOnlyProperty toStateObject for validValues needs refinement #444

Closed samreid closed 11 months ago

samreid commented 11 months ago

Discovered in https://github.com/phetsims/phet-io-wrappers/issues/581, ReadOnlyProperty toStateObject for validValues needs refinement. It currently looks like this:

        toStateObject: property => {
          assert && assert( parameterType.toStateObject, `toStateObject doesn't exist for ${parameterType.typeName}` );
          const stateObject: ReadOnlyPropertyState<StateType> = {
            value: parameterType.toStateObject( property.value ),

            // Only include validValues if specified, so they only show up in PhET-iO Studio when supplied.
            validValues: property.validValues ? property.validValues.map( v => {
              return parameterType.toStateObject( v );
            } ) : null,
            units: NullableIO( StringIO ).toStateObject( property.units )
          };

          return stateObject;
        },

Note that the comment no longer matches the code. We changed the implementation so the state schema is accurate. This means we can also simplify the implementation. I will do so shortly and request review from @zepumph

samreid commented 11 months ago

@zepumph reviewed this and recommended we regenerate APIs to make sure there are no changes. I did so and did not observe any API changes. Closing.