react-native/Libraries/Utilities/deprecatedPropType.js
Janic Duplessis 1c6e837504 Add a deprecatedPropType module to show deprecation warnings
Summary:
To allow smoother API changes for users we often deprecate props and keep them around for a while before removing them. Right now it is all done manually, this adds a consistent way to show a warning when using a deprecated prop.

This also adds a deprecation warning of the website generated from the deprecatedPropType.

<img width="643" alt="screen shot 2016-01-26 at 7 43 08 pm" src="https://cloud.githubusercontent.com/assets/2677334/12600172/7af28fb0-c465-11e5-85e5-3786852bf522.png">

It also changes places where we added the warnings manually to use deprecatedPropType instead.
Closes https://github.com/facebook/react-native/pull/5566

Reviewed By: svcscm

Differential Revision: D2874629

Pulled By: nicklockwood

fb-gh-sync-id: c3c63bae7bbec26cc146029abd9aa5efbe73f795
2016-01-29 02:05:38 -08:00

34 lines
970 B
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 deprecatedPropType
* @flow
*/
'use strict';
const UIManager = require('UIManager');
/**
* Adds a deprecation warning when the prop is used.
*/
function deprecatedPropType(
propType: ReactPropsCheckType,
explanation: string
): ReactPropsCheckType {
return function validate(props, propName, componentName) {
// Don't warn for native components.
if (!UIManager[componentName] && props[propName] !== undefined) {
console.warn(`\`${propName}\` supplied to \`${componentName}\` has been deprecated. ${explanation}`);
}
return propType(props, propName, componentName);
};
}
module.exports = deprecatedPropType;