Browse Source

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 years ago
parent
commit
4e74a1ac19
2 changed files with 18 additions and 0 deletions
  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 () {
     return
   }

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

@@ -28,6 +28,20 @@ class Dashboard extends React.Component {
     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 () {
     return h('div', {
       ref: (container) => {