phetsims / tandem

Simulation-side code for PhET-iO
MIT License
0 stars 5 forks source link

Why are LinkedElements phetioReadOnly: true? #272

Open samreid opened 1 year ago

samreid commented 1 year ago

From https://github.com/phetsims/joist/issues/744

    // This seems buggy since LinkedElement has no setter/mutation methods
    // So shouldn't it inherit like everything else?

class LinkedElement extends PhetioObject {
  public readonly element: LinkableElement;

  public constructor( coreElement: LinkableElement, providedOptions?: LinkedElementOptions ) {
    assert && assert( !!coreElement, 'coreElement should be defined' );

    const options = optionize<LinkedElementOptions, EmptySelfOptions, PhetioObjectOptions>()( {
      phetioType: LinkedElementIO,
      phetioState: false
    }, providedOptions );

    // References cannot be changed by PhET-iO
    assert && assert( !options.hasOwnProperty( 'phetioReadOnly' ), 'phetioReadOnly set by LinkedElement' );
    options.phetioReadOnly = true;
zepumph commented 1 year ago

I thought it was buggy when I thought we were going to be building out support for calling methods on linked elements and forwarding those calls to the core elements, but the "read only" part is inherent to LinkedElementIO, and I can see it making sense. What do you prefer?

samreid commented 1 year ago

I had expected to see it forward values like it does for phetioFeatured.

options.phetioFeatured = coreElement.phetioFeatured;

But I'm sure I can get used to it either way--not sure which is best.