From dc618ab12249aac9dadf757ca9c10540e3ebcf5f Mon Sep 17 00:00:00 2001 From: Kent Beck Date: Fri, 20 Mar 2020 10:45:30 -0700 Subject: [PATCH] Encapsulate SceneHistory. A little. (#1016) --- src/components/App.tsx | 5 +---- src/history.ts | 16 ++++++++-------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index 40587128..4f6676f5 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -2432,10 +2432,7 @@ export class App extends React.Component { this.broadcastSceneUpdate(); } - if (history.isRecording()) { - history.pushEntry(this.state, globalSceneState.getAllElements()); - history.skipRecording(); - } + history.record(this.state, globalSceneState.getAllElements()); } } diff --git a/src/history.ts b/src/history.ts index a714a936..35581c90 100644 --- a/src/history.ts +++ b/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 } = () => {