Prevent re-assignment of elements (#121)

This commit is contained in:
Christopher Chedeau 2020-01-04 10:48:23 -08:00 committed by GitHub
parent 25aabdc4d1
commit bd86f819df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,7 +26,7 @@ type ExcalidrawTextElement = ExcalidrawElement & {
const LOCAL_STORAGE_KEY = "excalidraw";
const LOCAL_STORAGE_KEY_STATE = "excalidraw-state";
let elements = Array.of<ExcalidrawElement>();
const elements = Array.of<ExcalidrawElement>();
// https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript/47593316#47593316
const LCG = (seed: number) => () =>
@ -582,13 +582,13 @@ function restore() {
const savedState = localStorage.getItem(LOCAL_STORAGE_KEY_STATE);
if (savedElements) {
elements = JSON.parse(savedElements);
elements.splice(0, elements.length, ...JSON.parse(savedElements));
elements.forEach((element: ExcalidrawElement) => generateDraw(element));
}
return savedState ? JSON.parse(savedState) : null;
} catch (e) {
elements = [];
elements.splice(0, elements.length);
return null;
}
}
@ -783,7 +783,7 @@ class App extends React.Component<{}, AppState> {
private clearCanvas = () => {
if (window.confirm("This will clear the whole canvas. Are you sure?")) {
elements = [];
elements.splice(0, elements.length);
this.setState({
viewBackgroundColor: "#ffffff",
scrollX: 0,