1import extend from './extend';
2import { hooks } from './hooks';
3import hasOwnProp from './has-own-prop';
4
5function warn(msg) {
6 if (
7 hooks.suppressDeprecationWarnings === false &&
8 typeof console !== 'undefined' &&
9 console.warn
10 ) {
11 console.warn('Deprecation warning: ' + msg);
12 }
13}
14
15export function deprecate(msg, fn) {
16 var firstTime = true;
17
18 return extend(function () {
19 if (hooks.deprecationHandler != null) {
20 hooks.deprecationHandler(null, msg);
21 }
22 if (firstTime) {
23 var args = [],
24 arg,
25 i,
26 key,
27 argLen = arguments.length;
28 for (i = 0; i < argLen; i++) {
29 arg = '';
30 if (typeof arguments[i] === 'object') {
31 arg += '\n[' + i + '] ';
32 for (key in arguments[0]) {
33 if (hasOwnProp(arguments[0], key)) {
34 arg += key + ': ' + arguments[0][key] + ', ';
35 }
36 }
37 arg = arg.slice(0, -2); // Remove trailing comma and space
38 } else {
39 arg = arguments[i];
40 }
41 args.push(arg);
42 }
43 warn(
44 msg +
45 '\nArguments: ' +
46 Array.prototype.slice.call(args).join('') +
47 '\n' +
48 new Error().stack
49 );
50 firstTime = false;
51 }
52 return fn.apply(this, arguments);
53 }, fn);
54}
55
56var deprecations = {};
57
58export function deprecateSimple(name, msg) {
59 if (hooks.deprecationHandler != null) {
60 hooks.deprecationHandler(name, msg);
61 }
62 if (!deprecations[name]) {
63 warn(msg);
64 deprecations[name] = true;
65 }
66}
67
68hooks.suppressDeprecationWarnings = false;
69hooks.deprecationHandler = null;