replace blocks timeout with a promise

The timeout as a promise lets us update the toolbox during the same
render as the workspace so that the screen updates all together. This
also means the toolbox will update before the loading screen is
dismissed after loading, letting us avoid a second flash for the
toolbox to update.
This commit is contained in:
Michael "Z" Goddard committed 2019-04-30 16:36:52 -04:00
1 parent 866af2f766
commit d83ec5a0b5
1 file changed
+11 -5
+11 -5
View File
@@ -180,13 +180,19 @@ class Blocks extends React.Component {
componentWillUnmount () {
this.detachVM();
this.workspace.dispose();
clearTimeout(this.toolboxUpdateTimeout);
if (this.toolboxUpdateTimeout) this.toolboxUpdateTimeout.cancel();
}
requestToolboxUpdate () {
clearTimeout(this.toolboxUpdateTimeout);
this.toolboxUpdateTimeout = setTimeout(() => {
this.updateToolbox();
}, 0);
if (this.toolboxUpdateTimeout) this.toolboxUpdateTimeout.cancel();
let running = true;
this.toolboxUpdateTimeout = Promise.resolve().then(() => {
if (running) {
this.updateToolbox();
}
});
this.toolboxUpdateTimeout.cancel = () => {
running = false;
};
}
setLocale () {
this.ScratchBlocks.ScratchMsgs.setLocale(this.props.locale);