Skip to content

Commit e359e03

Browse files
authored
Merge branch 'master' into fayyaz/replace_lodash_isFinite
2 parents 96cc209 + 59cdad4 commit e359e03

File tree

7 files changed

+39
-19
lines changed

7 files changed

+39
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var MODULE_NAME = 'AUDIENCE_EVALUATOR';
3535
* @constructor
3636
*/
3737
function AudienceEvaluator(UNSTABLE_conditionEvaluators) {
38-
this.typeToEvaluatorMap = fns.assignIn({}, UNSTABLE_conditionEvaluators, {
38+
this.typeToEvaluatorMap = fns.assign({}, UNSTABLE_conditionEvaluators, {
3939
'custom_attribute': customAttributeConditionEvaluator
4040
});
4141
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ DecisionService.prototype.__resolveExperimentBucketMap = function(userId, attrib
116116
attributes = attributes || {}
117117
var userProfile = this.__getUserProfile(userId) || {};
118118
var attributeExperimentBucketMap = attributes[enums.CONTROL_ATTRIBUTES.STICKY_BUCKETING_KEY];
119-
return fns.assignIn({}, userProfile.experiment_bucket_map, attributeExperimentBucketMap);
119+
return fns.assign({}, userProfile.experiment_bucket_map, attributeExperimentBucketMap);
120120
};
121121

122122

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ NotificationCenter.prototype.addNotificationListener = function (notificationTyp
6666
}
6767

6868
var callbackAlreadyAdded = false;
69-
fns.forEach(this.__notificationListeners[notificationType], function (listenerEntry) {
69+
(this.__notificationListeners[notificationType] || []).forEach(function(listenerEntry) {
7070
if (listenerEntry.callback === callback) {
7171
callbackAlreadyAdded = true;
7272
return false;
@@ -102,12 +102,13 @@ NotificationCenter.prototype.removeNotificationListener = function (listenerId)
102102
var indexToRemove;
103103
var typeToRemove;
104104
fns.forOwn(this.__notificationListeners, function (listenersForType, notificationType) {
105-
fns.forEach(listenersForType, function (listenerEntry, i) {
105+
(listenersForType || []).every(function(listenerEntry, i) {
106106
if (listenerEntry.id === listenerId) {
107107
indexToRemove = i;
108108
typeToRemove = notificationType;
109109
return false;
110110
}
111+
return true
111112
});
112113
if (indexToRemove !== undefined && typeToRemove !== undefined) {
113114
return false;
@@ -160,7 +161,7 @@ NotificationCenter.prototype.clearNotificationListeners = function (notification
160161
*/
161162
NotificationCenter.prototype.sendNotifications = function (notificationType, notificationData) {
162163
try {
163-
fns.forEach(this.__notificationListeners[notificationType], function (listenerEntry) {
164+
(this.__notificationListeners[notificationType] || []).forEach(function(listenerEntry) {
164165
var callback = listenerEntry.callback;
165166
try {
166167
callback(notificationData);

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

Lines changed: 9 additions & 9 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) {
58-
projectConfig.experiments.push(fns.assignIn(experiment, {groupId: Id}));
55+
Object.keys(projectConfig.groupIdMap || {}).forEach(function(Id) {
56+
experiments = fns.cloneDeep(projectConfig.groupIdMap[Id].experiments);
57+
(experiments || []).forEach(function(experiment) {
58+
projectConfig.experiments.push(fns.assign(experiment, {groupId: Id}));
5959
});
6060
});
6161

6262
projectConfig.rolloutIdMap = fns.keyBy(projectConfig.rollouts || [], 'id');
6363
fns.forOwn(projectConfig.rolloutIdMap, function(rollout) {
64-
fns.forEach(rollout.experiments || [], function(experiment) {
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,12 +73,12 @@ 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

8080
// Creates { <variationId>: { key: <variationKey>, id: <variationId> } } mapping for quick lookup
81-
fns.assignIn(projectConfig.variationIdMap, fns.keyBy(experiment.variations, 'id'));
81+
fns.assign(projectConfig.variationIdMap, fns.keyBy(experiment.variations, 'id'));
8282

8383
fns.forOwn(experiment.variationKeyMap, function(variation) {
8484
if (variation.variables) {
@@ -94,7 +94,7 @@ module.exports = {
9494
projectConfig.featureKeyMap = fns.keyBy(projectConfig.featureFlags || [], 'key');
9595
fns.forOwn(projectConfig.featureKeyMap, function(feature) {
9696
feature.variableKeyMap = fns.keyBy(feature.variables, 'key');
97-
fns.forEach(feature.experimentIds || [], function(experimentId) {
97+
(feature.experimentIds || []).forEach(function(experimentId) {
9898
// Add this experiment in experiment-feature map.
9999
if (projectConfig.experimentFeatureMap[experimentId]) {
100100
projectConfig.experimentFeatureMap[experimentId].push(feature.id);

packages/optimizely-sdk/lib/index.browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ module.exports = {
107107
eventDispatcher = config.eventDispatcher;
108108
}
109109

110-
config = fns.assignIn(
110+
config = fns.assign(
111111
{
112112
clientEngine: enums.JAVASCRIPT_CLIENT_ENGINE,
113113
eventBatchSize: DEFAULT_EVENT_BATCH_SIZE,

packages/optimizely-sdk/lib/index.react_native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ module.exports = {
8686
config.skipJSONValidation = true;
8787
}
8888

89-
config = fns.assignIn(
89+
config = fns.assign(
9090
{
9191
clientEngine: enums.JAVASCRIPT_CLIENT_ENGINE,
9292
eventBatchSize: DEFAULT_EVENT_BATCH_SIZE,

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,28 @@ var keyBy = require('@optimizely/js-sdk-utils').keyBy;
1818
var MAX_NUMBER_LIMIT = Math.pow(2, 53);
1919

2020
module.exports = {
21-
assign: require('lodash/assign'),
22-
assignIn: require('lodash/assignIn'),
21+
assign: function (target) {
22+
if (!target) {
23+
return {};
24+
}
25+
if (typeof Object.assign === 'function') {
26+
return Object.assign.apply(Object, arguments);
27+
} else {
28+
var to = Object(target);
29+
for (var index = 1; index < arguments.length; index++) {
30+
var nextSource = arguments[index];
31+
if (nextSource !== null && nextSource !== undefined) {
32+
for (var nextKey in nextSource) {
33+
// Avoid bugs when hasOwnProperty is shadowed
34+
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
35+
to[nextKey] = nextSource[nextKey];
36+
}
37+
}
38+
}
39+
}
40+
return to;
41+
}
42+
},
2343
cloneDeep: require('lodash/cloneDeep'),
2444
currentTimestamp: function() {
2545
return Math.round(new Date().getTime());
@@ -33,7 +53,6 @@ module.exports = {
3353
return item[key];
3454
});
3555
},
36-
forEach: require('lodash/forEach'),
3756
forOwn: require('lodash/forOwn'),
3857
uuid: function() {
3958
return uuid.v4();

0 commit comments

Comments
 (0)