mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
React.renderComponent -> React.render
Also rename all the associated render methods and adds deprecation notices.
This commit is contained in:
@@ -31,10 +31,10 @@ var invariant = require('invariant');
|
||||
* @param {ReactElement} element
|
||||
* @return {string} the HTML markup
|
||||
*/
|
||||
function renderComponentToString(element) {
|
||||
function renderToString(element) {
|
||||
invariant(
|
||||
ReactElement.isValidElement(element),
|
||||
'renderComponentToString(): You must pass a valid ReactElement.'
|
||||
'renderToString(): You must pass a valid ReactElement.'
|
||||
);
|
||||
|
||||
var transaction;
|
||||
@@ -55,12 +55,12 @@ function renderComponentToString(element) {
|
||||
/**
|
||||
* @param {ReactElement} element
|
||||
* @return {string} the HTML markup, without the extra React ID and checksum
|
||||
* (for generating static pages)
|
||||
* (for generating static pages)
|
||||
*/
|
||||
function renderComponentToStaticMarkup(element) {
|
||||
function renderToStaticMarkup(element) {
|
||||
invariant(
|
||||
ReactElement.isValidElement(element),
|
||||
'renderComponentToStaticMarkup(): You must pass a valid ReactElement.'
|
||||
'renderToStaticMarkup(): You must pass a valid ReactElement.'
|
||||
);
|
||||
|
||||
var transaction;
|
||||
@@ -78,6 +78,6 @@ function renderComponentToStaticMarkup(element) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
renderComponentToString: renderComponentToString,
|
||||
renderComponentToStaticMarkup: renderComponentToStaticMarkup
|
||||
renderToString: renderToString,
|
||||
renderToStaticMarkup: renderToStaticMarkup
|
||||
};
|
||||
|
||||
+38
-11
@@ -43,6 +43,7 @@ var ReactPropTypes = require('ReactPropTypes');
|
||||
var ReactServerRendering = require('ReactServerRendering');
|
||||
var ReactTextComponent = require('ReactTextComponent');
|
||||
|
||||
var deprecated = require('deprecated');
|
||||
var onlyChild = require('onlyChild');
|
||||
|
||||
ReactDefaultInjection.inject();
|
||||
@@ -63,6 +64,8 @@ createFactory = ReactLegacyElement.wrapCreateFactory(
|
||||
createFactory
|
||||
);
|
||||
|
||||
var render = ReactPerf.measure('React', 'render', ReactMount.render);
|
||||
|
||||
var React = {
|
||||
Children: {
|
||||
map: ReactChildren.map,
|
||||
@@ -76,22 +79,16 @@ var React = {
|
||||
EventPluginUtils.useTouchEvents = shouldUseTouch;
|
||||
},
|
||||
createClass: ReactCompositeComponent.createClass,
|
||||
createDescriptor: createElement, // deprecated, will be removed next week
|
||||
createElement: createElement,
|
||||
createFactory: createFactory,
|
||||
constructAndRenderComponent: ReactMount.constructAndRenderComponent,
|
||||
constructAndRenderComponentByID: ReactMount.constructAndRenderComponentByID,
|
||||
renderComponent: ReactPerf.measure(
|
||||
'React',
|
||||
'renderComponent',
|
||||
ReactMount.renderComponent
|
||||
),
|
||||
renderComponentToString: ReactServerRendering.renderComponentToString,
|
||||
renderComponentToStaticMarkup:
|
||||
ReactServerRendering.renderComponentToStaticMarkup,
|
||||
render: render,
|
||||
renderToString: ReactServerRendering.renderToString,
|
||||
renderToStaticMarkup: ReactServerRendering.renderToStaticMarkup,
|
||||
unmountComponentAtNode: ReactMount.unmountComponentAtNode,
|
||||
isValidClass: ReactLegacyElement.isValidFactory,
|
||||
isValidComponent: ReactElement.isValidElement,
|
||||
isValidElement: ReactElement.isValidElement,
|
||||
withContext: ReactContext.withContext,
|
||||
__internals: {
|
||||
Component: ReactComponent,
|
||||
@@ -102,7 +99,37 @@ var React = {
|
||||
Mount: ReactMount,
|
||||
MultiChild: ReactMultiChild,
|
||||
TextComponent: ReactTextComponent
|
||||
}
|
||||
},
|
||||
|
||||
// Deprecations (remove for 0.13)
|
||||
renderComponent: deprecated(
|
||||
'React',
|
||||
'renderComponent',
|
||||
'render',
|
||||
this,
|
||||
render
|
||||
),
|
||||
renderComponentToString: deprecated(
|
||||
'React',
|
||||
'renderComponentToString',
|
||||
'renderToString',
|
||||
this,
|
||||
ReactServerRendering.renderToString
|
||||
),
|
||||
renderComponentToStaticMarkup: deprecated(
|
||||
'React',
|
||||
'renderComponentToStaticMarkup',
|
||||
'renderToStaticMarkup',
|
||||
this,
|
||||
ReactServerRendering.renderToStaticMarkup
|
||||
),
|
||||
isValidComponent: deprecated(
|
||||
'React',
|
||||
'isValidComponent',
|
||||
'isValidElement',
|
||||
this,
|
||||
ReactElement.isValidElement
|
||||
)
|
||||
};
|
||||
|
||||
if (__DEV__) {
|
||||
|
||||
@@ -27,6 +27,7 @@ var ReactInstanceHandles = require('ReactInstanceHandles');
|
||||
var ReactPerf = require('ReactPerf');
|
||||
|
||||
var containsNode = require('containsNode');
|
||||
var deprecated = require('deprecated');
|
||||
var getReactRootElementInContainer = require('getReactRootElementInContainer');
|
||||
var instantiateReactComponent = require('instantiateReactComponent');
|
||||
var invariant = require('invariant');
|
||||
@@ -204,7 +205,7 @@ function findDeepestCachedAncestor(targetID) {
|
||||
* representative DOM elements and inserting them into a supplied `container`.
|
||||
* Any prior content inside `container` is destroyed in the process.
|
||||
*
|
||||
* ReactMount.renderComponent(
|
||||
* ReactMount.render(
|
||||
* component,
|
||||
* document.getElementById('container')
|
||||
* );
|
||||
@@ -340,7 +341,7 @@ var ReactMount = {
|
||||
* @param {?function} callback function triggered on completion
|
||||
* @return {ReactComponent} Component instance rendered in `container`.
|
||||
*/
|
||||
renderComponent: function(nextElement, container, callback) {
|
||||
render: function(nextElement, container, callback) {
|
||||
invariant(
|
||||
ReactElement.isValidElement(nextElement),
|
||||
'renderComponent(): Invalid component element.%s',
|
||||
@@ -401,7 +402,7 @@ var ReactMount = {
|
||||
*/
|
||||
constructAndRenderComponent: function(constructor, props, container) {
|
||||
var element = createElement(constructor, props);
|
||||
return ReactMount.renderComponent(element, container);
|
||||
return ReactMount.render(element, container);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -683,4 +684,13 @@ var ReactMount = {
|
||||
purgeID: purgeID
|
||||
};
|
||||
|
||||
// Deprecations (remove for 0.13)
|
||||
ReactMount.renderComponent = deprecated(
|
||||
'ReactMount',
|
||||
'renderComponent',
|
||||
'render',
|
||||
this,
|
||||
ReactMount.render
|
||||
);
|
||||
|
||||
module.exports = ReactMount;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright 2013-2014 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @providesModule deprecated
|
||||
*/
|
||||
|
||||
var warning = require('warning');
|
||||
|
||||
/**
|
||||
* This will log a single deprecation notice per function and forward the call
|
||||
* on to the new API.
|
||||
*
|
||||
* @param {string} namespace The namespace of the call, eg 'React'
|
||||
* @param {string} oldName The old function name, eg 'renderComponent'
|
||||
* @param {string} newName The new function name, eg 'render'
|
||||
* @param {*} ctx The context this forwarded call should run in
|
||||
* @param {function} fn The function to forward on to
|
||||
* @return {*} Will be the value as returned from `fn`
|
||||
*/
|
||||
function deprecated(namespace, oldName, newName, ctx, fn) {
|
||||
var warned = false;
|
||||
if (__DEV__) {
|
||||
var newFn = function() {
|
||||
warning(
|
||||
warned,
|
||||
`${namespace}.${oldName} will be deprecated in a future version. ` +
|
||||
`Use ${namespace}.${newName} instead.`
|
||||
);
|
||||
warned = true;
|
||||
return fn.apply(ctx, arguments);
|
||||
};
|
||||
newFn.displayName = `${namespace}_${oldName}`;
|
||||
return newFn;
|
||||
}
|
||||
|
||||
return fn;
|
||||
}
|
||||
|
||||
module.exports = deprecated;
|
||||
Reference in New Issue
Block a user