Browse Source

call removePlugin in close, immutable plugin removal, emit event, remove pluginState too

Artur Paikin 6 years ago
parent
commit
6fd178302c
2 changed files with 9 additions and 5 deletions
  1. 8 2
      src/core/Core.js
  2. 1 3
      src/core/Core.test.js

+ 8 - 2
src/core/Core.js

@@ -886,16 +886,22 @@ class Uppy {
    * @param {object} instance The plugin instance to remove.
    */
   removePlugin (instance) {
-    const list = this.plugins[instance.type]
+    this.emit('plugin-removed', instance)
 
     if (instance.uninstall) {
       instance.uninstall()
     }
 
+    const list = this.plugins[instance.type].slice()
     const index = list.indexOf(instance)
     if (index !== -1) {
       list.splice(index, 1)
+      this.plugins[instance.type] = list
     }
+
+    const updatedState = this.getState()
+    delete updatedState.plugins[instance.id]
+    this.setState(updatedState)
   }
 
   /**
@@ -907,7 +913,7 @@ class Uppy {
     this._storeUnsubscribe()
 
     this.iteratePlugins((plugin) => {
-      plugin.uninstall()
+      this.removePlugin(plugin)
     })
   }
 

+ 1 - 3
src/core/Core.test.js

@@ -278,9 +278,7 @@ describe('src/Core', () => {
       plugins: {},
       totalProgress: 0
     })
-    expect(core.plugins.acquirer[0].mocks.uninstall.mock.calls.length).toEqual(
-      1
-    )
+    expect(core.plugins[Object.keys(core.plugins)[0]].length).toEqual(0)
   })
 
   describe('upload hooks', () => {