From d83ec5a0b5bafdff7807e2680baf9dd3fb8fcef7 Mon Sep 17 00:00:00 2001 From: "Michael \"Z\" Goddard" Date: Tue, 30 Apr 2019 10:37:43 -0400 Subject: [PATCH] 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. --- src/containers/blocks.jsx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/containers/blocks.jsx b/src/containers/blocks.jsx index c366da458..694c50cbd 100644 --- a/src/containers/blocks.jsx +++ b/src/containers/blocks.jsx @@ -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);