Kaynağa Gözat

Fix the plugin naming system so it works when bundle is minified

Artur Paikin 9 yıl önce
ebeveyn
işleme
dc2bb9636d
4 değiştirilmiş dosya ile 9 ekleme ve 9 silme
  1. 3 3
      src/core/Core.js
  2. 1 2
      src/plugins/Dummy.js
  3. 1 1
      src/plugins/Modal.js
  4. 4 3
      src/plugins/Plugin.js

+ 3 - 3
src/core/Core.js

@@ -240,7 +240,7 @@ export default class Core {
   use (Plugin, opts) {
     // Instantiate
     const plugin = new Plugin(this, opts)
-    const pluginName = Utils.getFnName(plugin.constructor)
+    const pluginName = plugin.id
     this.plugins[plugin.type] = this.plugins[plugin.type] || []
 
     if (!pluginName) {
@@ -254,7 +254,7 @@ export default class Core {
     let existsPluginAlready = this.getPlugin(pluginName)
     if (existsPluginAlready) {
       let msg = `Already found a plugin named '${existsPluginAlready.name}'.
-        Tried to use: '${plugin.constructor.name}'.
+        Tried to use: '${pluginName}'.
         Uppy is currently limited to running one of every plugin.
         Share your use case with us over at
         https://github.com/transloadit/uppy/issues/
@@ -275,7 +275,7 @@ export default class Core {
   getPlugin (name) {
     let foundPlugin = false
     this.iteratePlugins((plugin) => {
-      const pluginName = Utils.getFnName(plugin.constructor)
+      const pluginName = plugin.id
       if (pluginName === name) {
         foundPlugin = plugin
         return false

+ 1 - 2
src/plugins/Dummy.js

@@ -26,7 +26,6 @@ export default class Dummy extends Plugin {
     return yo`
       <div class="wow-this-works">
         <input type="text" value="hello">
-        I am a dummy plugin, look at me, I was rendered in a modal! That’s crazy, I know.
         ${this.strange}
         ${bla}
       </div>
@@ -40,6 +39,6 @@ export default class Dummy extends Plugin {
 
   install () {
     this.el = this.render()
-    this.target = this.getTarget(this.opts.target, this, this.el, this.render.bind(this))
+    this.target = this.getTarget(this.opts.target, this, this.el, this.render)
   }
 }

+ 1 - 1
src/plugins/Modal.js

@@ -32,7 +32,7 @@ export default class Modal extends Plugin {
 
   addTarget (callerPlugin, render) {
     const callerPluginId = callerPlugin.constructor.name
-    const callerPluginName = callerPlugin.name || callerPluginId
+    const callerPluginName = callerPlugin.title || callerPluginId
     const callerPluginIcon = callerPlugin.icon || this.opts.defaultTabIcon
     const callerPluginType = callerPlugin.type
 

+ 4 - 3
src/plugins/Plugin.js

@@ -1,5 +1,4 @@
 import yo from 'yo-yo'
-import Utils from '../core/Utils'
 
 /**
  * Boilerplate that all Plugins share - and should not be used
@@ -37,7 +36,7 @@ export default class Plugin {
    *
    */
   getTarget (target, caller, el, render) {
-    const callerPluginName = Utils.getFnName(caller.constructor)
+    const callerPluginName = caller.id
 
     if (typeof target === 'string') {
       this.core.log(`Installing ${callerPluginName} to ${target}`)
@@ -50,7 +49,9 @@ export default class Plugin {
 
       return target
     } else {
-      const targetPluginName = Utils.getFnName(target)
+      // TODO: is this the way to roll just to get the plugin name?
+      const Target = target
+      const targetPluginName = new Target().id
       this.core.log(`Installing ${callerPluginName} to ${targetPluginName}`)
       let targetPlugin = this.core.getPlugin(targetPluginName)
       let selectorTarget = targetPlugin.addTarget(caller, render)