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:
1 file changed
+11
-5
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user