Skip to content

Commit

Permalink
Add warnings to React module
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiebits committed Sep 1, 2015
1 parent b1e16b9 commit c04d02e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 57 deletions.
53 changes: 1 addition & 52 deletions packages/react/react.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,3 @@
/* eslint-disable comma-dangle */
'use strict';

var React = require('./lib/React');

var assign = require('./lib/Object.assign');
var deprecated = require('./lib/deprecated');

// We want to warn once when any of these methods are used.
if (process.env.NODE_ENV !== 'production') {
var deprecations = {
// ReactDOM
findDOMNode: deprecated(
'findDOMNode',
'react-dom',
React,
React.findDOMNode
),
render: deprecated(
'render',
'react-dom',
React,
React.render
),
unmountComponentAtNode: deprecated(
'unmountComponentAtNode',
'react-dom',
React,
React.unmountComponentAtNode
),
// ReactDOMServer
renderToString: deprecated(
'renderToString',
'react-dom/server',
React,
React.renderToString
),
renderToStaticMarkup: deprecated(
'renderToStaticMarkup',
'react-dom/server',
React,
React.renderToStaticMarkup
)
};
// Export a wrapped object. We'll use assign and take advantage of the fact
// that this will override the original methods in React.
module.exports = assign(
{},
React,
deprecations
);
} else {
module.exports = React;
}
module.exports = require('./lib/React');
44 changes: 42 additions & 2 deletions src/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,52 @@ var ReactDOMServer = require('ReactDOMServer');
var ReactIsomorphic = require('ReactIsomorphic');

var assign = require('Object.assign');
var deprecated = require('deprecated');

var React = {};

assign(React, ReactIsomorphic);
assign(React, ReactDOM);
assign(React, ReactDOMServer);

assign(React, {
// ReactDOM
findDOMNode: deprecated(
'findDOMNode',
'ReactDOM',
'react-dom',
ReactDOM,
ReactDOM.findDOMNode
),
render: deprecated(
'render',
'ReactDOM',
'react-dom',
ReactDOM,
ReactDOM.render
),
unmountComponentAtNode: deprecated(
'unmountComponentAtNode',
'ReactDOM',
'react-dom',
ReactDOM,
ReactDOM.unmountComponentAtNode
),

// ReactDOMServer
renderToString: deprecated(
'renderToString',
'ReactDOMServer',
'react-dom/server',
ReactDOMServer,
ReactDOMServer.renderToString
),
renderToStaticMarkup: deprecated(
'renderToStaticMarkup',
'ReactDOMServer',
'react-dom/server',
ReactDOMServer,
ReactDOMServer.renderToStaticMarkup
),
});

React.version = '0.14.0-beta3';

Expand Down
8 changes: 5 additions & 3 deletions src/shared/utils/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ var warning = require('warning');
*
* @param {string} fnName The name of the function
* @param {string} newModule The module that fn will exist in
* @param {string} newPackage The module that fn will exist in
* @param {*} ctx The context this forwarded call should run in
* @param {function} fn The function to forward on to
* @return {function} The function that will warn once and then call fn
*/
function deprecated(fnName, newModule, ctx, fn) {
function deprecated(fnName, newModule, newPackage, ctx, fn) {
var warned = false;
if (__DEV__) {
var newFn = function() {
Expand All @@ -33,11 +34,12 @@ function deprecated(fnName, newModule, ctx, fn) {
// Require examples in this string must be split to prevent React's
// build tools from mistaking them for real requires.
// Otherwise the build tools will attempt to build a '%s' module.
'`require' + '("react").%s` is deprecated. Please use `require' + '("%s").%s` ' +
'React.%s is deprecated. Please use %s.%s from require' + '(\'%s\') ' +
'instead.',
fnName,
newModule,
fnName
fnName,
newPackage
);
warned = true;
return fn.apply(ctx, arguments);
Expand Down

0 comments on commit c04d02e

Please sign in to comment.