phetsims / sun

User-interface components for PhET simulations, built on top of Scenery.
MIT License
4 stars 12 forks source link

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

Open marlitas opened 8 months ago

marlitas commented 8 months ago

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:

Affected AccordionBox Subclasses:

Affected Panel Subclasses/Usages:

marlitas commented 8 months ago

Dev Meeting 12/7/23

JO: Any objections to refactoring to remove these usages?

pixelzoom commented 8 months ago

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 commented 8 months ago

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

marlitas commented 8 months ago

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 commented 8 months ago

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 commented 7 months ago

So far none of these components have raised any errors:

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

marlitas commented 7 months ago

Tested components:

marlitas commented 1 week ago

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.