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

Components with "content" should refrain from Decorator Pattern #860

Open
9 tasks done
marlitas opened this issue Dec 7, 2023 · 13 comments
Open
9 tasks done

Components with "content" should refrain from Decorator Pattern #860

marlitas opened this issue Dec 7, 2023 · 13 comments
Assignees

Comments

@marlitas
Copy link
Contributor

marlitas commented Dec 7, 2023

Components that handle the layout of their children such as: ButtonNode, AccordionBox, Panel, Carousel, etc should not use the decorator pattern. Adding children to these components outside of the "content" or "contentNode" seems like an anti-pattern. We would like to discourage these Node subclasses from adding children through options or mutation.

Affected ButtonNode Subclasses:

  • RectangularRadioButton (sun)
  • LevelSelectionButton (vegas)
  • SmallStepsLockToggleButton (quadrilateral)

Affected AccordionBox Subclasses:

  • EnergyBarGraphAccordionBox (energy-skate-park)
  • EnergyGraphAccordionBox (energy-skate-park)
  • ShoppingQuestionsAccordionBox (unit-rates)
  • PHAccordionBox (ph-scale)

Affected Panel Subclasses/Usages:

  • BAAScreenView (build-an-atom, labelVisibilityControlPanel)
  • PieChartLegend (energy-skate-park)
@marlitas
Copy link
Contributor Author

marlitas commented Dec 7, 2023

Dev Meeting 12/7/23

JO: Any objections to refactoring to remove these usages?

  • No Objections, it will be loud to prevent future usages.

@pixelzoom
Copy link
Contributor

pixelzoom commented Dec 7, 2023

I'll be happy to address refactoring any in the sims that I'm responsible for. I see 2 so far in the list above, which I'll take care of now.

@pixelzoom pixelzoom self-assigned this Dec 7, 2023
pixelzoom added a commit to phetsims/unit-rates that referenced this issue Dec 7, 2023
pixelzoom added a commit to phetsims/ph-scale that referenced this issue Dec 7, 2023
@pixelzoom
Copy link
Contributor

pixelzoom commented Dec 7, 2023

Some other common-code UI components that have "content" (not a complete list) ...

  • Checkbox
  • Dialog
  • Carousel
  • KeyboardHelpSection

@marlitas marlitas assigned marlitas and jonathanolson and unassigned pixelzoom Dec 7, 2023
@marlitas
Copy link
Contributor Author

marlitas commented Dec 7, 2023

Thanks @pixelzoom! I'll keep going through components to make a comprehensive list. I will plan on refactoring the common code components that need this work done.

@pixelzoom
Copy link
Contributor

In case it's useful, I added this at the end of relevant constructors to identify culprits:

    this.childrenChangedEmitter.addListener( () => console.log( new Error( 'children changed' ).stack ) );

@marlitas
Copy link
Contributor Author

So far none of these components have raised any errors:

  • Checkbox
  • Dialog
  • Carousel
  • KeyboardHelpSection

I'll continue checking components that use the "content" pattern, especially those that extend sizable.

@marlitas
Copy link
Contributor Author

marlitas commented Dec 14, 2023

Tested components:

  • AccordionBox
  • AlignBox
  • AquaRadioButton
  • AquaRadioButtonGroup
  • ButtonNode
  • Carousel
  • Checkbox
  • Dialog
  • KeyboardHelpSection
  • NumberControl
  • Panel
  • RichText
  • Slider

@marlitas
Copy link
Contributor Author

This would be good to put on the radar again. I would love some help as I don't think I have the bandwidth to complete myself. I'll add it to the dev board to discuss in the next meeting and see if I can wrangle a co-conspirator.

@jessegreenberg
Copy link
Contributor

jessegreenberg commented Aug 15, 2024

Recommendation from developer meeting:

  • Prioritize the common code components. Leave sim specific components for the responsible developers. They will need to work on it when it is time for dynamic layout.

I will take a look at the common code components this iteration, and also review the assertions that were proposed here.

It is possible that some of these have already been fixed.

@pixelzoom
Copy link
Contributor

pixelzoom commented Aug 15, 2024

I will take a look at the common code components this iteration, and also review the assertions that were proposed here.

It is possible that some of these have already been fixed.

From #860 (comment), the common-code components are:

  • RectangularRadioButton (sun)
  • LevelSelectionButton (vegas)

LevelSelectionButton is already fixed. @marlitas said the problem was fixed in phetsims/vegas@f605de4. And I recently (7/31/24) added support for dynamic layout.

I don't know about RectangularRadioButton.

jessegreenberg added a commit to phetsims/scenery-phet that referenced this issue Aug 19, 2024
jessegreenberg added a commit to phetsims/quadrilateral that referenced this issue Aug 19, 2024
jessegreenberg added a commit to phetsims/graphing-quadratics that referenced this issue Aug 19, 2024
jessegreenberg added a commit to phetsims/scenery that referenced this issue Aug 19, 2024
jessegreenberg added a commit to phetsims/energy-skate-park that referenced this issue Aug 19, 2024
jessegreenberg added a commit to phetsims/ratio-and-proportion that referenced this issue Aug 19, 2024
@jessegreenberg
Copy link
Contributor

jessegreenberg commented Aug 20, 2024

Here is what I have done so far -

While working on this, it was pointed out that some components should allow having children added to them (like Slider and RichText), because the implementation of their layout does not make assumptions about children.

However, @jonathanolson suggested that all common code components should discourage adding children to them because a) it is difficult to review the implementation of each and decide whether assumptions are made and b) adding children to UI components makes usages less maintainable.

We need to check in at developer meeting to decide next steps.

@jonathanolson
Copy link
Contributor

Dev meeting decision:

  • This is a general anti-pattern, components should be responsible for their own children, and outside code shouldn't add children to them.
  • We'll want to add assertions to ComboBox and any remaining Sizable components (and potentially everything in sun/scenery-phet as a chip-away)
  • We'll want to StrictOmit children from common component options
  • Common code Node components should ideally have a run-time assertion for detection + StrictOmit on children.

@jessegreenberg thoughts on what would be good to do now?

@marlitas
Copy link
Contributor Author

marlitas commented Sep 4, 2024

@jessegreenberg I will have some time again to finish this off. Would you like to meet and discuss next steps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants