@samitouri / QOS-React-2 / commits / 9b1fa914fa

React.renderComponent -> React.render

Also rename all the associated render methods and adds deprecation notices.

Paul O’Shannessy committed Aug 5, 2014 at 18:53 UTC 9b1fa914fafca23b201d5bf4d7ca6ffa1dff6cc4
4 files changed +109 -21
src/browser/server/ReactServerRendering.js
+7 -7
@@ -31,10 +31,10 @@ var invariant = require('invariant');
31 * @param {ReactElement} element
32 * @return {string} the HTML markup
33 */
34 -function renderComponentToString(element) {
34 +function renderToString(element) {
35 invariant(
36 ReactElement.isValidElement(element),
37 - 'renderComponentToString(): You must pass a valid ReactElement.'
37 + 'renderToString(): You must pass a valid ReactElement.'
38 );
39
40 var transaction;
@@ -55,12 +55,12 @@ function renderComponentToString(element) {
55 /**
56 * @param {ReactElement} element
57 * @return {string} the HTML markup, without the extra React ID and checksum
58 -* (for generating static pages)
58 + * (for generating static pages)
59 */
60 -function renderComponentToStaticMarkup(element) {
60 +function renderToStaticMarkup(element) {
61 invariant(
62 ReactElement.isValidElement(element),
63 - 'renderComponentToStaticMarkup(): You must pass a valid ReactElement.'
63 + 'renderToStaticMarkup(): You must pass a valid ReactElement.'
64 );
65
66 var transaction;
@@ -78,6 +78,6 @@ function renderComponentToStaticMarkup(element) {
78 }
79
80 module.exports = {
81 - renderComponentToString: renderComponentToString,
82 - renderComponentToStaticMarkup: renderComponentToStaticMarkup
81 + renderToString: renderToString,
82 + renderToStaticMarkup: renderToStaticMarkup
83 };
src/browser/ui/React.js
+38 -11
@@ -43,6 +43,7 @@ var ReactPropTypes = require('ReactPropTypes');
43 var ReactServerRendering = require('ReactServerRendering');
44 var ReactTextComponent = require('ReactTextComponent');
45
46 +var deprecated = require('deprecated');
47 var onlyChild = require('onlyChild');
48
49 ReactDefaultInjection.inject();
@@ -63,6 +64,8 @@ createFactory = ReactLegacyElement.wrapCreateFactory(
64 createFactory
65 );
66
67 +var render = ReactPerf.measure('React', 'render', ReactMount.render);
68 +
69 var React = {
70 Children: {
71 map: ReactChildren.map,
@@ -76,22 +79,16 @@ var React = {
79 EventPluginUtils.useTouchEvents = shouldUseTouch;
80 },
81 createClass: ReactCompositeComponent.createClass,
79 - createDescriptor: createElement, // deprecated, will be removed next week
82 createElement: createElement,
83 createFactory: createFactory,
84 constructAndRenderComponent: ReactMount.constructAndRenderComponent,
85 constructAndRenderComponentByID: ReactMount.constructAndRenderComponentByID,
84 - renderComponent: ReactPerf.measure(
85 - 'React',
86 - 'renderComponent',
87 - ReactMount.renderComponent
88 - ),
89 - renderComponentToString: ReactServerRendering.renderComponentToString,
90 - renderComponentToStaticMarkup:
91 - ReactServerRendering.renderComponentToStaticMarkup,
86 + render: render,
87 + renderToString: ReactServerRendering.renderToString,
88 + renderToStaticMarkup: ReactServerRendering.renderToStaticMarkup,
89 unmountComponentAtNode: ReactMount.unmountComponentAtNode,
90 isValidClass: ReactLegacyElement.isValidFactory,
94 - isValidComponent: ReactElement.isValidElement,
91 + isValidElement: ReactElement.isValidElement,
92 withContext: ReactContext.withContext,
93 __internals: {
94 Component: ReactComponent,
@@ -102,7 +99,37 @@ var React = {
99 Mount: ReactMount,
100 MultiChild: ReactMultiChild,
101 TextComponent: ReactTextComponent
105 - }
102 + },
103 +
104 + // Deprecations (remove for 0.13)
105 + renderComponent: deprecated(
106 + 'React',
107 + 'renderComponent',
108 + 'render',
109 + this,
110 + render
111 + ),
112 + renderComponentToString: deprecated(
113 + 'React',
114 + 'renderComponentToString',
115 + 'renderToString',
116 + this,
117 + ReactServerRendering.renderToString
118 + ),
119 + renderComponentToStaticMarkup: deprecated(
120 + 'React',
121 + 'renderComponentToStaticMarkup',
122 + 'renderToStaticMarkup',
123 + this,
124 + ReactServerRendering.renderToStaticMarkup
125 + ),
126 + isValidComponent: deprecated(
127 + 'React',
128 + 'isValidComponent',
129 + 'isValidElement',
130 + this,
131 + ReactElement.isValidElement
132 + )
133 };
134
135 if (__DEV__) {
src/browser/ui/ReactMount.js
+13 -3
@@ -27,6 +27,7 @@ var ReactInstanceHandles = require('ReactInstanceHandles');
27 var ReactPerf = require('ReactPerf');
28
29 var containsNode = require('containsNode');
30 +var deprecated = require('deprecated');
31 var getReactRootElementInContainer = require('getReactRootElementInContainer');
32 var instantiateReactComponent = require('instantiateReactComponent');
33 var invariant = require('invariant');
@@ -204,7 +205,7 @@ function findDeepestCachedAncestor(targetID) {
205 * representative DOM elements and inserting them into a supplied `container`.
206 * Any prior content inside `container` is destroyed in the process.
207 *
207 - * ReactMount.renderComponent(
208 + * ReactMount.render(
209 * component,
210 * document.getElementById('container')
211 * );
@@ -340,7 +341,7 @@ var ReactMount = {
341 * @param {?function} callback function triggered on completion
342 * @return {ReactComponent} Component instance rendered in `container`.
343 */
343 - renderComponent: function(nextElement, container, callback) {
344 + render: function(nextElement, container, callback) {
345 invariant(
346 ReactElement.isValidElement(nextElement),
347 'renderComponent(): Invalid component element.%s',
@@ -401,7 +402,7 @@ var ReactMount = {
402 */
403 constructAndRenderComponent: function(constructor, props, container) {
404 var element = createElement(constructor, props);
404 - return ReactMount.renderComponent(element, container);
405 + return ReactMount.render(element, container);
406 },
407
408 /**
@@ -683,4 +684,13 @@ var ReactMount = {
684 purgeID: purgeID
685 };
686
687 +// Deprecations (remove for 0.13)
688 +ReactMount.renderComponent = deprecated(
689 + 'ReactMount',
690 + 'renderComponent',
691 + 'render',
692 + this,
693 + ReactMount.render
694 +);
695 +
696 module.exports = ReactMount;
src/utils/deprecated.js new
+51
@@ -0,0 +1,51 @@
1 +/**
2 + * Copyright 2013-2014 Facebook, Inc.
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + *
16 + * @providesModule deprecated
17 + */
18 +
19 +var warning = require('warning');
20 +
21 +/**
22 + * This will log a single deprecation notice per function and forward the call
23 + * on to the new API.
24 + *
25 + * @param {string} namespace The namespace of the call, eg 'React'
26 + * @param {string} oldName The old function name, eg 'renderComponent'
27 + * @param {string} newName The new function name, eg 'render'
28 + * @param {*} ctx The context this forwarded call should run in
29 + * @param {function} fn The function to forward on to
30 + * @return {*} Will be the value as returned from `fn`
31 + */
32 +function deprecated(namespace, oldName, newName, ctx, fn) {
33 + var warned = false;
34 + if (__DEV__) {
35 + var newFn = function() {
36 + warning(
37 + warned,
38 + `${namespace}.${oldName} will be deprecated in a future version. ` +
39 + `Use ${namespace}.${newName} instead.`
40 + );
41 + warned = true;
42 + return fn.apply(ctx, arguments);
43 + };
44 + newFn.displayName = `${namespace}_${oldName}`;
45 + return newFn;
46 + }
47 +
48 + return fn;
49 +}
50 +
51 +module.exports = deprecated;