debug.js 3.0 KB

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