Просмотр исходного кода

@uppy/core - avoid excessive setState()

Evgenia Karunus 5 лет назад
Родитель
Сommit
8f36b116ea
1 измененных файлов с 6 добавлено и 8 удалено
  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)
     })