From f3dbddcf2bdc0e4f49dd6f5220360b5ff383e16f Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Wed, 26 Apr 2017 09:51:19 -0700 Subject: [PATCH] BREAKING - Remove React forwarding and wrong import warnings Summary: Importing `react` modules from `react-native` has been deprecated since 0.25 so I think it's safe to remove it now since everyone has migrated their code and it is now well know and documented that you import from different packages. This finishes the spring cleanup of `react-native-implementation.js` :) **Test plan** Tested that UIExplorer still works. Closes https://github.com/facebook/react-native/pull/13354 Reviewed By: bvaughn Differential Revision: D4928785 Pulled By: javache fbshipit-source-id: 38c623c309b06b2cb5e73074833342d2745ab198 --- Libraries/Utilities/throwOnWrongReactAPI.js | 32 --------------- .../react-native-implementation.js | 39 ------------------- 2 files changed, 71 deletions(-) delete mode 100644 Libraries/Utilities/throwOnWrongReactAPI.js diff --git a/Libraries/Utilities/throwOnWrongReactAPI.js b/Libraries/Utilities/throwOnWrongReactAPI.js deleted file mode 100644 index 4685a4071..000000000 --- a/Libraries/Utilities/throwOnWrongReactAPI.js +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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 throwOnWrongReactAPI - * @flow - */ - -'use strict'; - -function throwOnWrongReactAPI(key: string) { - throw new Error( -`Seems you're trying to access 'ReactNative.${key}' from the 'react-native' package. Perhaps you meant to access 'React.${key}' from the 'react' package instead? - -For example, instead of: - - import React, { Component, View } from 'react-native'; - -You should now do: - - import React, { Component } from 'react'; - import { View } from 'react-native'; - -Check the release notes on how to upgrade your code - https://github.com/facebook/react-native/releases/tag/v0.25.1 -`); -} - -module.exports = throwOnWrongReactAPI; diff --git a/Libraries/react-native/react-native-implementation.js b/Libraries/react-native/react-native-implementation.js index e38853640..e836ee7e1 100644 --- a/Libraries/react-native/react-native-implementation.js +++ b/Libraries/react-native/react-native-implementation.js @@ -124,43 +124,4 @@ const ReactNative = { }, }; -// Better error messages when accessing React APIs on ReactNative -if (__DEV__) { - const throwOnWrongReactAPI = require('throwOnWrongReactAPI'); - const reactAPIs = [ 'createClass', 'Component' ]; - - for (const key of reactAPIs) { - Object.defineProperty(ReactNative, key, { - get() { throwOnWrongReactAPI(key); }, - enumerable: false, - configurable: false, - }); - } -} - -// Preserve getters with warnings on the internal ReactNative copy without -// invoking them. -const ReactNativeInternal = require('ReactNative'); -function applyForwarding(key) { - if (__DEV__) { - Object.defineProperty( - ReactNative, - key, - Object.getOwnPropertyDescriptor(ReactNativeInternal, key) - ); - return; - } - if (ReactNative.hasOwnProperty(key)) { - // WARNING! ReactNative has read-only keys. So, if ReactNativeInternal - // has any duplicate key that ReactNative already has, this assignment - // would fail with "Attempted to assign to readonly property." - // So, if the key already exists on ReactNative, we assume that it's the - // correct module and skip re-assigning it. - return; - } - ReactNative[key] = ReactNativeInternal[key]; -} -for (const key in ReactNativeInternal) { - applyForwarding(key); -} module.exports = ReactNative;