1616
1717var enums = require ( '../../utils/enums' ) ;
1818var fns = require ( '../../utils/fns' ) ;
19- var sprintf = require ( '@optimizely/js-sdk-utils' ) . sprintf ;
19+ var jsSdkUtils = require ( '@optimizely/js-sdk-utils' ) ;
2020
2121var LOG_LEVEL = enums . LOG_LEVEL ;
2222var LOG_MESSAGES = enums . LOG_MESSAGES ;
@@ -37,7 +37,9 @@ function NotificationCenter(options) {
3737 this . logger = options . logger ;
3838 this . errorHandler = options . errorHandler ;
3939 this . __notificationListeners = { } ;
40- fns . forOwn ( enums . NOTIFICATION_TYPES , function ( notificationTypeEnum ) {
40+
41+ Object . keys ( enums . NOTIFICATION_TYPES ) . forEach ( function ( key ) {
42+ var notificationTypeEnum = enums . NOTIFICATION_TYPES [ key ] ;
4143 this . __notificationListeners [ notificationTypeEnum ] = [ ] ;
4244 } . bind ( this ) ) ;
4345 this . __listenerId = 1 ;
@@ -55,7 +57,7 @@ function NotificationCenter(options) {
5557 */
5658NotificationCenter . prototype . addNotificationListener = function ( notificationType , callback ) {
5759 try {
58- var isNotificationTypeValid = fns . values ( enums . NOTIFICATION_TYPES )
60+ var isNotificationTypeValid = jsSdkUtils . objectValues ( enums . NOTIFICATION_TYPES )
5961 . indexOf ( notificationType ) > - 1 ;
6062 if ( ! isNotificationTypeValid ) {
6163 return - 1 ;
@@ -101,19 +103,18 @@ NotificationCenter.prototype.removeNotificationListener = function (listenerId)
101103 try {
102104 var indexToRemove ;
103105 var typeToRemove ;
104- fns . forOwn ( this . __notificationListeners , function ( listenersForType , notificationType ) {
106+
107+ Object . keys ( this . __notificationListeners ) . forEach ( function ( notificationType ) {
108+ var listenersForType = this . __notificationListeners [ notificationType ] ;
105109 fns . forEach ( listenersForType , function ( listenerEntry , i ) {
106110 if ( listenerEntry . id === listenerId ) {
107111 indexToRemove = i ;
108112 typeToRemove = notificationType ;
109113 return false ;
110114 }
111115 } ) ;
112- if ( indexToRemove !== undefined && typeToRemove !== undefined ) {
113- return false ;
114- }
115- } ) ;
116-
116+ } . bind ( this ) ) ;
117+
117118 if ( indexToRemove !== undefined && typeToRemove !== undefined ) {
118119 this . __notificationListeners [ typeToRemove ] . splice ( indexToRemove , 1 ) ;
119120 return true ;
@@ -130,7 +131,8 @@ NotificationCenter.prototype.removeNotificationListener = function (listenerId)
130131 */
131132NotificationCenter . prototype . clearAllNotificationListeners = function ( ) {
132133 try {
133- fns . forOwn ( enums . NOTIFICATION_TYPES , function ( notificationTypeEnum ) {
134+ Object . keys ( enums . NOTIFICATION_TYPES ) . forEach ( function ( key ) {
135+ var notificationTypeEnum = enums . NOTIFICATION_TYPES [ key ] ;
134136 this . __notificationListeners [ notificationTypeEnum ] = [ ] ;
135137 } . bind ( this ) ) ;
136138 } catch ( e ) {
@@ -165,7 +167,7 @@ NotificationCenter.prototype.sendNotifications = function (notificationType, not
165167 try {
166168 callback ( notificationData ) ;
167169 } catch ( ex ) {
168- this . logger . log ( LOG_LEVEL . ERROR , sprintf ( LOG_MESSAGES . NOTIFICATION_LISTENER_EXCEPTION , MODULE_NAME , notificationType , ex . message ) ) ;
170+ this . logger . log ( LOG_LEVEL . ERROR , jsSdkUtils . sprintf ( LOG_MESSAGES . NOTIFICATION_LISTENER_EXCEPTION , MODULE_NAME , notificationType , ex . message ) ) ;
169171 }
170172 } . bind ( this ) ) ;
171173 } catch ( e ) {
0 commit comments