Rename unmountAndReleaseReactRootNode() -> unmountComponentAtNode()
This is just a better name; we may revisit the name later.
Pete Hunt committed
Sep 19, 2013 at 14:46 UTC
832d9de0374496a3a99a0df7cf100305f1a24158
7 files changed
+48
-10
src/core/React.js
+1
@@ -45,6 +45,7 @@ var React = {
45
ReactMount.renderComponent
46
),
47
renderComponentToString: ReactServerRendering.renderComponentToString,
48
+ unmountComponentAtNode: ReactMount.unmountComponentAtNode,
49
unmountAndReleaseReactRootNode: ReactMount.unmountAndReleaseReactRootNode,
50
isValidClass: ReactCompositeComponent.isValidClass,
51
isValidComponent: ReactComponent.isValidComponent
src/core/ReactMount.js
+17
-3
@@ -341,7 +341,7 @@ var ReactMount = {
341
callback
342
);
343
} else {
344
- ReactMount.unmountAndReleaseReactRootNode(container);
344
+ ReactMount.unmountComponentAtNode(container);
345
}
346
}
347
@@ -415,7 +415,7 @@ var ReactMount = {
415
* @return {boolean} True if a component was found in and unmounted from
416
* `container`
417
*/
418
- unmountAndReleaseReactRootNode: function(container) {
418
+ unmountComponentAtNode: function(container) {
419
var reactRootID = getReactRootID(container);
420
var component = instancesByReactRootID[reactRootID];
421
if (!component) {
@@ -430,6 +430,20 @@ var ReactMount = {
430
return true;
431
},
432
433
+ /**
434
+ * @deprecated
435
+ */
436
+ unmountAndReleaseReactRootNode: function() {
437
+ if (__DEV__) {
438
+ console.warn(
439
+ 'unmountAndReleaseReactRootNode() has been renamed to ' +
440
+ 'unmountComponentAtNode() and will be removed in the next ' +
441
+ 'version of React.'
442
+ );
443
+ }
444
+ return ReactMount.unmountComponentAtNode.apply(this, arguments);
445
+ },
446
+
447
/**
448
* Unmounts a component and removes it from the DOM.
449
*
@@ -437,7 +451,7 @@ var ReactMount = {
451
* @param {DOMElement} container DOM element to unmount from.
452
* @final
453
* @internal
440
- * @see {ReactMount.unmountAndReleaseReactRootNode}
454
+ * @see {ReactMount.unmountComponentAtNode}
455
*/
456
unmountComponentFromNode: function(instance, container) {
457
instance.unmountComponent();
src/core/__tests__/ReactCompositeComponent-test.js
+1
-1
@@ -286,7 +286,7 @@ describe('ReactCompositeComponent', function() {
286
instance.forceUpdate();
287
}).not.toThrow();
288
289
- React.unmountAndReleaseReactRootNode(container);
289
+ React.unmountComponentAtNode(container);
290
expect(function() {
291
instance.forceUpdate();
292
}).toThrow(
src/core/__tests__/ReactMount-test.js
+23
@@ -19,6 +19,8 @@
19
20
"use strict";
21
22
+var mocks = require('mocks');
23
+
24
describe('ReactMount', function() {
25
var React = require('React');
26
var ReactMount = require('ReactMount');
@@ -33,4 +35,25 @@ describe('ReactMount', function() {
35
ReactMount.renderComponent(<span></span>, container);
36
expect(container.firstChild.nodeName).toBe('SPAN');
37
});
38
+
39
+ it('should warn on unmountAndReleaseReactRootNode', function() {
40
+ var _warn = console.warn;
41
+ console.warn = mocks.getMockFunction();
42
+
43
+ var container = document.createElement('container');
44
+ ReactMount.renderComponent(<span />, container);
45
+ expect(console.warn.mock.calls.length).toBe(0);
46
+
47
+ // This method should warn, nothing else should.
48
+ ReactMount.unmountAndReleaseReactRootNode(container);
49
+ expect(console.warn.mock.calls.length).toBe(1);
50
+
51
+ ReactMount.renderComponent(<span />, container);
52
+ expect(console.warn.mock.calls.length).toBe(1);
53
+
54
+ ReactMount.unmountComponentAtNode(container);
55
+ expect(console.warn.mock.calls.length).toBe(1);
56
+
57
+ console.warn = _warn;
58
+ });
59
});
src/core/__tests__/ReactMountDestruction-test.js
+2
-2
@@ -49,10 +49,10 @@ describe('ReactMount', function() {
49
.toBe(1);
50
51
// Test that after unmounting each, they are no longer in the document.
52
- React.unmountAndReleaseReactRootNode(firstRootDiv);
52
+ React.unmountComponentAtNode(firstRootDiv);
53
expect(firstRootDiv.getElementsByClassName('firstReactDiv').length)
54
.toBe(0);
55
- React.unmountAndReleaseReactRootNode(secondRootDiv);
55
+ React.unmountComponentAtNode(secondRootDiv);
56
expect(secondRootDiv.getElementsByClassName('secondReactDiv').length)
57
.toBe(0);
58
});
src/core/__tests__/ReactNativeComponent-test.js
+1
-1
@@ -332,7 +332,7 @@ describe('ReactNativeComponent', function() {
332
ReactEventEmitter.getListener(rootNodeID, 'onClick')
333
).toBe(callback);
334
335
- React.unmountAndReleaseReactRootNode(container);
335
+ React.unmountComponentAtNode(container);
336
337
expect(
338
ReactEventEmitter.getListener(rootNodeID, 'onClick')
src/environment/__tests__/ReactServerRendering-test.js
+3
-3
@@ -181,7 +181,7 @@ describe('ReactServerRendering', function() {
181
182
// Unmount and remount. We should get another mount event and
183
// we should get different markup, as the IDs are unique each time.
184
- React.unmountAndReleaseReactRootNode(element);
184
+ React.unmountComponentAtNode(element);
185
expect(element.innerHTML).toEqual('');
186
React.renderComponent(<TestComponent name="x" />, element);
187
expect(mountCount).toEqual(2);
@@ -191,7 +191,7 @@ describe('ReactServerRendering', function() {
191
// we used server rendering. We should mount again, but the markup should be
192
// unchanged. We will append a sentinel at the end of innerHTML to be sure
193
// that innerHTML was not changed.
194
- React.unmountAndReleaseReactRootNode(element);
194
+ React.unmountComponentAtNode(element);
195
expect(element.innerHTML).toEqual('');
196
197
ExecutionEnvironment.canUseDOM = false;
@@ -208,7 +208,7 @@ describe('ReactServerRendering', function() {
208
React.renderComponent(<TestComponent name="x" />, element);
209
expect(mountCount).toEqual(3);
210
expect(element.innerHTML.indexOf('__sentinel__') > -1).toBe(true);
211
- React.unmountAndReleaseReactRootNode(element);
211
+ React.unmountComponentAtNode(element);
212
expect(element.innerHTML).toEqual('');
213
214
// Now simulate a situation where the app is not idempotent. React should