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

add _.extend to bad sim text? #805

Closed
zepumph opened this issue Oct 18, 2019 · 9 comments
Closed

add _.extend to bad sim text? #805

zepumph opened this issue Oct 18, 2019 · 9 comments
Assignees

Comments

@zepumph
Copy link
Member

zepumph commented Oct 18, 2019

phetsims/phet-core#71

@zepumph
Copy link
Member Author

zepumph commented Oct 18, 2019

We should decide if this is really forbidden in sim text, marking for dev meeting.

@pixelzoom
Copy link
Contributor

pixelzoom commented Oct 24, 2019

When I have full control over the args, and I know that _.extend is appropriate, I'd like to be able to use _.extend. It's more convenient, because unlike merge, I don't need a require statement. For example:

// options shared by all Rectangle instances
const RECTANGLE_OPTIONS = { 
  stroke: 'black',
  lineWidth: 2,
  cornerRadius: 3
};

const redRectangle = new Rectangle( ..., _.extend( { fill: 'red' }, RECTANGLE_OPTIONS );
const greenRectangle = new Rectangle( ..., _.extend( { fill: 'green' }, RECTANGLE_OPTIONS );

@zepumph
Copy link
Member Author

zepumph commented Oct 24, 2019

I think that is reasonable, but I also see value in having an established pattern. If everything is the same, it may be a bit easier for the project as a whole.

I also think that there is a point to be made about maintainability. In the example above, it is currently harmless, but perhaps in the future Rectangle will add in a nested set of options, like paintOptions or something. In which case this potentially becomes a harder refactor.

Again I don't feel strongly about this.

@pixelzoom
Copy link
Contributor

pixelzoom commented Oct 24, 2019

perhaps in the future Rectangle will add in a nested set of options, like paintOptions or something. In which case this potentially becomes a harder refactor.

It doesn't become any harder (and in fact doesn't change) because I have full control over all of the args. If my args are unchanged, then it's irrelevant whether Rectangle takes nested options or not, I need to change nothing. If I'm not using nested options, I can use _.extend. If I need to change my args to nested options in the future, then I know that _.extend in inappropriate, and I change to merge. Yes, I need to know that I must use merge. But PhET developers should be familiar with lodash, and this is minor compared to the other types of trouble that you can get into with Javascript.

@samreid
Copy link
Member

samreid commented Oct 24, 2019

It's more convenient, because unlike merge, I don't need a require statement.

We could change merge to a preload.

@jonathanolson
Copy link
Contributor

jonathanolson commented Oct 24, 2019

We could change merge to a preload.

I'm seeing a common trend where we find something of general use in phet-core (i.e. most of phet-core) and it's "I wish we didn't have to use a require statement" and "I wish I could use this in other preloads, but it's in require.js".

Should we consider moving some core code into a preload that is outside of the require.js system?

@samreid
Copy link
Member

samreid commented Oct 24, 2019

I'm up for making it easy for the entire team, but thought I should mention it doesn't bother me to add the require statement. I use shift-option-cmd-R to automatically add require statements and it has been working well for my situation.

@zepumph
Copy link
Member Author

zepumph commented Oct 24, 2019

We will go with adding [Op]ptions = _.extend and [cC]onfig = _.extend to bad SIM text.

@zepumph
Copy link
Member Author

zepumph commented Nov 7, 2019

Lint rules added above. Only a few had crept in since the conversion. I'm glad to have added these now. Closing.

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

4 participants