mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Make data restoration functions immutable
- Make mutations in App component
This commit is contained in:
parent
2ef809fe5d
commit
642a11e380
2 changed files with 63 additions and 39 deletions
|
@ -106,10 +106,16 @@ export class App extends React.Component<{}, AppState> {
|
|||
document.addEventListener("keydown", this.onKeyDown, false);
|
||||
window.addEventListener("resize", this.onResize, false);
|
||||
|
||||
const appState = restoreFromLocalStorage(elements);
|
||||
const { elements: newElements, appState } = restoreFromLocalStorage();
|
||||
|
||||
if (newElements) {
|
||||
elements = newElements;
|
||||
}
|
||||
|
||||
if (appState) {
|
||||
this.setState(appState);
|
||||
} else {
|
||||
this.forceUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -512,7 +518,10 @@ export class App extends React.Component<{}, AppState> {
|
|||
}
|
||||
onSaveScene={() => saveAsJSON(elements, this.state.name)}
|
||||
onLoadScene={() =>
|
||||
loadFromJSON(elements).then(() => this.forceUpdate())
|
||||
loadFromJSON().then(({ elements: newElements }) => {
|
||||
elements = newElements;
|
||||
this.forceUpdate();
|
||||
})
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue