Skip to content
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

New class instantiation and initialization process #2808

Merged
merged 1 commit into from
Jan 20, 2015

Conversation

sebmarkbage
Copy link
Collaborator

Builds on top of #2806

This allows state to be set up in the constructor instead of through
getInitialState. getInitialState is now considered part of "classic".
Therefore, they move into ReactClass's constructor.

As a consequence of this, we no longer have a mapping between the internal
representation and the public instance during the mounting process.
Because the constructor hasn't returned yet.

We used to have a special case for calling setState in getInitialState
which was just ignored. This makes that throw and the component is
considered unmounted during the construction phase.

@sebmarkbage sebmarkbage changed the title WIP: New class instantiation and initialization process New class instantiation and initialization process Jan 20, 2015
@@ -123,7 +109,7 @@ var ReactCompositeComponentMixin = assign({},
this._rootNodeID = null;

this._instance.props = element.props;
this._instance.state = null;
// state gets set up during mount
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is state is already set to null here from the constructor?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Er… never mind; the constructor calls getInitialState. This comment seems wrong then.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

well it gets reset during mount. this can be simplified later. if it's undefined, it gets set to null.

@sophiebits
Copy link
Collaborator

lgtm

This allows state to be set up in the constructor instead of through
getInitialState. getInitialState is now considered part of "classic".
Therefore, they move into ReactClass's constructor.

As a consequence of this, we no longer have a mapping between the internal
representation and the public instance during the mounting process.
Because the constructor hasn't returned yet.

We used to have a special case for calling setState in getInitialState
which was just ignored. This makes that throw and the component is
considered unmounted during the construction phase.
sebmarkbage added a commit that referenced this pull request Jan 20, 2015
New class instantiation and initialization process
@sebmarkbage sebmarkbage merged commit 2d75b11 into facebook:master Jan 20, 2015
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.

2 participants