Browse Source

allow for usage without `new`, remove installAll

Artur Paikin 8 years ago
parent
commit
ffa57c41bd
1 changed files with 27 additions and 19 deletions
  1. 27 19
      src/core/Core.js

+ 27 - 19
src/core/Core.js

@@ -9,7 +9,7 @@ import en_US from '../locales/en_US'
  *
  *
  * @param {object} opts general options, like locales, to show modal or not to show
  * @param {object} opts general options, like locales, to show modal or not to show
  */
  */
-export default class Core {
+class Uppy {
   constructor (opts) {
   constructor (opts) {
     // set default options
     // set default options
     const defaultOptions = {
     const defaultOptions = {
@@ -325,17 +325,18 @@ export default class Core {
  */
  */
   use (Plugin, opts) {
   use (Plugin, opts) {
     // Prepare props to pass to plugins
     // Prepare props to pass to plugins
-    const props = {
-      getState: this.getState.bind(this),
-      setState: this.setState.bind(this),
-      updateMeta: this.updateMeta.bind(this),
-      addFile: this.addFile.bind(this),
-      i18n: this.i18n.bind(this),
-      bus: this.ee,
-      log: this.log.bind(this)
-    }
+    // const props = {
+    //   getState: this.getState.bind(this),
+    //   setState: this.setState.bind(this),
+    //   updateMeta: this.updateMeta.bind(this),
+    //   addFile: this.addFile.bind(this),
+    //   i18n: this.i18n.bind(this),
+    //   bus: this.ee,
+    //   log: this.log.bind(this)
+    // }
+
     // Instantiate
     // Instantiate
-    const plugin = new Plugin(this, opts, props)
+    const plugin = new Plugin(this, opts)
     const pluginName = plugin.id
     const pluginName = plugin.id
     this.plugins[plugin.type] = this.plugins[plugin.type] || []
     this.plugins[plugin.type] = this.plugins[plugin.type] || []
 
 
@@ -359,6 +360,7 @@ export default class Core {
     }
     }
 
 
     this.plugins[plugin.type].push(plugin)
     this.plugins[plugin.type].push(plugin)
+    plugin.install()
 
 
     return this
     return this
   }
   }
@@ -421,13 +423,13 @@ export default class Core {
     return this.socket
     return this.socket
   }
   }
 
 
-  installAll () {
-    Object.keys(this.plugins).forEach((pluginType) => {
-      this.plugins[pluginType].forEach((plugin) => {
-        plugin.install()
-      })
-    })
-  }
+  // installAll () {
+  //   Object.keys(this.plugins).forEach((pluginType) => {
+  //     this.plugins[pluginType].forEach((plugin) => {
+  //       plugin.install(this)
+  //     })
+  //   })
+  // }
 
 
 /**
 /**
  * Initializes actions, installs all plugins (by iterating on them and calling `install`), sets options
  * Initializes actions, installs all plugins (by iterating on them and calling `install`), sets options
@@ -444,8 +446,14 @@ export default class Core {
     // }
     // }
 
 
     // Install all plugins
     // Install all plugins
-    this.installAll()
+    // this.installAll()
 
 
     return
     return
   }
   }
 }
 }
+
+export default function (opts) {
+  if (!(this instanceof Uppy)) {
+    return new Uppy(opts)
+  }
+}