1 | /**
|
2 | * Copyright (c) 2013-present, Facebook, Inc.
|
3 | *
|
4 | * This source code is licensed under the MIT license found in the
|
5 | * LICENSE file in the root directory of this source tree.
|
6 | *
|
7 | *
|
8 | */
|
9 |
|
10 | ;
|
11 |
|
12 | var _assign = require('object-assign');
|
13 |
|
14 | var lowPriorityWarning = require('./lowPriorityWarning');
|
15 |
|
16 | /**
|
17 | * This will log a single deprecation notice per function and forward the call
|
18 | * on to the new API.
|
19 | *
|
20 | * @param {string} fnName The name of the function
|
21 | * @param {string} newModule The module that fn will exist in
|
22 | * @param {string} newPackage The module that fn will exist in
|
23 | * @param {*} ctx The context this forwarded call should run in
|
24 | * @param {function} fn The function to forward on to
|
25 | * @return {function} The function that will warn once and then call fn
|
26 | */
|
27 | function deprecated(fnName, newModule, newPackage, ctx, fn) {
|
28 | var warned = false;
|
29 | if (process.env.NODE_ENV !== 'production') {
|
30 | var newFn = function () {
|
31 | lowPriorityWarning(warned,
|
32 | /* eslint-disable no-useless-concat */
|
33 | // Require examples in this string must be split to prevent React's
|
34 | // build tools from mistaking them for real requires.
|
35 | // Otherwise the build tools will attempt to build a '%s' module.
|
36 | 'React.%s is deprecated. Please use %s.%s from require' + "('%s') " + 'instead.', fnName, newModule, fnName, newPackage);
|
37 | /* eslint-enable no-useless-concat */
|
38 | warned = true;
|
39 | return fn.apply(ctx, arguments);
|
40 | };
|
41 | // We need to make sure all properties of the original fn are copied over.
|
42 | // In particular, this is needed to support PropTypes
|
43 | _assign(newFn, fn);
|
44 |
|
45 | // Flow is not smart enough to figure out that newFn is of the same type as
|
46 | // fn. Since we don't want to lose out the type of the function, casting
|
47 | // to any and force flow to use T.
|
48 | return newFn;
|
49 | }
|
50 |
|
51 | return fn;
|
52 | }
|
53 |
|
54 | module.exports = deprecated; |
\ | No newline at end of file |