debug.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // App
  3. //
  4. const _init = app.init;
  5. app.init = function () {
  6. console.time("Init");
  7. _init.call(app);
  8. console.timeEnd("Init");
  9. return console.time("Load");
  10. };
  11. const _start = app.start;
  12. app.start = function () {
  13. console.timeEnd("Load");
  14. console.time("Start");
  15. _start.call(app, ...arguments);
  16. return console.timeEnd("Start");
  17. };
  18. //
  19. // Searcher
  20. //
  21. app.Searcher = class TimingSearcher extends app.Searcher {
  22. setup() {
  23. console.groupCollapsed(`Search: ${this.query}`);
  24. console.time("Total");
  25. return super.setup();
  26. }
  27. match() {
  28. if (this.matcher) {
  29. console.timeEnd(this.matcher.name);
  30. }
  31. return super.match();
  32. }
  33. setupMatcher() {
  34. console.time(this.matcher.name);
  35. return super.setupMatcher();
  36. }
  37. end() {
  38. console.log(`Results: ${this.totalResults}`);
  39. console.timeEnd("Total");
  40. console.groupEnd();
  41. return super.end();
  42. }
  43. kill() {
  44. if (this.timeout) {
  45. if (this.matcher) {
  46. console.timeEnd(this.matcher.name);
  47. }
  48. console.groupEnd();
  49. console.timeEnd("Total");
  50. console.warn("Killed");
  51. }
  52. return super.kill();
  53. }
  54. };
  55. //
  56. // View tree
  57. //
  58. this.viewTree = function (view, level, visited) {
  59. if (view == null) {
  60. view = app.document;
  61. }
  62. if (level == null) {
  63. level = 0;
  64. }
  65. if (visited == null) {
  66. visited = [];
  67. }
  68. if (visited.includes(view)) {
  69. return;
  70. }
  71. visited.push(view);
  72. console.log(
  73. `%c ${Array(level + 1).join(" ")}${
  74. view.constructor.name
  75. }: ${!!view.activated}`,
  76. "color:" + ((view.activated && "green") || "red"),
  77. );
  78. for (var key of Object.keys(view || {})) {
  79. var value = view[key];
  80. if (key !== "view" && value) {
  81. if (typeof value === "object" && value.setupElement) {
  82. this.viewTree(value, level + 1, visited);
  83. } else if (value.constructor.toString().match(/Object\(\)/)) {
  84. for (var k of Object.keys(value || {})) {
  85. var v = value[k];
  86. if (v && typeof v === "object" && v.setupElement) {
  87. this.viewTree(v, level + 1, visited);
  88. }
  89. }
  90. }
  91. }
  92. }
  93. };