-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Usage of .name|.displayName
to identify stateless functional components
#6161
Conversation
it('should prefer `displayName`', function () { | ||
var displayName = 'Else'; | ||
|
||
function Something () {} |
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.
To avoid lint error: var Something = function(){};
This change seems good conceptually. I like the additional unit tests and docs change.
We generally aren't afraid of a little copy-pasting. Premature consolidation can actually make readability worse (https://www.youtube.com/watch?v=4anAwXYqLG8). For instance, when reading the tests, I became a little frustrated when I hit Anyway, I could go either way with |
Also, you have a few lint errors, try |
65dde5d
to
2241c69
Compare
@jmm updated the pull request. |
Thanks for the review and feedback @jimfb. I'm sorry the lint errors were a distraction. My goal was to provide a good enough sketch of what I had in mind to see if it's something you're interested in before doing all of the work. In the future I'll try to eliminate lint errors first so they're not distracting. (To that end, it'd be helpful if I've pushed new commits here that resolve the lint errors and perhaps address some of your other concerns (discussed below). Docs
I ended up seeing some discussion of that after opening this PR, so I know what you mean and I understand not wanting to over commit, but I would think that at least specifying that
What do you think? Test structure
I guess I'm not going to get away with not watching this video....
I'm sorry that was frustrating. In my defense:
Personally I'm not a big fan of duplication. If something has to be duplicated I'd prefer it to be some comments than all of the code, which can be the same for each instance except for a couple of parameters. I've added some comments documenting the functions like Component name helper function
Ultimately it's up to you, and of course you're far more familiar with the code base than I am. I haven't gone through all of the potential call sites (so I'm not even sure how many there are), but there are 2 inconsistent versions I know of: use I have to take a closer look at what |
The "if so" is a little confusing. How about:
|
2241c69
to
37a7344
Compare
👍 Edited that in here. |
@jmm updated the pull request. |
Is this now ready, or are there more changes that you wanted to make? Also, please squash your commits together into a single commit ( |
@jimfb So you're good with the structure of the tests and with adding the There are probably some more changes I'd make, though it should work to merge this and PR those separately later, or add them to this PR depending on your preference. Some of the things I have in mind:
I was hoping you could help me understand something about the tests. In
Sure, I'll do that when this settles. (Aside: when squashing a whole branch I usually find it easier to do something like |
})); | ||
} | ||
|
||
it( |
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.
Having many tests like this seems unnecessary to me. If we extract getComponentName
into a function, we can get away with one test here and a bunch of tests for specific cases in getComponentName-test
. The indirection with testKeyAccess
seems over-abstracted and unnecessary to me. Can we make this file simple again?
This PR has heavy conflicts with changes made in #7488 and #8149. @jmm feel free to open a new PR if you want to work on this, it looks like all it would take is using the existing |
This is WIP. I want to see if this is something you're interested in and if so I can clean everything up.
displayName
on stateless functional components be documented? (It would seem so from displayName is set to "o" when minifiying Stateless function components via webpack #4915 (comment).).displayName
/.name
and I think there may be some holes (I'm only positive of one right now, the one in the failing test added here for thekey
warning on a stateless component with only.name
.) Are you interested in patching up those holes?getComponentName
added here.