debug.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // TODO: This file was created by bulk-decaffeinate.
  2. // Sanity-check the conversion and remove this comment.
  3. /*
  4. * decaffeinate suggestions:
  5. * DS102: Remove unnecessary code created because of implicit returns
  6. * DS203: Remove `|| {}` from converted for-own loops
  7. * DS207: Consider shorter variations of null checks
  8. * DS208: Avoid top-level this
  9. * DS209: Avoid top-level return
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
  11. */
  12. if (!(typeof console !== 'undefined' && console !== null ? console.time : undefined) || !console.groupCollapsed) { return; }
  13. //
  14. // App
  15. //
  16. const _init = app.init;
  17. app.init = function() {
  18. console.time('Init');
  19. _init.call(app);
  20. console.timeEnd('Init');
  21. return console.time('Load');
  22. };
  23. const _start = app.start;
  24. app.start = function() {
  25. console.timeEnd('Load');
  26. console.time('Start');
  27. _start.call(app, ...arguments);
  28. return console.timeEnd('Start');
  29. };
  30. //
  31. // Searcher
  32. //
  33. const _super = app.Searcher;
  34. const _proto = app.Searcher.prototype;
  35. app.Searcher = function() {
  36. _super.apply(this, arguments);
  37. const _setup = this.setup.bind(this);
  38. this.setup = function() {
  39. console.groupCollapsed(`Search: ${this.query}`);
  40. console.time('Total');
  41. return _setup();
  42. };
  43. const _match = this.match.bind(this);
  44. this.match = () => {
  45. if (this.matcher) { console.timeEnd(this.matcher.name); }
  46. return _match();
  47. };
  48. const _setupMatcher = this.setupMatcher.bind(this);
  49. this.setupMatcher = function() {
  50. console.time(this.matcher.name);
  51. return _setupMatcher();
  52. };
  53. const _end = this.end.bind(this);
  54. this.end = function() {
  55. console.log(`Results: ${this.totalResults}`);
  56. console.timeEnd('Total');
  57. console.groupEnd();
  58. return _end();
  59. };
  60. const _kill = this.kill.bind(this);
  61. this.kill = function() {
  62. if (this.timeout) {
  63. if (this.matcher) { console.timeEnd(this.matcher.name); }
  64. console.groupEnd();
  65. console.timeEnd('Total');
  66. console.warn('Killed');
  67. }
  68. return _kill();
  69. };
  70. };
  71. $.extend(app.Searcher, _super);
  72. _proto.constructor = app.Searcher;
  73. app.Searcher.prototype = _proto;
  74. //
  75. // View tree
  76. //
  77. this.viewTree = function(view, level, visited) {
  78. if (view == null) { view = app.document; }
  79. if (level == null) { level = 0; }
  80. if (visited == null) { visited = []; }
  81. if (visited.indexOf(view) >= 0) { return; }
  82. visited.push(view);
  83. console.log(`%c ${Array(level + 1).join(' ')}${view.constructor.name}: ${!!view.activated}`,
  84. 'color:' + ((view.activated && 'green') || 'red'));
  85. for (var key of Object.keys(view || {})) {
  86. var value = view[key];
  87. if ((key !== 'view') && value) {
  88. if ((typeof value === 'object') && value.setupElement) {
  89. this.viewTree(value, level + 1, visited);
  90. } else if (value.constructor.toString().match(/Object\(\)/)) {
  91. for (var k of Object.keys(value || {})) { var v = value[k]; if (v && (typeof v === 'object') && v.setupElement) { this.viewTree(v, level + 1, visited); } }
  92. }
  93. }
  94. }
  95. };