Skip to content

Commit

Permalink
Wrap all top-level components for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiebits committed Jun 22, 2015
1 parent 9d2c9b5 commit 643651b
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions src/renderers/dom/client/ReactMount.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,11 @@ function mountComponentIntoNode(
var markup = ReactReconciler.mountComponent(
componentInstance, rootID, transaction, context
);
componentInstance._isTopLevel = true;
if (typeof componentInstance._renderedComponent._currentElement.type ===
'function') {
// hax
componentInstance._renderedComponent._isTopLevel = true;
}
ReactMount._mountImageIntoNode(markup, container, shouldReuseMarkup);
}

Expand Down Expand Up @@ -328,6 +332,17 @@ function unmountComponentFromNode(instance, container) {
}
}

/**
* Temporary (?) hack so that we can store all top-level pending updates on
* composites instead of having to worry about different types of components
* here.
*/
var TopLevelWrapper = function() {};
TopLevelWrapper.prototype.render = function() {
// this.props is actually a ReactElement
return this.props;
};

/**
* Mounting is the process of initializing a React component by creating its
* representative DOM elements and inserting them into a supplied `container`.
Expand Down Expand Up @@ -522,17 +537,26 @@ var ReactMount = {
'for your app.'
);

var nextWrappedElement = new ReactElement(
TopLevelWrapper,
null,
null,
null,
nextElement
);

var prevComponent = instancesByReactRootID[getReactRootID(container)];

if (prevComponent) {
var prevElement = prevComponent._currentElement;
var prevWrappedElement = prevComponent._currentElement;
var prevElement = prevWrappedElement.props;
if (shouldUpdateReactComponent(prevElement, nextElement)) {
return ReactMount._updateRootComponent(
prevComponent,
nextElement,
nextWrappedElement,
container,
callback
).getPublicInstance();
)._renderedComponent.getPublicInstance();
} else {
ReactMount.unmountComponentAtNode(container);
}
Expand Down Expand Up @@ -563,15 +587,15 @@ var ReactMount = {

var shouldReuseMarkup = containerHasReactMarkup && !prevComponent;
var component = ReactMount._renderNewRootComponent(
nextElement,
nextWrappedElement,
container,
shouldReuseMarkup,
parentComponent != null ?
parentComponent._reactInternalInstance._processChildContext(
parentComponent._reactInternalInstance._context
) :
emptyObject
).getPublicInstance();
)._renderedComponent.getPublicInstance();
if (callback) {
callback.call(component);
}
Expand Down

0 comments on commit 643651b

Please sign in to comment.