mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Support rendering different components into same node
var container = ...; // some DOM node
React.renderComponent(<div />, container);
React.renderComponent(<span />, container);
This should replace the rendered <div> with a <span>, effectively
reconciling at the root level.
(cherry picked from commit 100af48f53)
This commit is contained in:
committed by
Paul O’Shannessy
parent
e105cb56e7
commit
2af5be4c4c
@@ -106,11 +106,15 @@ var ReactMount = {
|
||||
renderComponent: function(nextComponent, container) {
|
||||
var prevComponent = instanceByReactRootID[getReactRootID(container)];
|
||||
if (prevComponent) {
|
||||
var nextProps = nextComponent.props;
|
||||
ReactMount.scrollMonitor(container, function() {
|
||||
prevComponent.replaceProps(nextProps);
|
||||
});
|
||||
return prevComponent;
|
||||
if (prevComponent.constructor === nextComponent.constructor) {
|
||||
var nextProps = nextComponent.props;
|
||||
ReactMount.scrollMonitor(container, function() {
|
||||
prevComponent.replaceProps(nextProps);
|
||||
});
|
||||
return prevComponent;
|
||||
} else {
|
||||
ReactMount.unmountAndReleaseReactRootNode(container);
|
||||
}
|
||||
}
|
||||
|
||||
ReactMount.prepareTopLevelEvents(ReactEventTopLevelCallback);
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* @jsx React.DOM
|
||||
* @emails react-core
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
describe('ReactMount', function() {
|
||||
var React = require('React');
|
||||
var ReactMount = require('ReactMount');
|
||||
|
||||
it('should render different components in same root', function() {
|
||||
var container = document.createElement('container');
|
||||
document.documentElement.appendChild(container);
|
||||
|
||||
ReactMount.renderComponent(<div></div>, container);
|
||||
expect(container.firstChild.nodeName).toBe('DIV');
|
||||
|
||||
ReactMount.renderComponent(<span></span>, container);
|
||||
expect(container.firstChild.nodeName).toBe('SPAN');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user