瀏覽代碼

Encapsulate SceneHistory. A little. (#1016)

Kent Beck 5 年之前
父節點
當前提交
dc618ab122
共有 2 個文件被更改,包括 9 次插入12 次删除
  1. 1 4
      src/components/App.tsx
  2. 8 8
      src/history.ts

+ 1 - 4
src/components/App.tsx

@@ -2432,10 +2432,7 @@ export class App extends React.Component<any, AppState> {
       this.broadcastSceneUpdate();
     }
 
-    if (history.isRecording()) {
-      history.pushEntry(this.state, globalSceneState.getAllElements());
-      history.skipRecording();
-    }
+    history.record(this.state, globalSceneState.getAllElements());
   }
 }
 

+ 8 - 8
src/history.ts

@@ -123,17 +123,17 @@ export class SceneHistory {
     return null;
   }
 
-  isRecording() {
-    return this.recording;
-  }
-
-  skipRecording() {
-    this.recording = false;
-  }
-
+  // Suspicious that this is called so many places. Seems error-prone.
   resumeRecording() {
     this.recording = true;
   }
+
+  record(state: AppState, elements: readonly ExcalidrawElement[]) {
+    if (this.recording) {
+      this.pushEntry(state, elements);
+      this.recording = false;
+    }
+  }
 }
 
 export const createHistory: () => { history: SceneHistory } = () => {