Browse Source

Move `update()` to `Plugin.js` to avoid duplication

Artur Paikin 9 years ago
parent
commit
6502d66d0b
3 changed files with 14 additions and 25 deletions
  1. 13 6
      src/plugins/Plugin.js
  2. 0 9
      src/plugins/ProgressBar.js
  3. 1 10
      src/plugins/ProgressDrawer.js

+ 13 - 6
src/plugins/Plugin.js

@@ -1,3 +1,5 @@
+import yo from 'yo-yo'
+
 /**
  * Boilerplate that all Plugins share - and should not be used
  * directly. It also shows which methods final plugins should implement/override,
@@ -16,6 +18,15 @@ export default class Plugin {
     this.name = this.constructor.name
   }
 
+  update () {
+    if (typeof this.el === 'undefined') {
+      return
+    }
+
+    const newEl = this.render(this.core.state)
+    yo.update(this.el, newEl)
+  }
+
   /**
    * Check if supplied `target` is a `string` or an `object`.
    * If object (that means its a plugin), search `plugins` for
@@ -43,15 +54,11 @@ export default class Plugin {
     return
   }
 
-  update () {
-    return
-  }
-
   install () {
     return
   }
 
-  run (results) {
-    return results
+  run () {
+    return
   }
 }

+ 0 - 9
src/plugins/ProgressBar.js

@@ -17,15 +17,6 @@ export default class ProgressBar extends Plugin {
     this.opts = Object.assign({}, defaultOptions, opts)
   }
 
-  update () {
-    if (typeof this.el === 'undefined') {
-      return
-    }
-
-    const newEl = this.render(this.core.state)
-    yo.update(this.el, newEl)
-  }
-
   render (state) {
     const progress = state.totalProgress || 0
 

+ 1 - 10
src/plugins/ProgressDrawer.js

@@ -18,15 +18,6 @@ export default class ProgressDrawer extends Plugin {
     this.opts = Object.assign({}, defaultOptions, opts)
   }
 
-  update () {
-    if (typeof this.el === 'undefined') {
-      return
-    }
-
-    const newEl = this.render(this.core.state)
-    yo.update(this.el, newEl)
-  }
-
   drawerItem (file) {
     const isUploaded = file.progress === 100
 
@@ -52,7 +43,7 @@ export default class ProgressDrawer extends Plugin {
         <h4 class="UppyProgressDrawer-itemName">
           ${file.uploadURL
             ? yo`<a href="${file.uploadURL}" target="_blank">${file.name}</a>`
-            : yo`<span>${file.name} (${file.progress})</span>`
+            : yo`<span>${file.name} (${file.progress}%)</span>`
           }
         </h4>
           ${isUploaded ? checkIcon : ''}