Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81152 views
1
/**
2
* Copyright 2013-2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule deprecated
10
*/
11
12
var assign = require('Object.assign');
13
var warning = require('warning');
14
15
/**
16
* This will log a single deprecation notice per function and forward the call
17
* on to the new API.
18
*
19
* @param {string} namespace The namespace of the call, eg 'React'
20
* @param {string} oldName The old function name, eg 'renderComponent'
21
* @param {string} newName The new function name, eg 'render'
22
* @param {*} ctx The context this forwarded call should run in
23
* @param {function} fn The function to forward on to
24
* @return {*} Will be the value as returned from `fn`
25
*/
26
function deprecated(namespace, oldName, newName, ctx, fn) {
27
var warned = false;
28
if (__DEV__) {
29
var newFn = function() {
30
warning(
31
warned,
32
`${namespace}.${oldName} will be deprecated in a future version. ` +
33
`Use ${namespace}.${newName} instead.`
34
);
35
warned = true;
36
return fn.apply(ctx, arguments);
37
};
38
newFn.displayName = `${namespace}_${oldName}`;
39
// We need to make sure all properties of the original fn are copied over.
40
// In particular, this is needed to support PropTypes
41
return assign(newFn, fn);
42
}
43
44
return fn;
45
}
46
47
module.exports = deprecated;
48
49