Prechádzať zdrojové kódy

@uppy/core - avoid excessive setState()

Evgenia Karunus 5 rokov pred
rodič
commit
8f36b116ea
1 zmenil súbory, kde vykonal 6 pridanie a 8 odobranie
  1. 6 8
      packages/@uppy/core/src/index.js

+ 6 - 8
packages/@uppy/core/src/index.js

@@ -553,16 +553,14 @@ class Uppy {
 
     this.setState({
       currentUploads: updatedUploads,
-      files: updatedFiles
+      files: updatedFiles,
+      ...(
+        // If this is the last file we just removed - allow new uploads!
+        Object.keys(updatedFiles).length === 0 &&
+        { allowNewUpload: true }
+      )
     })
 
-    // If nothing is uploading anymore, and if nothing has uploaded yet - allow new uploads!
-    if (Object.keys(updatedFiles).length === 0) {
-      this.setState({
-        allowNewUpload: true
-      })
-    }
-
     removeUploads.forEach((uploadID) => {
       this._removeUpload(uploadID)
     })