Browse Source

Merge pull request #226 from transloadit/feature/reset

Add simple reset() method to core that clears files and totalProgress
Artur Paikin 7 years ago
parent
commit
31cb86e0b2
1 changed files with 13 additions and 4 deletions
  1. 13 4
      src/core/Core.js

+ 13 - 4
src/core/Core.js

@@ -101,6 +101,14 @@ class Uppy {
     return this.state
   }
 
+  reset () {
+    this.emit('core:pause-all')
+    this.emit('core:cancel-all')
+    this.setState({
+      totalProgress: 0
+    })
+  }
+
   addPreProcessor (fn) {
     this.preProcessors.push(fn)
   }
@@ -292,10 +300,9 @@ class Uppy {
     })
 
     this.on('core:cancel-all', () => {
-      const files = this.getState().files
-      Object.keys(files).forEach((file) => {
-        this.removeFile(files[file].id)
-      })
+      let updatedFiles = this.getState().files
+      updatedFiles = {}
+      this.setState({files: updatedFiles})
     })
 
     this.on('core:upload-started', (fileID, upload) => {
@@ -508,6 +515,8 @@ class Uppy {
    * Uninstall all plugins and close down this Uppy instance.
    */
   close () {
+    this.reset()
+
     this.iteratePlugins((plugin) => {
       plugin.uninstall()
     })