Skip to content

Commit 08cb4bf

Browse files
authored
Merge branch 'master' into zeeshan/replace-lodash-forown
2 parents 9d3a331 + 59cdad4 commit 08cb4bf

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ NotificationCenter.prototype.addNotificationListener = function (notificationTyp
6767
}
6868

6969
var callbackAlreadyAdded = false;
70-
fns.forEach(this.__notificationListeners[notificationType], function (listenerEntry) {
70+
(this.__notificationListeners[notificationType] || []).forEach(function(listenerEntry) {
7171
if (listenerEntry.callback === callback) {
7272
callbackAlreadyAdded = true;
7373
return false;
@@ -102,15 +102,16 @@ NotificationCenter.prototype.removeNotificationListener = function (listenerId)
102102
try {
103103
var indexToRemove;
104104
var typeToRemove;
105-
105+
106106
Object.keys(this.__notificationListeners).some(function(notificationType) {
107-
var listenersForType = this.__notificationListeners[notificationType];
108-
fns.forEach(listenersForType, function (listenerEntry, i) {
107+
var listenersForType = this.__notificationListeners[notificationType];
108+
(listenersForType || []).every(function(listenerEntry, i) {
109109
if (listenerEntry.id === listenerId) {
110110
indexToRemove = i;
111111
typeToRemove = notificationType;
112112
return false;
113113
}
114+
return true
114115
});
115116
if (indexToRemove !== undefined && typeToRemove !== undefined) {
116117
return true;
@@ -163,7 +164,7 @@ NotificationCenter.prototype.clearNotificationListeners = function (notification
163164
*/
164165
NotificationCenter.prototype.sendNotifications = function (notificationType, notificationData) {
165166
try {
166-
fns.forEach(this.__notificationListeners[notificationType], function (listenerEntry) {
167+
(this.__notificationListeners[notificationType] || []).forEach(function(listenerEntry) {
167168
var callback = listenerEntry.callback;
168169
try {
169170
callback(notificationData);

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = {
4141
* Conditions of audiences in projectConfig.typedAudiences are not
4242
* expected to be string-encoded as they are here in projectConfig.audiences.
4343
*/
44-
fns.forEach(projectConfig.audiences, function(audience) {
44+
(projectConfig.audiences || []).forEach(function(audience) {
4545
audience.conditions = JSON.parse(audience.conditions);
4646
});
4747
projectConfig.audiencesById = fns.keyBy(projectConfig.audiences, 'id');
@@ -52,16 +52,16 @@ module.exports = {
5252
projectConfig.groupIdMap = fns.keyBy(projectConfig.groups, 'id');
5353

5454
var experiments;
55-
fns.forEach(projectConfig.groupIdMap, function(group, Id) {
56-
experiments = fns.cloneDeep(group.experiments);
57-
fns.forEach(experiments, function(experiment) {
55+
Object.keys(projectConfig.groupIdMap || {}).forEach(function(Id) {
56+
experiments = fns.cloneDeep(projectConfig.groupIdMap[Id].experiments);
57+
(experiments || []).forEach(function(experiment) {
5858
projectConfig.experiments.push(fns.assign(experiment, {groupId: Id}));
5959
});
6060
});
6161

6262
projectConfig.rolloutIdMap = fns.keyBy(projectConfig.rollouts || [], 'id');
63-
jsSdkUtils.objectValues(projectConfig.rolloutIdMap || {}).forEach(function (rollout) {
64-
fns.forEach(rollout.experiments || [], function(experiment) {
63+
jsSdkUtils.objectValues(projectConfig.rolloutIdMap || {}).forEach(function (rollout) {
64+
(rollout.experiments || []).forEach(function(experiment) {
6565
projectConfig.experiments.push(fns.cloneDeep(experiment));
6666
// Creates { <variationKey>: <variation> } map inside of the experiment
6767
experiment.variationKeyMap = fns.keyBy(experiment.variations, 'key');
@@ -73,7 +73,7 @@ module.exports = {
7373

7474
projectConfig.variationIdMap = {};
7575
projectConfig.variationVariableUsageMap = {};
76-
fns.forEach(projectConfig.experiments, function(experiment) {
76+
(projectConfig.experiments || []).forEach(function(experiment) {
7777
// Creates { <variationKey>: <variation> } map inside of the experiment
7878
experiment.variationKeyMap = fns.keyBy(experiment.variations, 'key');
7979

@@ -93,7 +93,7 @@ module.exports = {
9393
projectConfig.featureKeyMap = fns.keyBy(projectConfig.featureFlags || [], 'key');
9494
jsSdkUtils.objectValues(projectConfig.featureKeyMap || {}).forEach(function (feature) {
9595
feature.variableKeyMap = fns.keyBy(feature.variables, 'key');
96-
fns.forEach(feature.experimentIds || [], function(experimentId) {
96+
(feature.experimentIds || []).forEach(function(experimentId) {
9797
// Add this experiment in experiment-feature map.
9898
if (projectConfig.experimentFeatureMap[experimentId]) {
9999
projectConfig.experimentFeatureMap[experimentId].push(feature.id);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ module.exports = {
5454
return item[key];
5555
});
5656
},
57-
forEach: require('lodash/forEach'),
5857
uuid: function() {
5958
return uuid.v4();
6059
},

0 commit comments

Comments
 (0)