Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/optimizely-sdk/lib/core/notification_center/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ NotificationCenter.prototype.addNotificationListener = function (notificationTyp
}

var callbackAlreadyAdded = false;
fns.forEach(this.__notificationListeners[notificationType], function (listenerEntry) {
(this.__notificationListeners[notificationType] || []).forEach(function(listenerEntry) {
if (listenerEntry.callback === callback) {
callbackAlreadyAdded = true;
return false;
Expand Down Expand Up @@ -102,12 +102,13 @@ NotificationCenter.prototype.removeNotificationListener = function (listenerId)
var indexToRemove;
var typeToRemove;
fns.forOwn(this.__notificationListeners, function (listenersForType, notificationType) {
fns.forEach(listenersForType, function (listenerEntry, i) {
(listenersForType || []).every(function(listenerEntry, i) {
if (listenerEntry.id === listenerId) {
indexToRemove = i;
typeToRemove = notificationType;
return false;
}
return true
});
if (indexToRemove !== undefined && typeToRemove !== undefined) {
return false;
Expand Down Expand Up @@ -160,7 +161,7 @@ NotificationCenter.prototype.clearNotificationListeners = function (notification
*/
NotificationCenter.prototype.sendNotifications = function (notificationType, notificationData) {
try {
fns.forEach(this.__notificationListeners[notificationType], function (listenerEntry) {
(this.__notificationListeners[notificationType] || []).forEach(function(listenerEntry) {
var callback = listenerEntry.callback;
try {
callback(notificationData);
Expand Down
14 changes: 7 additions & 7 deletions packages/optimizely-sdk/lib/core/project_config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = {
* Conditions of audiences in projectConfig.typedAudiences are not
* expected to be string-encoded as they are here in projectConfig.audiences.
*/
fns.forEach(projectConfig.audiences, function(audience) {
(projectConfig.audiences || []).forEach(function(audience) {
audience.conditions = JSON.parse(audience.conditions);
});
projectConfig.audiencesById = fns.keyBy(projectConfig.audiences, 'id');
Expand All @@ -52,16 +52,16 @@ module.exports = {
projectConfig.groupIdMap = fns.keyBy(projectConfig.groups, 'id');

var experiments;
fns.forEach(projectConfig.groupIdMap, function(group, Id) {
experiments = fns.cloneDeep(group.experiments);
fns.forEach(experiments, function(experiment) {
Object.keys(projectConfig.groupIdMap || {}).forEach(function(Id) {
experiments = fns.cloneDeep(projectConfig.groupIdMap[Id].experiments);
(experiments || []).forEach(function(experiment) {
projectConfig.experiments.push(fns.assign(experiment, {groupId: Id}));
});
});

projectConfig.rolloutIdMap = fns.keyBy(projectConfig.rollouts || [], 'id');
fns.forOwn(projectConfig.rolloutIdMap, function(rollout) {
fns.forEach(rollout.experiments || [], function(experiment) {
(rollout.experiments || []).forEach(function(experiment) {
projectConfig.experiments.push(fns.cloneDeep(experiment));
// Creates { <variationKey>: <variation> } map inside of the experiment
experiment.variationKeyMap = fns.keyBy(experiment.variations, 'key');
Expand All @@ -73,7 +73,7 @@ module.exports = {

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

Expand All @@ -94,7 +94,7 @@ module.exports = {
projectConfig.featureKeyMap = fns.keyBy(projectConfig.featureFlags || [], 'key');
fns.forOwn(projectConfig.featureKeyMap, function(feature) {
feature.variableKeyMap = fns.keyBy(feature.variables, 'key');
fns.forEach(feature.experimentIds || [], function(experimentId) {
(feature.experimentIds || []).forEach(function(experimentId) {
// Add this experiment in experiment-feature map.
if (projectConfig.experimentFeatureMap[experimentId]) {
projectConfig.experimentFeatureMap[experimentId].push(feature.id);
Expand Down
1 change: 0 additions & 1 deletion packages/optimizely-sdk/lib/utils/fns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ module.exports = {
return item[key];
});
},
forEach: require('lodash/forEach'),
forOwn: require('lodash/forOwn'),
uuid: function() {
return uuid.v4();
Expand Down