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