refactor: deferred React render

This commit is contained in:
cha0s 2019-05-25 08:46:20 -05:00
parent bba6c64410
commit a4b33ba3b9

View File

@ -256,10 +256,11 @@ export class App extends decorate(class {}) {
onPacket(packet) {
if (!this.hasReceivedState) {
this.renderIntoDom(document.querySelector('.app'));
this.startProcessingInput();
this.startSimulation();
this.startRendering();
this.renderIntoDom(document.querySelector('.app')).then(() => {
this.startProcessingInput();
this.startSimulation();
this.startRendering();
});
this.hasReceivedState = true;
}
if (packet instanceof BundlePacket) {
@ -439,13 +440,24 @@ export class App extends decorate(class {}) {
this.reactContainer = this.createReactContainer();
this.stage.ui.appendChild(this.reactContainer);
const UiComponent = <Ui app={this} />;
ReactDOM.render(UiComponent, this.reactContainer, () => {
this.stage.flushUiElements();
});
// Debug UI.
this.debugUiNode = node.querySelector('.debug-container');
const DebugUiComponent = <DebugUi app={this} />;
ReactDOM.render(DebugUiComponent, this.debugUiNode);
// Deferred render.
return Promise.all([
promise,
new Promise((resolve) => {
ReactDOM.render(UiComponent, this.reactContainer, () => {
this.stage.flushUiElements();
resolve();
});
}),
new Promise((resolve) => {
ReactDOM.render(DebugUiComponent, this.debugUiNode, () => {
resolve();
});
}),
]);
}
setActiveSlotIndex(slotIndex) {