Files
react-native/Libraries/ReactNative/ReactNative.js
Sebastian Markbage 2eafcd45db 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
2016-04-09 04:18:25 -07:00

58 lines
1.5 KiB
JavaScript

/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule ReactNative
* @flow
*/
'use strict';
const ReactIsomorphic = require('ReactIsomorphic');
const ReactNativeImpl = require('ReactNativeImpl');
const warning = require('warning');
const ReactNative = { ...ReactNativeImpl };
const dedupe = {};
if (__DEV__) {
for (const key in ReactNativeImpl) {
Object.defineProperty(ReactNative, key, {
get: function() {
return ReactNativeImpl[key];
},
set: function(value) {
// Useful for hacky solutions like createExamplePage.
ReactNativeImpl[key] = value;
},
});
}
}
for (const key in ReactIsomorphic) {
ReactNative[key] = ReactIsomorphic[key];
if (__DEV__) {
Object.defineProperty(ReactNative, key, {
get: function() {
warning(
dedupe[key],
'ReactNative.' + key + ' is deprecated. Use React.' + key +
' from the "react" package instead.'
);
dedupe[key] = true;
return ReactIsomorphic[key];
},
set: function(value) {
// Useful for hacky solutions like createExamplePage.
ReactIsomorphic[key] = value;
},
});
}
}
module.exports = ReactNative;