-
Notifications
You must be signed in to change notification settings - Fork 50.4k
(WIP) Separate internal class for functional components #7702
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
Conversation
…ReactFunctionalComponent These are just copies that do the same thing, and ReactClassComponent is the one being used right now.
Fiber deals with this by marking these as "indeterminate components" until the first mount, at which point they are re-classified as either functional or class components. Could a similar approach work here, as well? |
|
The problem is “reclassifying” an already created object as another class is weird (even though technically possible), and we don’t want to add another allocation for a delegating instance either. Fiber doesn’t use classes so doesn’t have this problem. |
|
Sorry, I wasn't suggesting to literally change the class/prototype of the object, but to use a flag of some kind. |
|
Having a flag inside CompositeComponent complicates it logic quite a bit (which is how it works now) and causes us to store redundant information (like public instances for functional components). Moving a flag outside to a "delegating" instance seems like would incur the extra allocation discussed in #3995 (comment). But maybe I misunderstood that comment. |
| }); | ||
|
|
||
| it('uses displayName, name, or Object for factory components', () => { | ||
| xit('uses displayName, name, or Object for factory components', () => { |
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.
just curious: what are xit and xdescribe?
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.
A way to quickly disable a test.
There's also fit which is handy as it tells jest (or jasmine) to only run that specific test, so you don't need to comment out everything else when trying to troubleshot a single one.
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.
Looks like it's not documented on the jest page for some reason: http://facebook.github.io/jest/docs/api.html#content
cc @cpojer
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.
This is important to document. Also many people will try to use it.only, it will crash, and people will think Jest doesn't support this feature.
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.
@gaearon it.only is already in master and will be available the next time a release get cut: jestjs/jest#1632
|
My theory was that it's mostly the polymorphic lifecycle lookups that are slow (ex: evaluating |
|
@spicyj I tried to benchmark it but the script got affected by the splitting of |
|
@keyanzhang Sure. Maybe it could take both filenames just like |
|
I just fixed the bench in #7704. |
For fun, I tried to make a separate internal class for functional components.
Previously this was attempted in #3995.
This is work in progress. I’d like to measure perf implications of this but haven’t had the time yet.
The one feature that I don’t support here is factory components:
They are very inconvenient with our OOP internal hierarchy because we don’t know whether we’re dealing with a functional or a factory component until we call the function at least once.
I assume this is the same reason #3995 got shoot down. However I don’t think I’ve ever seen a “factory component” in the wild and I’m not convinced in the utility of supporting them. Who are their users?
Shallow rendering is also broken in this PR, but I think it’s fixable.