6594d7523d0e099c2fe9ca1e81161f2d72a4045957812662b979db2981eb078d6e9434b2d287fdf4f32d03a880fdf42dbad63e5892f8f32c1c8e279f36b0ba 1.6 KB

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