Skip to content

Use if statement instead of ternary #371

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

Merged
merged 2 commits into from
Aug 15, 2016
Merged

Use if statement instead of ternary #371

merged 2 commits into from
Aug 15, 2016

Conversation

gaearon
Copy link
Contributor

@gaearon gaearon commented Aug 15, 2016

I think this is more consistent with how people use React in practice.

React is JS, and it is expected that you use ternaries in the same case as you would use them in JS: only if they help readability. In this case they seem to obscure it.

You still get to say that React is verbose after this change ;-)

<li key={item.id}>
{item.name}
</li>
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closing parens without a beginning :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typed it on iPhone so maybe I missed something but this paren should correspond to opening items.map(.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wait nevermind haha, you are right

@chrisvfritz chrisvfritz merged commit 68621e9 into vuejs:2.0 Aug 15, 2016
@chrisvfritz
Copy link
Contributor

Thanks @gaearon! I just merged and will update the surrounding text accordingly, but I do have one question: Why update const { items } = this.props to use let instead? It doesn't look like it's being overwritten later on.

@gaearon gaearon deleted the patch-1 branch August 16, 2016 00:44
@gaearon
Copy link
Contributor Author

gaearon commented Aug 16, 2016

People reading this might not have good knowledge of ES6 and might assume React forces them to use "const" or something.

@gaearon
Copy link
Contributor Author

gaearon commented Aug 16, 2016

In general I've seen people being opinionated about this (both sides) so I think going with a more "relaxed" style is more beginner friendly.

@chrisvfritz
Copy link
Contributor

Got it. Thanks for the explanation!

Peter-WF referenced this pull request in Peter-WF/vuefe.github.io Nov 18, 2016
* Use if statement instead of ternary

* Make it a little more compact
@chrisvfritz chrisvfritz mentioned this pull request Feb 19, 2017
kazupon added a commit to kazupon/vuejs.org that referenced this pull request Nov 24, 2017
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

Successfully merging this pull request may close these issues.

3 participants