mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-12 03:35:30 +08:00
Add deprecation warnings for split of the react and react-native packages
Summary:This adds deprecation warnings that correspond to what React 0.14 did for the web. I.e. `React.render` -> `ReactNative.render` but also `ReactNative.createClass` -> `React.createClass`. This hopefully means that it will become easier and more idiomatic to write components that are decoupled from the react-native package. It will be clear when you take on react-native as a dependency such as when using findNodeHandle. This codemod is a little more invasive for React Native because the common stuff often used the `react-native` package. For web only the uncommon stuff needed to move. Reviewed By: spicyj Differential Revision: D3148860 fb-gh-sync-id: d87628d2089a2e012ad6ad50dd0a20ccec5e6c45 fbshipit-source-id: d87628d2089a2e012ad6ad50dd0a20ccec5e6c45
This commit is contained in:
committed by
Facebook Github Bot 2
parent
a80dd9a92a
commit
2eafcd45db
@@ -11,4 +11,33 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
module.exports = require('ReactNative');
|
||||
const ReactIsomorphic = require('ReactIsomorphic');
|
||||
const ReactNativeImpl = require('ReactNativeImpl');
|
||||
const warning = require('warning');
|
||||
|
||||
const React = { ...ReactIsomorphic };
|
||||
|
||||
const dedupe = {};
|
||||
|
||||
for (const key in ReactNativeImpl) {
|
||||
React[key] = ReactNativeImpl[key];
|
||||
if (__DEV__) {
|
||||
Object.defineProperty(React, key, {
|
||||
get: function() {
|
||||
warning(
|
||||
dedupe[key],
|
||||
'React.' + key + ' is deprecated. Use ReactNative.' + key +
|
||||
' from the "react-native" package instead.'
|
||||
);
|
||||
dedupe[key] = true;
|
||||
return ReactNativeImpl[key];
|
||||
},
|
||||
set: function(value) {
|
||||
// Useful for hacky solutions like createExamplePage.
|
||||
ReactNativeImpl[key] = value;
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = React;
|
||||
|
||||
Reference in New Issue
Block a user