Skip to content

Minimal implementation of stateless components #4587

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 11, 2015

Conversation

sophiebits
Copy link
Collaborator

Stateless pure-function components give us more opportunity to make performance optimizations. For now, we'll do a minimal implementation which has similar performance characteristics to other components in the interests of shipping 0.14 and allowing people to begin writing code using this pattern; in the future we can refactor to allocate less and avoid other unnecessary work.

This adapts @vslinko's tests from #3995.

Shouldn't be much change. Notably, this calls `.getName()` instead of trying to derive it manually, which is more consistent.
@sophiebits
Copy link
Collaborator Author

cc @sebmarkbage

@vslinko: Thanks for your work in #3995. We're planning to go with a minimal implementation for now but let's keep your other PR open to see if we want to pull it in for 0.15.

Stateless pure-function components give us more opportunity to make performance optimizations. For now, we'll do a minimal implementation which has similar performance characteristics to other components in the interests of shipping 0.14 and allowing people to begin writing code using this pattern; in the future we can refactor to allocate less and avoid other unnecessary work.
@vslinko
Copy link

vslinko commented Aug 9, 2015

@spicyj ok, agreed

@sebmarkbage
Copy link
Collaborator

lgtm

sophiebits added a commit that referenced this pull request Aug 11, 2015
Minimal implementation of stateless components
@sophiebits sophiebits merged commit d1a2193 into facebook:master Aug 11, 2015
inst = new Component(publicProps, publicContext, ReactUpdateQueue);
}

if (inst === null || inst === false || ReactElement.isValidElement(inst)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This won't work because the construct trap will intercept any non-object and turn it into this. :(

@epsitec
Copy link

epsitec commented Nov 14, 2015

@spicyj I'm not sure: are there plans for the stateless function component to be handled as being pure and thus avoiding repeated calls (to render the output) if the properties provided stay unchanged (with respect to a shallowCompare, probably)?

@jimfb
Copy link
Contributor

jimfb commented Nov 14, 2015

@epsitec You can read the relevant discussion is here: #3995 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants