[Addon] Add 'once' method for wrappedEventEmitter 26/230326/1
authorhyunduk.kim <hyunduk.kim@samsung.com>
Thu, 9 Apr 2020 08:51:31 +0000 (17:51 +0900)
committerhyunduk.kim <hyunduk.kim@samsung.com>
Thu, 9 Apr 2020 08:54:20 +0000 (17:54 +0900)
This change will add a new method 'once'
which will work as same as 'once' of EventEmitter.

Change-Id: Ib218727447a79c2d1a596e5fc972e5748caca42a
Signed-off-by: hyunduk.kim <hyunduk.kim@samsung.com>
wrt_app/src/addon_manager.js

index 6492b88..0eb9b55 100644 (file)
@@ -207,6 +207,14 @@ class AddonManager {
                     this.evt_emitter_.off(eventName, this.addons_listeners[listener]);
                     delete this.addons_listeners[listener];
                 } else console.log('Listener is not registered');
+            },
+            once: (eventName, listener) => {
+                if (EventList.indexOf(eventName) === -1) {
+                    console.log(`Invalid Event: ${eventName}`);
+                } else if (!this.addons_listeners[listener]) {
+                    console.log(`A new one-time listener for ${eventName} is added`);
+                    this.evt_emitter_.once(eventName, getSafeFunction(listener));
+                } else console.log('Listener is already registered for the multiple-time use');
             }
         }
     }