Преглед изворни кода

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

Artur Paikin пре 9 година
родитељ
комит
dc2bb9636d
4 измењених фајлова са 9 додато и 9 уклоњено
  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) {
   use (Plugin, opts) {
     // Instantiate
     // Instantiate
     const plugin = new Plugin(this, opts)
     const plugin = new Plugin(this, opts)
-    const pluginName = Utils.getFnName(plugin.constructor)
+    const pluginName = plugin.id
     this.plugins[plugin.type] = this.plugins[plugin.type] || []
     this.plugins[plugin.type] = this.plugins[plugin.type] || []
 
 
     if (!pluginName) {
     if (!pluginName) {
@@ -254,7 +254,7 @@ export default class Core {
     let existsPluginAlready = this.getPlugin(pluginName)
     let existsPluginAlready = this.getPlugin(pluginName)
     if (existsPluginAlready) {
     if (existsPluginAlready) {
       let msg = `Already found a plugin named '${existsPluginAlready.name}'.
       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.
         Uppy is currently limited to running one of every plugin.
         Share your use case with us over at
         Share your use case with us over at
         https://github.com/transloadit/uppy/issues/
         https://github.com/transloadit/uppy/issues/
@@ -275,7 +275,7 @@ export default class Core {
   getPlugin (name) {
   getPlugin (name) {
     let foundPlugin = false
     let foundPlugin = false
     this.iteratePlugins((plugin) => {
     this.iteratePlugins((plugin) => {
-      const pluginName = Utils.getFnName(plugin.constructor)
+      const pluginName = plugin.id
       if (pluginName === name) {
       if (pluginName === name) {
         foundPlugin = plugin
         foundPlugin = plugin
         return false
         return false

+ 1 - 2
src/plugins/Dummy.js

@@ -26,7 +26,6 @@ export default class Dummy extends Plugin {
     return yo`
     return yo`
       <div class="wow-this-works">
       <div class="wow-this-works">
         <input type="text" value="hello">
         <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}
         ${this.strange}
         ${bla}
         ${bla}
       </div>
       </div>
@@ -40,6 +39,6 @@ export default class Dummy extends Plugin {
 
 
   install () {
   install () {
     this.el = this.render()
     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) {
   addTarget (callerPlugin, render) {
     const callerPluginId = callerPlugin.constructor.name
     const callerPluginId = callerPlugin.constructor.name
-    const callerPluginName = callerPlugin.name || callerPluginId
+    const callerPluginName = callerPlugin.title || callerPluginId
     const callerPluginIcon = callerPlugin.icon || this.opts.defaultTabIcon
     const callerPluginIcon = callerPlugin.icon || this.opts.defaultTabIcon
     const callerPluginType = callerPlugin.type
     const callerPluginType = callerPlugin.type
 
 

+ 4 - 3
src/plugins/Plugin.js

@@ -1,5 +1,4 @@
 import yo from 'yo-yo'
 import yo from 'yo-yo'
-import Utils from '../core/Utils'
 
 
 /**
 /**
  * Boilerplate that all Plugins share - and should not be used
  * Boilerplate that all Plugins share - and should not be used
@@ -37,7 +36,7 @@ export default class Plugin {
    *
    *
    */
    */
   getTarget (target, caller, el, render) {
   getTarget (target, caller, el, render) {
-    const callerPluginName = Utils.getFnName(caller.constructor)
+    const callerPluginName = caller.id
 
 
     if (typeof target === 'string') {
     if (typeof target === 'string') {
       this.core.log(`Installing ${callerPluginName} to ${target}`)
       this.core.log(`Installing ${callerPluginName} to ${target}`)
@@ -50,7 +49,9 @@ export default class Plugin {
 
 
       return target
       return target
     } else {
     } 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}`)
       this.core.log(`Installing ${callerPluginName} to ${targetPluginName}`)
       let targetPlugin = this.core.getPlugin(targetPluginName)
       let targetPlugin = this.core.getPlugin(targetPluginName)
       let selectorTarget = targetPlugin.addTarget(caller, render)
       let selectorTarget = targetPlugin.addTarget(caller, render)