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

SoluteIO 'name' does not update when locale is changed. #243

Closed
pixelzoom opened this issue Sep 7, 2022 · 14 comments
Closed

SoluteIO 'name' does not update when locale is changed. #243

pixelzoom opened this issue Sep 7, 2022 · 14 comments

Comments

@pixelzoom
Copy link
Contributor

pixelzoom commented Sep 7, 2022

After adding support for dynamic locale in #239, we have a problem with SoluteIO. It is currently defined like this:

  /**
   * SoluteIO handles PhET-iO serialization of Solute. Since all Solutes are static instances, it implements
   * 'Reference type serialization', as described in the Serialization section of
   * https://github.com/phetsims/phet-io/blob/master/doc/phet-io-instrumentation-technical-guide.md#serialization
   * But because we want 'name' and 'pH' fields to appear in Studio, we cannot simply subclass ReferenceIO, We
   * must also provide stateSchema and toStateObject. See https://github.com/phetsims/ph-scale/issues/205.
   */
  public static readonly SoluteIO = new IOType( 'SoluteIO', {
    valueType: Solute,
    supertype: ReferenceIO( IOType.ObjectIO ),
    stateSchema: {
      name: StringIO,
      pH: NumberIO
    },
    toStateObject: solute => {
      const soluteReference = ReferenceIO( IOType.ObjectIO ).toStateObject( solute );
      soluteReference.name = solute.nameProperty.value;
      soluteReference.pH = solute.pH;
      return soluteReference;
    }
  } );

And the value shown in Studio displays 'phetioID', 'name', and 'pH' fields, for example:

screenshot_1855

The problem is that the name field is now dynamic (changes with localeProperty) and it does not update where SoluteIO is displayed in Studio.

@zepumph @samreid thoughts?

@pixelzoom
Copy link
Contributor Author

The easiest thing to do here would be to reimplement SoluteIO like this:

  public static readonly SoluteIO = new IOType( 'SoluteIO', {
    valueType: Solute,
    supertype: ReferenceIO( IOType.ObjectIO ),
} );

I'm not really convinced that showing Solute name and pH in Studio has much value. The instructional designer can always consult the running sim. @arouinfar your thoughts?

@samreid
Copy link
Member

samreid commented Sep 7, 2022

I'll self-unassign until we hear from @arouinfar, but I agree if information is in the sim, it does not need to be restated in studio.

@samreid samreid removed their assignment Sep 7, 2022
@zepumph zepumph removed their assignment Sep 7, 2022
@arouinfar
Copy link
Contributor

The problem is that the name field is now dynamic (changes with localeProperty) and it does not update where SoluteIO is displayed in Studio.

I'm not really convinced that showing Solute name and pH in Studio has much value.

Can we drop the name field and instead just include the phetioID and pH? We include the pH so users know the undiluted value.

@arouinfar arouinfar assigned pixelzoom and unassigned arouinfar Sep 9, 2022
@pixelzoom
Copy link
Contributor Author

pixelzoom commented Sep 9, 2022

I can certainly drop the 'name' field for SoluteIO.

But what's the general plan for when a dynamic string needs to appear in an IOType in Studio. @zepumph @samreid? Should I create a general issue, and in which repo?

@zepumph
Copy link
Member

zepumph commented Sep 9, 2022

#243 (comment) seems fine to me. I see 2 other problems though:

  1. It would be ideal if we could go to phScale.global.model.solutes.soda and see its initialState. It has serialization potential, but since it is phetioState:false, we don't get serialization data in the wrapper.
  2. It seems like a weird bug in studio that I cannot explain that phScale.global.model.solutes.soda says its IOType is ObjectIO instead of SoluteIO.

If (1) was not the case, then #243 (comment) would be particularly ideal because we would be able to go to that in studio and see the state of it. @samreid, yet another time we wished we differentiated between allowing to have a serialized value VS. being included in state setting.

@zepumph zepumph removed their assignment Sep 9, 2022
@pixelzoom
Copy link
Contributor Author

  1. It would be ideal if we could go to phScale.global.model.solutes.soda and see its initialState. It has serialization potential, but since it is phetioState:false, we don't get serialization data in the wrapper.

How/why does it have any serialization potential other than "reference"? It has no Properties that it owns, and nameProperty is a references to a localized string Property.

  1. It seems like a weird bug in studio that I cannot explain that phScale.global.model.solutes.soda says its IOType is ObjectIO instead of SoluteIO.

That does seem buggy.

I see the same problem in BLL with static solutes under beersLawLab.global.model.solutes. Static solutions under beersLawLab.beersLawScreen.model.solutions look OK.

@pixelzoom
Copy link
Contributor Author

@arouinfar please review. SoluteIO 'name' field was removed in the above commit. Here's how the value of a soluteProperty looks in Studio:

screenshot_1860

@samreid
Copy link
Member

samreid commented Sep 10, 2022

It's unclear if I need to comment on any parts of this, I'll self-unassign for now but please reinvite me if necessary.

@samreid samreid removed their assignment Sep 10, 2022
@pixelzoom
Copy link
Contributor Author

Yes @samreid -- I would still like you or @zepumph to reply to #243 (comment):

But what's the general plan for when a dynamic string needs to appear in an IOType in Studio. @zepumph @samreid? Should I create a general issue, and in which repo?

@samreid
Copy link
Member

samreid commented Sep 10, 2022

But what's the general plan for when a dynamic string needs to appear in an IOType in Studio.

Dynamic, localized strings should not appear in IOType documentation or method names. If we need to link one PhetioObject to a LocalizedString, perhaps that could be done via a linked element?

@samreid samreid assigned pixelzoom and unassigned samreid Sep 10, 2022
@pixelzoom
Copy link
Contributor Author

pixelzoom commented Sep 10, 2022

Dynamic, localized strings should not appear in IOType documentation or method names.

It's not appearing in IOType documentation or method names. It's in the state object.

If we need to link one PhetioObject to a LocalizedString, perhaps that could be done via a linked element?

That is the problem that resulted in phetsims/axon#414. LocalizedStrings are TReadOnlyProperty<string> in Strings.ts files, which is not linkable.

@pixelzoom pixelzoom assigned samreid and unassigned pixelzoom Sep 10, 2022
@samreid
Copy link
Member

samreid commented Sep 10, 2022

In phetsims/axon#414 we will make the localized strings linkable.

Copying the current value of one instrumented property so it will show up in the state of another PhetioObject doesn't sound like a good idea to me.

But what's the general plan for when a dynamic string needs to appear in an IOType in Studio. @zepumph @samreid? Should I create a general issue, and in which repo?

This sounds like a job for linked elements, if I understand correctly.

@pixelzoom
Copy link
Contributor Author

This sounds like a job for linked elements, if I understand correctly.

You understand correctly, and I agree. So I'll unassign @samreid and @zepumph.

I'll create a new ph-scale issue to link Solute to its nameProperty when phetsims/axon#414 has been addressed.

Remaining work here is review by @arouinfar, see #243 (comment).

@arouinfar
Copy link
Contributor

Looks good, thanks @pixelzoom.

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

4 participants