0c536374a91fa489c015c557b750437d197e7016217b520a71f5f4c848fac3cac4f786f818529524341ffbb9e44d29274b0312255c94e35421ab1f57533f0b 1.9 KB

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