Move update() to Plugin.js to avoid duplication

This commit is contained in:
Artur Paikin 2016-04-23 18:01:21 -04:00
parent 7ffc0ee990
commit 6502d66d0b
3 changed files with 14 additions and 25 deletions

View file

@ -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
}
}

View file

@ -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

View file

@ -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 : ''}