Skip to content

Commit f8fdfae

Browse files
committed
removed values function from fns. using it directly from js sdk utils
1 parent e78b60a commit f8fdfae

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

packages/optimizely-sdk/lib/core/notification_center/index.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
var enums = require('../../utils/enums');
1818
var fns = require('../../utils/fns');
19-
var sprintf = require('@optimizely/js-sdk-utils').sprintf;
19+
var jsSdkUtils = require('@optimizely/js-sdk-utils');
2020

2121
var LOG_LEVEL = enums.LOG_LEVEL;
2222
var 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
*/
5658
NotificationCenter.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
*/
131132
NotificationCenter.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) {

packages/optimizely-sdk/lib/utils/fns/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
var uuid = require('uuid');
1717
var _isFinite = require('lodash/isFinite');
18-
var objectValues = require('@optimizely/js-sdk-utils').objectValues;
1918
var MAX_NUMBER_LIMIT = Math.pow(2, 53);
2019

2120
module.exports = {
@@ -34,6 +33,5 @@ module.exports = {
3433
uuid: function() {
3534
return uuid.v4();
3635
},
37-
values: objectValues,
3836
isNumber: require('lodash/isNumber'),
3937
};

0 commit comments

Comments
 (0)