feat: support updating appState in updateScene API (#3576)

* feat: support updating appState in updateScene API

* make `updateScene.data.appState` more type-safe

* restore `appState` when passing to `updateScene`

* fix

Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
Aakansha Doshi 2021-05-14 17:52:56 +05:30 committed by GitHub
parent f1cf28a84e
commit 78da4c075e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 21 deletions

View file

@ -1458,26 +1458,30 @@ class App extends React.Component<AppProps, AppState> {
}
};
public updateScene = withBatchedUpdates((sceneData: SceneData) => {
if (sceneData.commitToHistory) {
this.history.resumeRecording();
}
public updateScene = withBatchedUpdates(
<K extends keyof AppState>(sceneData: {
elements?: SceneData["elements"];
appState?: Pick<AppState, K> | null;
collaborators?: SceneData["collaborators"];
commitToHistory?: SceneData["commitToHistory"];
}) => {
if (sceneData.commitToHistory) {
this.history.resumeRecording();
}
// currently we only support syncing background color
if (sceneData.appState?.viewBackgroundColor) {
this.setState({
viewBackgroundColor: sceneData.appState.viewBackgroundColor,
});
}
if (sceneData.appState) {
this.setState(sceneData.appState);
}
if (sceneData.elements) {
this.scene.replaceAllElements(sceneData.elements);
}
if (sceneData.elements) {
this.scene.replaceAllElements(sceneData.elements);
}
if (sceneData.collaborators) {
this.setState({ collaborators: sceneData.collaborators });
}
});
if (sceneData.collaborators) {
this.setState({ collaborators: sceneData.collaborators });
}
},
);
private onSceneUpdated = () => {
this.setState({});