forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeprecated.js
More file actions
49 lines (44 loc) · 1.5 KB
/
deprecated.js
File metadata and controls
49 lines (44 loc) · 1.5 KB
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
/**
* Copyright 2013-2014, 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 deprecated
*/
"use strict";
var assign = require('Object.assign');
var warning = require('warning');
/**
* This will log a single deprecation notice per function and forward the call
* on to the new API.
*
* @param {string} namespace The namespace of the call, eg 'React'
* @param {string} oldName The old function name, eg 'renderComponent'
* @param {string} newName The new function name, eg 'render'
* @param {*} ctx The context this forwarded call should run in
* @param {function} fn The function to forward on to
* @return {*} Will be the value as returned from `fn`
*/
function deprecated(namespace, oldName, newName, ctx, fn) {
var warned = false;
if (__DEV__) {
var newFn = function() {
warning(
warned,
`${namespace}.${oldName} will be deprecated in a future version. ` +
`Use ${namespace}.${newName} instead.`
);
warned = true;
return fn.apply(ctx, arguments);
};
newFn.displayName = `${namespace}_${oldName}`;
// We need to make sure all properties of the original fn are copied over.
// In particular, this is needed to support PropTypes
return assign(newFn, fn);
}
return fn;
}
module.exports = deprecated;