Переглянути джерело

remove unused methods, use getState()

Artur Paikin 7 роки тому
батько
коміт
59263c59a2
3 змінених файлів з 33 додано та 48 видалено
  1. 31 43
      src/core/Core.js
  2. 1 1
      src/plugins/Dashboard/index.js
  3. 1 4
      src/plugins/Provider/view/index.js

+ 31 - 43
src/core/Core.js

@@ -1,6 +1,5 @@
 const Utils = require('../core/Utils')
 const Utils = require('../core/Utils')
 const Translator = require('../core/Translator')
 const Translator = require('../core/Translator')
-const UppySocket = require('./UppySocket')
 const ee = require('namespace-emitter')
 const ee = require('namespace-emitter')
 const cuid = require('cuid')
 const cuid = require('cuid')
 const throttle = require('lodash.throttle')
 const throttle = require('lodash.throttle')
@@ -70,7 +69,7 @@ class Uppy {
     this.getPlugin = this.getPlugin.bind(this)
     this.getPlugin = this.getPlugin.bind(this)
     this.setFileMeta = this.setFileMeta.bind(this)
     this.setFileMeta = this.setFileMeta.bind(this)
     this.setFileState = this.setFileState.bind(this)
     this.setFileState = this.setFileState.bind(this)
-    this.initSocket = this.initSocket.bind(this)
+    // this._initSocket = this._initSocket.bind(this)
     this.log = this.log.bind(this)
     this.log = this.log.bind(this)
     this.info = this.info.bind(this)
     this.info = this.info.bind(this)
     this.hideInfo = this.hideInfo.bind(this)
     this.hideInfo = this.hideInfo.bind(this)
@@ -158,6 +157,17 @@ class Uppy {
     return this.getState()
     return this.getState()
   }
   }
 
 
+  /**
+  * Shorthand to set state for a specific file
+  */
+  setFileState (fileID, state) {
+    this.setState({
+      files: Object.assign({}, this.getState().files, {
+        [fileID]: Object.assign({}, this.getState().files[fileID], state)
+      })
+    })
+  }
+
   resetProgress () {
   resetProgress () {
     const defaultProgress = {
     const defaultProgress = {
       percentage: 0,
       percentage: 0,
@@ -235,17 +245,6 @@ class Uppy {
     this.setState({files: updatedFiles})
     this.setState({files: updatedFiles})
   }
   }
 
 
-  /**
-  * Shorthand to set state for a specific file
-  */
-  setFileState (fileID, state) {
-    this.setState({
-      files: Object.assign({}, this.state.files, {
-        [fileID]: Object.assign({}, this.state.files[fileID], state)
-      })
-    })
-  }
-
   /**
   /**
    * Get a file object.
    * Get a file object.
    *
    *
@@ -425,14 +424,7 @@ class Uppy {
    * Set the preview URL for a file.
    * Set the preview URL for a file.
    */
    */
   setPreviewURL (fileID, preview) {
   setPreviewURL (fileID, preview) {
-    const { files } = this.getState()
-    this.setState({
-      files: Object.assign({}, files, {
-        [fileID]: Object.assign({}, files[fileID], {
-          preview: preview
-        })
-      })
-    })
+    this.setFileState(fileID, { preview: preview })
   }
   }
 
 
   pauseResume (fileID) {
   pauseResume (fileID) {
@@ -516,6 +508,11 @@ class Uppy {
     return this._runUpload(uploadID)
     return this._runUpload(uploadID)
   }
   }
 
 
+  cancelAll () {
+    this.emit('cancel-all')
+    this.setState({ files: {}, totalProgress: 0 })
+  }
+
   retryUpload (fileID) {
   retryUpload (fileID) {
     const updatedFiles = Object.assign({}, this.getState().files)
     const updatedFiles = Object.assign({}, this.getState().files)
     const updatedFile = Object.assign({}, updatedFiles[fileID],
     const updatedFile = Object.assign({}, updatedFiles[fileID],
@@ -536,11 +533,6 @@ class Uppy {
     this.cancelAll()
     this.cancelAll()
   }
   }
 
 
-  cancelAll () {
-    this.emit('cancel-all')
-    this.setState({ files: {}, totalProgress: 0 })
-  }
-
   calculateProgress (data) {
   calculateProgress (data) {
     const fileID = data.id
     const fileID = data.id
 
 
@@ -624,9 +616,9 @@ class Uppy {
       this.setState({ error: null })
       this.setState({ error: null })
     })
     })
 
 
-    this.on('file-add', (data) => {
-      this.addFile(data)
-    })
+    // this.on('file-add', (data) => {
+    //   this.addFile(data)
+    // })
 
 
     this.on('file-added', (file) => {
     this.on('file-added', (file) => {
       this.generatePreview(file)
       this.generatePreview(file)
@@ -807,7 +799,7 @@ class Uppy {
    * @param function method description
    * @param function method description
    */
    */
   iteratePlugins (method) {
   iteratePlugins (method) {
-    Object.keys(this.plugins).forEach((pluginType) => {
+    Object.keys(this.plugins).forEach(pluginType => {
       this.plugins[pluginType].forEach(method)
       this.plugins[pluginType].forEach(method)
     })
     })
   }
   }
@@ -836,19 +828,15 @@ class Uppy {
   close () {
   close () {
     this.reset()
     this.reset()
 
 
-    if (this.withDevTools) {
-      this.devToolsUnsubscribe()
-    }
-
     this._storeUnsubscribe()
     this._storeUnsubscribe()
 
 
     this.iteratePlugins((plugin) => {
     this.iteratePlugins((plugin) => {
       plugin.uninstall()
       plugin.uninstall()
     })
     })
 
 
-    if (this.socket) {
-      this.socket.close()
-    }
+    // if (this.socket) {
+    //   this.socket.close()
+    // }
   }
   }
 
 
   /**
   /**
@@ -926,13 +914,13 @@ class Uppy {
     }
     }
   }
   }
 
 
-  initSocket (opts) {
-    if (!this.socket) {
-      this.socket = new UppySocket(opts)
-    }
+  // _initSocket (opts) {
+  //   if (!this.socket) {
+  //     this.socket = new UppySocket(opts)
+  //   }
 
 
-    return this.socket
-  }
+  //   return this.socket
+  // }
 
 
   /**
   /**
    * 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

+ 1 - 1
src/plugins/Dashboard/index.js

@@ -396,7 +396,7 @@ module.exports = class DashboardUI extends Plugin {
 
 
     const cancelUpload = (fileID) => {
     const cancelUpload = (fileID) => {
       this.core.emit('upload-cancel', fileID)
       this.core.emit('upload-cancel', fileID)
-      this.core.emit('file-remove', fileID)
+      this.core.removeFile(fileID)
     }
     }
 
 
     const showFileCard = (fileID) => {
     const showFileCard = (fileID) => {

+ 1 - 4
src/plugins/Provider/view/index.js

@@ -6,11 +6,8 @@ const Utils = require('../../../core/Utils')
 /**
 /**
  * Class to easily generate generic views for plugins
  * Class to easily generate generic views for plugins
  *
  *
- * This class expects the plugin using to have the following attributes
  *
  *
- * stateId {String} object key of which the plugin state is stored
- *
- * This class also expects the plugin instance using it to have the following
+ * This class expects the plugin instance using it to have the following
  * accessor methods.
  * accessor methods.
  * Each method takes the item whose property is to be accessed
  * Each method takes the item whose property is to be accessed
  * as a param
  * as a param