-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conventions for specifying PhET-iO options #67
Comments
I recall our decision to partition out the different options, and we sometimes include a |
I'm a little uncertain what to do with this issue... is there a convention I should be following? It makes sense to organize the options in a way that's consistent and legible, so I can move forward on that? |
I will defer to the PhET-iO team on this one. The convention has been to group all PhET-iO default under |
Nothing in https://github.com/phetsims/phet-io/blob/master/doc/phet-io-instrumentation-technical-guide.md by the way, so if there's a convention, it's not documented. |
I will go ahead and move forward on grouping PhET-iO related options together at the end of the object literal. Seems to provide clarity, and I would probably recommend adding this as a convention to the phet-io instrumentation guide if this is something we want new devs to be aware of. @samreid and @zepumph... thoughts? |
This is where we documented it. Generally for all options grouping, not just for |
In TypeScript code, I've found it more useful to group default values by the type that they are associated with. I generally put SelfOptions values first, followed by superclass values. For example, in geometric-optics LabelNode.ts: type SelfOptions = {
xAlign?: XAlign;
yAlign?: YAlign;
xOffset?: number; // from center, in view coordinates
yOffset?: number; // in view coordinates
phetioReadOnlyText?: boolean; // should the RichText be phetioReadOnly?
};
export type LabelNodeOptions = SelfOptions & PickRequired<BackgroundNodeOptions, 'visibleProperty' | 'tandem'>;
export default class LabelNode extends BackgroundNode {
...
public constructor( ..., providedOptions: LabelNodeOptions ) {
const options = optionize<LabelNodeOptions, SelfOptions, BackgroundNodeOptions>()( {
// SelfOptions
xAlign: 'center',
yAlign: 'top',
xOffset: 0,
yOffset: 2,
phetioReadOnlyText: false,
// BackgroundNodeOptions
xMargin: 5,
yMargin: 5,
rectangleOptions: {
fill: GOColors.screenBackgroundColorProperty,
cornerRadius: 4,
opacity: 0.5
}
}, providedOptions ); |
Categorized and organized options with |
👍🏻 closing |
For code review #41 ...
This is a question for the PhET-iO team, @zepumph and @samreid.
I've gotten in the habit of putting PhET-iO related option last at instantitation sites. That's the pattern that I've seen in most code, and I vaguely recall a conversation to that effect, so maybe it's an unwritten convention.
This sim puts that PhET-iO options wherever. For example, in MeanShareAndBalanceScreenView.ts:
So... Does the PhET-iO team care when options like
tandem
appear? Or whether all PhET-iO options are grouped together? Or anything else that should be written into conventions?The text was updated successfully, but these errors were encountered: