debug.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 (
  13. !(typeof console !== "undefined" && console !== null
  14. ? console.time
  15. : undefined) ||
  16. !console.groupCollapsed
  17. ) {
  18. return;
  19. }
  20. //
  21. // App
  22. //
  23. const _init = app.init;
  24. app.init = function () {
  25. console.time("Init");
  26. _init.call(app);
  27. console.timeEnd("Init");
  28. return console.time("Load");
  29. };
  30. const _start = app.start;
  31. app.start = function () {
  32. console.timeEnd("Load");
  33. console.time("Start");
  34. _start.call(app, ...arguments);
  35. return console.timeEnd("Start");
  36. };
  37. //
  38. // Searcher
  39. //
  40. const _super = app.Searcher;
  41. const _proto = app.Searcher.prototype;
  42. app.Searcher = function () {
  43. _super.apply(this, arguments);
  44. const _setup = this.setup.bind(this);
  45. this.setup = function () {
  46. console.groupCollapsed(`Search: ${this.query}`);
  47. console.time("Total");
  48. return _setup();
  49. };
  50. const _match = this.match.bind(this);
  51. this.match = () => {
  52. if (this.matcher) {
  53. console.timeEnd(this.matcher.name);
  54. }
  55. return _match();
  56. };
  57. const _setupMatcher = this.setupMatcher.bind(this);
  58. this.setupMatcher = function () {
  59. console.time(this.matcher.name);
  60. return _setupMatcher();
  61. };
  62. const _end = this.end.bind(this);
  63. this.end = function () {
  64. console.log(`Results: ${this.totalResults}`);
  65. console.timeEnd("Total");
  66. console.groupEnd();
  67. return _end();
  68. };
  69. const _kill = this.kill.bind(this);
  70. this.kill = function () {
  71. if (this.timeout) {
  72. if (this.matcher) {
  73. console.timeEnd(this.matcher.name);
  74. }
  75. console.groupEnd();
  76. console.timeEnd("Total");
  77. console.warn("Killed");
  78. }
  79. return _kill();
  80. };
  81. };
  82. $.extend(app.Searcher, _super);
  83. _proto.constructor = app.Searcher;
  84. app.Searcher.prototype = _proto;
  85. //
  86. // View tree
  87. //
  88. this.viewTree = function (view, level, visited) {
  89. if (view == null) {
  90. view = app.document;
  91. }
  92. if (level == null) {
  93. level = 0;
  94. }
  95. if (visited == null) {
  96. visited = [];
  97. }
  98. if (visited.indexOf(view) >= 0) {
  99. return;
  100. }
  101. visited.push(view);
  102. console.log(
  103. `%c ${Array(level + 1).join(" ")}${
  104. view.constructor.name
  105. }: ${!!view.activated}`,
  106. "color:" + ((view.activated && "green") || "red"),
  107. );
  108. for (var key of Object.keys(view || {})) {
  109. var value = view[key];
  110. if (key !== "view" && value) {
  111. if (typeof value === "object" && value.setupElement) {
  112. this.viewTree(value, level + 1, visited);
  113. } else if (value.constructor.toString().match(/Object\(\)/)) {
  114. for (var k of Object.keys(value || {})) {
  115. var v = value[k];
  116. if (v && typeof v === "object" && v.setupElement) {
  117. this.viewTree(v, level + 1, visited);
  118. }
  119. }
  120. }
  121. }
  122. }
  123. };