Skip to content

Commit

Permalink
Revert "Merge pull request facebook#5689 from jimfb/cleanup-5151"
Browse files Browse the repository at this point in the history
This reverts commit 067547c, reversing
changes made to 102cd29.
  • Loading branch information
sophiebits committed Jan 5, 2016
1 parent 067547c commit 0ebc7b6
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/renderers/dom/shared/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,10 @@ ReactDOMComponent.Mixin = {
}
},

getNativeNode: function() {
return getNode(this);
},

/**
* Destroys all event registrations for this instance. Does not remove from
* the DOM. That must be done by the parent.
Expand Down Expand Up @@ -1053,15 +1057,13 @@ ReactDOMComponent.Mixin = {
break;
}

var nativeNode = getNode(this);
this.unmountChildren();
ReactDOMComponentTree.uncacheNode(this);
EventPluginHub.deleteAllListeners(this);
ReactComponentBrowserEnvironment.unmountIDFromEnvironment(this._rootNodeID);
this._rootNodeID = null;
this._domID = null;
this._wrapperState = null;
return nativeNode;
},

getPublicInstance: function() {
Expand Down
5 changes: 3 additions & 2 deletions src/renderers/dom/shared/ReactDOMEmptyComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ assign(ReactDOMEmptyComponent.prototype, {
},
receiveComponent: function() {
},
getNativeNode: function() {
return ReactDOMComponentTree.getNodeFromInstance(this);
},
unmountComponent: function() {
var node = ReactDOMComponentTree.getNodeFromInstance(this);
ReactDOMComponentTree.uncacheNode(this);
return node;
},
});

Expand Down
7 changes: 5 additions & 2 deletions src/renderers/dom/shared/ReactDOMTextComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,13 @@ assign(ReactDOMTextComponent.prototype, {
}
}
},

getNativeNode: function() {
return getNode(this);
},

unmountComponent: function() {
var node = getNode(this);
ReactDOMComponentTree.uncacheNode(this);
return node;
},

});
Expand Down
17 changes: 14 additions & 3 deletions src/renderers/shared/reconciler/ReactCompositeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ var ReactCompositeComponentMixin = {
return markup;
},

getNativeNode: function() {
return ReactReconciler.getNativeNode(this._renderedComponent);
},

/**
* Releases any resources allocated by `mountComponent`.
*
Expand All @@ -384,7 +388,7 @@ var ReactCompositeComponentMixin = {
}

if (this._renderedComponent) {
var unmountedNativeNode = ReactReconciler.unmountComponent(this._renderedComponent);
ReactReconciler.unmountComponent(this._renderedComponent);
this._renderedNodeType = null;
this._renderedComponent = null;
this._instance = null;
Expand Down Expand Up @@ -415,7 +419,6 @@ var ReactCompositeComponentMixin = {
// TODO: inst.props = null;
// TODO: inst.state = null;
// TODO: inst.context = null;
return unmountedNativeNode;
},

/**
Expand Down Expand Up @@ -803,7 +806,15 @@ var ReactCompositeComponentMixin = {
this._processChildContext(context)
);
} else {
var oldNativeNode = ReactReconciler.unmountComponent(prevComponentInstance);
// TODO: This is currently necessary due to the unfortunate caching
// that ReactMount does which makes it exceedingly difficult to unmount
// a set of siblings without accidentally repopulating the node cache (see
// #5151). Once ReactMount no longer stores the nodes by ID, this method
// can go away.
var oldNativeNode = ReactReconciler.getNativeNode(prevComponentInstance);

ReactReconciler.unmountComponent(prevComponentInstance);

this._renderedNodeType = ReactNodeTypes.getType(nextRenderedElement);
this._renderedComponent = this._instantiateReactComponent(
nextRenderedElement
Expand Down
8 changes: 8 additions & 0 deletions src/renderers/shared/reconciler/ReactReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ var ReactReconciler = {
return markup;
},

/**
* Returns a value that can be passed to
* ReactComponentEnvironment.replaceNodeWithMarkup.
*/
getNativeNode: function(internalInstance) {
return internalInstance.getNativeNode();
},

/**
* Releases any resources allocated by `mountComponent`.
*
Expand Down
3 changes: 3 additions & 0 deletions src/renderers/shared/reconciler/ReactSimpleEmptyComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ assign(ReactSimpleEmptyComponent.prototype, {
},
receiveComponent: function() {
},
getNativeNode: function() {
return ReactReconciler.getNativeNode(this._renderedComponent);
},
unmountComponent: function() {
ReactReconciler.unmountComponent(this._renderedComponent);
this._renderedComponent = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function instantiateReactComponent(node) {
typeof instance.construct === 'function' &&
typeof instance.mountComponent === 'function' &&
typeof instance.receiveComponent === 'function' &&
typeof instance.getNativeNode === 'function' &&
typeof instance.unmountComponent === 'function',
'Only React Components can be mounted.'
);
Expand Down
4 changes: 4 additions & 0 deletions src/test/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ NoopInternalComponent.prototype = {
this._currentElement = element;
},

getNativeNode: function() {
return undefined;
},

unmountComponent: function() {
},

Expand Down

0 comments on commit 0ebc7b6

Please sign in to comment.