瀏覽代碼

move debug helpers to app.tsx

dwelle 3 年之前
父節點
當前提交
d731a6463c
共有 2 個文件被更改,包括 47 次插入47 次删除
  1. 47 0
      src/components/App.tsx
  2. 0 47
      src/excalidraw-app/index.tsx

+ 47 - 0
src/components/App.tsx

@@ -264,6 +264,53 @@ import {
 } from "../element/Hyperlink";
 } from "../element/Hyperlink";
 import { shouldShowBoundingBox } from "../element/transformHandles";
 import { shouldShowBoundingBox } from "../element/transformHandles";
 
 
+const TIMES_AGGR: Record<string, { t: number; times: number[] }> = {};
+const TIMES_AVG: Record<string, { times: number[] }> = {};
+
+window.DEBUG_LOG_TIMES = true;
+
+setInterval(() => {
+  if (window.DEBUG_LOG_TIMES) {
+    for (const [name, { t, times }] of Object.entries(TIMES_AGGR)) {
+      if (times.length) {
+        console.info(
+          name,
+          times.reduce((a, b) => a + b),
+          times.sort((a, b) => a - b),
+        );
+        TIMES_AGGR[name] = { t, times: [] };
+      }
+    }
+    for (const [name, { times }] of Object.entries(TIMES_AVG)) {
+      if (times.length) {
+        console.info(
+          name,
+          parseFloat(
+            (times.reduce((a, b) => a + b) / times.length).toPrecision(5),
+          ),
+          times.sort((a, b) => a - b),
+        );
+        TIMES_AVG[name] = { times: [] };
+      }
+    }
+  }
+}, 1000);
+
+window.logTime = (name: string, time?: number) => {
+  const { t, times } = (TIMES_AGGR[name] = TIMES_AGGR[name] || {
+    t: 0,
+    times: [],
+  });
+  if (t) {
+    times.push(time != null ? time : Date.now() - t);
+  }
+  TIMES_AGGR[name].t = Date.now();
+};
+window.logTimeAverage = (name: string, time: number) => {
+  const { times } = (TIMES_AVG[name] = TIMES_AVG[name] || { times: [] });
+  times.push(time);
+};
+
 const deviceContextInitialValue = {
 const deviceContextInitialValue = {
   isSmScreen: false,
   isSmScreen: false,
   isMobile: false,
   isMobile: false,

+ 0 - 47
src/excalidraw-app/index.tsx

@@ -84,53 +84,6 @@ import { jotaiStore, useAtomWithInitialValue } from "../jotai";
 import { reconcileElements } from "./collab/reconciliation";
 import { reconcileElements } from "./collab/reconciliation";
 import { parseLibraryTokensFromUrl, useHandleLibrary } from "../data/library";
 import { parseLibraryTokensFromUrl, useHandleLibrary } from "../data/library";
 
 
-const TIMES_AGGR: Record<string, { t: number; times: number[] }> = {};
-const TIMES_AVG: Record<string, { times: number[] }> = {};
-
-window.DEBUG_LOG_TIMES = true;
-
-setInterval(() => {
-  if (window.DEBUG_LOG_TIMES) {
-    for (const [name, { t, times }] of Object.entries(TIMES_AGGR)) {
-      if (times.length) {
-        console.info(
-          name,
-          times.reduce((a, b) => a + b),
-          times.sort((a, b) => a - b),
-        );
-        TIMES_AGGR[name] = { t, times: [] };
-      }
-    }
-    for (const [name, { times }] of Object.entries(TIMES_AVG)) {
-      if (times.length) {
-        console.info(
-          name,
-          parseFloat(
-            (times.reduce((a, b) => a + b) / times.length).toPrecision(5),
-          ),
-          times.sort((a, b) => a - b),
-        );
-        TIMES_AVG[name] = { times: [] };
-      }
-    }
-  }
-}, 1000);
-
-window.logTime = (name: string, time?: number) => {
-  const { t, times } = (TIMES_AGGR[name] = TIMES_AGGR[name] || {
-    t: 0,
-    times: [],
-  });
-  if (t) {
-    times.push(time != null ? time : Date.now() - t);
-  }
-  TIMES_AGGR[name].t = Date.now();
-};
-window.logTimeAverage = (name: string, time: number) => {
-  const { times } = (TIMES_AVG[name] = TIMES_AVG[name] || { times: [] });
-  times.push(time);
-};
-
 polyfill();
 polyfill();
 window.EXCALIDRAW_THROTTLE_RENDER = true;
 window.EXCALIDRAW_THROTTLE_RENDER = true;