forked from aweary/react-is-deprecated
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdist.js
57 lines (50 loc) · 1.82 KB
/
dist.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.deprecate = deprecate;
exports.addIsDeprecated = addIsDeprecated;
/**
* Wraps a singular React.PropTypes.[type] with
* a console.warn call that is only called if the
* prop is not undefined/null and is only called
* once.
* @param {Object} propType React.PropType type
* @param {String} message Deprecation message
* @return {Function} ReactPropTypes checkType
*/
function deprecate(propType, message) {
var warned = false;
return function () {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var props = args[0],
propName = args[1];
var prop = props[propName];
if (prop !== undefined && prop !== null && !warned) {
warned = true;
console.warn(message);
}
return propType.call.apply(propType, [this].concat(args));
};
}
/**
* Returns a copy of `PropTypes` with an `isDeprecated`
* method available on all top-level propType options.
* @param {React.PropTypes} PropTypes
* @return {React.PropTypes} newPropTypes
*/
function addIsDeprecated(PropTypes) {
var newPropTypes = _extends({}, PropTypes);
for (var type in newPropTypes) {
if (newPropTypes.hasOwnProperty(type) && newPropTypes[type].constructor === Function) {
var propType = newPropTypes[type];
propType = propType.bind(newPropTypes);
propType.isDeprecated = deprecate.bind(newPropTypes, propType);
newPropTypes[type] = propType;
}
}
return newPropTypes;
}