Explorar el Código

@uppy/utils: use private fields in `ProgressTimeout` (#3080)

Antoine du Hamel hace 3 años
padre
commit
dc5cab4922
Se han modificado 1 ficheros con 18 adiciones y 13 borrados
  1. 18 13
      packages/@uppy/utils/src/ProgressTimeout.js

+ 18 - 13
packages/@uppy/utils/src/ProgressTimeout.js

@@ -5,32 +5,37 @@
  * Call `timer.done()` when the upload has completed.
  */
 class ProgressTimeout {
+  #aliveTimer;
+
+  #isDone = false;
+
+  #onTimedOut;
+
+  #timeout;
+
   constructor (timeout, timeoutHandler) {
-    this._timeout = timeout
-    this._onTimedOut = timeoutHandler
-    this._isDone = false
-    this._aliveTimer = null
-    this._onTimedOut = this._onTimedOut.bind(this)
+    this.#timeout = timeout
+    this.#onTimedOut = timeoutHandler
   }
 
   progress () {
     // Some browsers fire another progress event when the upload is
     // cancelled, so we have to ignore progress after the timer was
     // told to stop.
-    if (this._isDone) return
+    if (this.#isDone) return
 
-    if (this._timeout > 0) {
-      if (this._aliveTimer) clearTimeout(this._aliveTimer)
-      this._aliveTimer = setTimeout(this._onTimedOut, this._timeout)
+    if (this.#timeout > 0) {
+      clearTimeout(this.#aliveTimer)
+      this.#aliveTimer = setTimeout(this.#onTimedOut, this.#timeout)
     }
   }
 
   done () {
-    if (this._aliveTimer) {
-      clearTimeout(this._aliveTimer)
-      this._aliveTimer = null
+    if (!this.#isDone) {
+      clearTimeout(this.#aliveTimer)
+      this.#aliveTimer = null
+      this.#isDone = true
     }
-    this._isDone = true
   }
 }