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

Move instrumented textProperty from IO Type to core type #1082

Closed
zepumph opened this issue Sep 25, 2020 · 9 comments
Closed

Move instrumented textProperty from IO Type to core type #1082

zepumph opened this issue Sep 25, 2020 · 9 comments

Comments

@zepumph
Copy link
Member

zepumph commented Sep 25, 2020

From #1046 and largely related to #1047, we want to remove the phet-io specific Property that exists in TextIO and RichTextIO. It would be best if Text.js and RichText could be refactored to run on TinyProperty. Likely this would be a similar pattern as implemented for visibleProperty over in #1046.

I want to put this on hold until #1046 is more thoroughly vetted. If we need to use this pattern 5 times (Text.text, RichText.text, Node.visible, Node.opacity, Node.pickable), the likely we may want to change how much logic is needed to accomplish it.

@zepumph
Copy link
Member Author

zepumph commented Sep 25, 2020

This is blocking This is blocking phetsims/tandem#210

@zepumph
Copy link
Member Author

zepumph commented Oct 16, 2020

would be best if Text.js and RichText could be refactored to run on TinyProperty.

Oops, this work happened as part of #490. This issue is really focused on getting rid of PhET-iO instrumented text Properties implemented out of the IO type and into the core type.

@zepumph zepumph changed the title Can Text run on Property? Move instrumented textProperty from IO Type to core type Oct 16, 2020
@samreid
Copy link
Member

samreid commented Oct 17, 2020

@zepumph and I discussed how to apply the pattern for visibleProperty to Text.textProperty and RichText.textProperty. Some topics:

  • Will textProperty need to be instrumented if we are using https://github.com/phetsims/studio/issues/192 for text customization? Or maybe text should default to phetioReadOnly: true
  • How can we share code between Text/RichText? We cannot use the modern pattern for mixins until Text and RichText use class

@samreid
Copy link
Member

samreid commented Oct 17, 2020

I applied the pattern from visibleProperty to Text.textProperty. I tested in Natural Selection like so:

Index: js/common/view/EnvironmentalFactorsPanel.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- js/common/view/EnvironmentalFactorsPanel.js	(revision bd63acdecbd514f293e742612a4854f7fd89e3df)
+++ js/common/view/EnvironmentalFactorsPanel.js	(date 1602899306510)
@@ -8,6 +8,7 @@
  */
 
 import Property from '../../../../axon/js/Property.js';
+import StringProperty from '../../../../axon/js/StringProperty.js';
 import merge from '../../../../phet-core/js/merge.js';
 import AssertUtils from '../../../../phetcommon/js/AssertUtils.js';
 import AlignGroup from '../../../../scenery/js/nodes/AlignGroup.js';
@@ -43,10 +44,15 @@
       tandem: Tandem.REQUIRED
     }, NaturalSelectionConstants.PANEL_OPTIONS, options );
 
+    const myTextProperty = new StringProperty('salut',{
+      tandem: options.tandem.createTandem('bonjourProperty')
+    });
+
     const titleNode = new Text( naturalSelectionStrings.environmentalFactors, {
       font: NaturalSelectionConstants.TITLE_FONT,
       maxWidth: 175, // determined empirically,
-      tandem: options.tandem.createTandem( 'titleNode' )
+      tandem: options.tandem.createTandem( 'titleNode' ),
+      textProperty: myTextProperty
     } );
 
     // To make all checkbox labels have the same effective size

It created the correct linkedProperty. I also generated generate-phet-io-api before and after, and they came out the same.

@samreid
Copy link
Member

samreid commented Oct 17, 2020

I applied the same pattern to RichText. Now there are 100 lines that are identical between RichText.js and Text.js, and they are highly similar with visibleProperty in Node.js. I considered:

  • Using the old pattern for mixins, but I am not sure of costs or risks involved in that pattern. It would at least make navigation/autocomplete readability worse.
  • Using the new pattern for mixins, which would be possible after these use ES6, this would also make navigation/autocomplete/readability worse.
  • Marking with line comments on every line that those lines should be maintained together
  • Factoring out method bodies or parts of method bodies to shared common code

I'll move the "factor out shared code" to a side issue and request review of what's been done so far.

@zepumph
Copy link
Member Author

zepumph commented Oct 21, 2020

It does seem like this could largely benefit from some factored out logic. Thanks for making #1097. I have no other thoughts for this issue. Thanks for implementing!

I think this issue further adds priority to https://github.com/phetsims/studio/issues/192, but that is more of a medium-term goal that we should do after more clean-up.

Anything else here?

@zepumph
Copy link
Member Author

zepumph commented Oct 21, 2020

Oh! I feel like we should create factored out unit tests for these Texts. Perhaps we could reuse blocks of code from NodeTests.js. What do you think?

@zepumph zepumph assigned samreid and unassigned zepumph Oct 21, 2020
@zepumph
Copy link
Member Author

zepumph commented Oct 30, 2020

@samreid
Copy link
Member

samreid commented Nov 18, 2020

I don't think we should add Text and RichText sub-Properties tests like we have done for the NodeTests. I think this issue can be closed, but feel free to reopen/disagree.

@samreid samreid closed this as completed Nov 18, 2020
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