[Addon] Add 'once' method for wrappedEventEmitter 44/230644/1
authorhyunduk.kim <hyunduk.kim@samsung.com>
Mon, 13 Apr 2020 07:00:46 +0000 (16:00 +0900)
committerhyunduk.kim <hyunduk.kim@samsung.com>
Mon, 13 Apr 2020 07:00:46 +0000 (16:00 +0900)
This change will add a new method 'once'
which will work as same as 'once' of EventEmitter.

Change-Id: Ib07ffcdbe357af6b9c36b7a4e22ddf4c8a7f8669
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');
             }
         }
     }