Bläddra i källkod

uppy-react: Experiment with unmounting.

This implements unmounting for the inline Dashboard component.
To do that, the Dashboard plugin now has a method `uninstall`,
which removes all listeners and removes the Dashboard element
from the DOM. The `componentWillUnmount` handler removes the plugin
from Uppy's internal plugin list. If this approach is the way to
go, we'd add a method to core to remove plugins… I think in that
case, it'd be good to add some concept of View Plugins, so that
Acquirer plugins function like they do now but View plugins can be
mounted and unmounted.
René Kooi 8 år sedan
förälder
incheckning
4e74a1ac19
2 ändrade filer med 18 tillägg och 0 borttagningar
  1. 4 0
      src/plugins/Plugin.js
  2. 14 0
      src/uppy-react/Dashboard.js

+ 4 - 0
src/plugins/Plugin.js

@@ -94,6 +94,10 @@ module.exports = class Plugin {
     }
     }
   }
   }
 
 
+  focus () {
+    return
+  }
+
   install () {
   install () {
     return
     return
   }
   }

+ 14 - 0
src/uppy-react/Dashboard.js

@@ -28,6 +28,20 @@ class Dashboard extends React.Component {
     this.plugin = uppy.getPlugin('DashboardUI')
     this.plugin = uppy.getPlugin('DashboardUI')
   }
   }
 
 
+  componentWillUnmount () {
+    // EXPERIMENTAL!
+    // If we add a method like this to Uppy core, unmounting and remounting
+    // works fine.
+    const uppy = this.props.uppy
+    const plugins = uppy.plugins[this.plugin.type]
+    this.plugin.uninstall()
+
+    const i = plugins.indexOf(this.plugin)
+    if (i !== -1) {
+      plugins.splice(i, 1)
+    }
+  }
+
   render () {
   render () {
     return h('div', {
     return h('div', {
       ref: (container) => {
       ref: (container) => {