-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Change up componentName #3330
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
Change up componentName #3330
Conversation
|
|
||
| function checkPropTypes(componentName, propTypes, props) { | ||
| componentName = componentName || 'UnknownComponent' | ||
| componentName = {} || '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this supposed to do?
This always assigns {} to componentName, and the function as a whole will always return {}, as @ryanflorence noted.
Why? Is this just a style thing? or is there a bug or something? |
|
Thanks for this @ev1stensberg, but there aren't bugs (that we know of) in this code as-is and I don't think there is any point here other than a style change. |
|
@ryanflorence For me it just seems like using logical OR with itself is messy to be able to use another value on demand. I have no problems using locial OR, and many use it like that, but I guess this is code style related. @taion to address the use of Would it make sense to get rid of locial OR? |
|
No – it's generally accepted best styling practice: https://github.com/airbnb/javascript#comparison--unneeded-ternary. |
|
Wasn't targeting using tenaries, but I assume you knew that. What we should have, is something like: #ES8proposal |
|
I'll slowly start on a temp fix on this btw. Would be as methods/functions though. |
|
There really isn't anything that needs to be fixed here. This is a commonly used pattern, e.g. in https://github.com/facebook/react/blob/v15.0.1/src/isomorphic/classic/types/ReactPropTypes.js#L114. |
|
Cool if I put up a Issue once I've created something showing how I'd pull this off? |
|
This is what I wanted to target. Would be such a nice thing to have a logical Note: This issue is made by babel, but I wanted to encapsulate the effect & show it what it meant to reuse this in an example. |
|
You'll never hit that error. It's logically dead code. |
|
There is default parameters in ES6 which can be used instead but if it isn't used in other places in the code it seems strange to me to change this line of code. |
|
@timdorr In what way? |
|
@ev1stensberg Show me an input where that function will throw an error. |
|
@timdorr thought you meant the function. The error is just there to ensure the user passes something into |
|
But it comes after the logical OR. Again, show me any input that will cause it to throw that error. You cannot. Therefore, there is no point to it existing. I'm really confused why you're so interested in this one line of code in a minor function. Is there some bug here that we're missing? This seems like a lot of bikeshedding. |
|
say a user has Iknow this is like super-picky. You'd end up having the same repetitive code just cause you assign a method to it. For me, this makes more sense than redeclaring your object. This is a paradox though, it's a hacky way of doing the same thing. That's why @timdorr example is twisted in as explanations here. obj is the argument passed to your assign, the conditional was meant to catch a error if user types |
|
Additional note to my cyborg typo: Did you get any of that? If this just seems like you said, bikeshedding, I'd agree to that. Just wanted to point out why this is bad versus what I think it should be |
|
I'm not seeing the point at all. Just because you use a variable twice doesn't make it repetitive. You still have to use it twice in your example. This only muddies the code further because now you've over-abstracted a simple conditional assignment. Honestly, we might make better use of our time discussing the merits and performance benefits of single- vs. double-quoted strings... |
|
@timdorr Yeah I mentioned that in what I wrote, both about abstraction and about repetitiveness. Anyways, enjoy rest of the week! 👊 |
|
|
@taion Thanks for the fix on tenaries. I'm not saying One thing to say about default parameters, is that it's not fit for everything, especially when it sets I'm not the best programmer, of which you'd see in one of my many PR's. Worth noting. Anyways, think this discussion has taken it's latest breath for now, thanks for participating all! |


Last PR was messed up. Sorry about that. Also, sorry for waiting, had to
githere and there. Cheery-picking skills aren't that great yet. You'd end up with 9 file changes if I'd PR the fix I ended up with, so I just forked it lazily. Enough about that...So, the PR.. Lot's of confusion here.
First of all, I didn't see the validation before, so thanks for sorting that out. To address the reason for this PR:
componentName = componentName || 'String'Also thank @sampeka for pointing out clearly bad code. The previous PR wasn't really well composed.
Ultimately I'd love to have
componentName = 'String'and have it loop through like I did in this PR.Cons/Pros? @ryanflorence