Explorar el Código

feat(Listenable): make addListener remove unsubscribe method

It makes it easier to remove listeners.
dev1
paweldomas hace 5 años
padre
commit
caedfd27b3
Se han modificado 1 ficheros con 3 adiciones y 0 borrados
  1. 3
    0
      modules/util/Listenable.js

+ 3
- 0
modules/util/Listenable.js Ver fichero

@@ -23,9 +23,12 @@ export default class Listenable {
23 23
      * Adds new listener.
24 24
      * @param {String} eventName the name of the event
25 25
      * @param {Function} listener the listener.
26
+     * @returns {Function} - The unsubscribe function.
26 27
      */
27 28
     addListener(eventName, listener) {
28 29
         this.eventEmitter.addListener(eventName, listener);
30
+
31
+        return () => this.removeEventListener(eventName, listener);
29 32
     }
30 33
 
31 34
     /**

Loading…
Cancelar
Guardar