浏览代码

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

Antoine du Hamel 3 年之前
父节点
当前提交
c8606ae5fe
共有 1 个文件被更改,包括 10 次插入7 次删除
  1. 10 7
      packages/@uppy/utils/src/EventTracker.js

+ 10 - 7
packages/@uppy/utils/src/EventTracker.js

@@ -3,19 +3,22 @@
  * all events that were added using the wrapped emitter.
  */
 module.exports = class EventTracker {
+  #emitter
+
+  #events = []
+
   constructor (emitter) {
-    this._events = []
-    this._emitter = emitter
+    this.#emitter = emitter
   }
 
   on (event, fn) {
-    this._events.push([event, fn])
-    return this._emitter.on(event, fn)
+    this.#events.push([event, fn])
+    return this.#emitter.on(event, fn)
   }
 
   remove () {
-    this._events.forEach(([event, fn]) => {
-      this._emitter.off(event, fn)
-    })
+    for (const [event, fn] of this.#events.splice(0)) {
+      this.#emitter.off(event, fn)
+    }
   }
 }