8000 refactor: Removed dependency on lodash.isEmpty (#403) · github/optimizely-javascript-sdk@ee5a24d · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit ee5a24d

Browse files
refactor: Removed dependency on lodash.isEmpty (optimizely#403)
Summary: to reduce package size, we are trying to gradually get rid of lodash library. This PR removes isEmpty function Test plan: Added unit tests for this Co-authored-by: zashraf1985 <35262377+zashraf1985@users.noreply.github.com>
1 parent d298f48 commit ee5a24d

File tree

5 files changed

+8
-9
lines changed

5 files changed

+8
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ DecisionService.prototype.__checkIfExperimentIsActive = function(configObj, expe
144144
* @return {string|null} Forced variation if it exists for user ID, otherwise null
145145
*/
146146
DecisionService.prototype.__getWhitelistedVariation = function(experiment, userId) {
147-
if (!fns.isEmpty(experiment.forcedVariations) && experiment.forcedVariations.hasOwnProperty(userId)) {
147+
if (experiment.forcedVariations && experiment.forcedVariations.hasOwnProperty(userId)) {
148148
var forcedVariationKey = experiment.forcedVariations[userId];
149149
if (experiment.variationKeyMap.hasOwnProperty(forcedVariationKey)) {
150150
var forcedBucketingSucceededMessageLog = sprintf(LOG_MESSAGES.USER_FORCED_IN_VARIATION, MODULE_NAME, userId, forcedVariationKey);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ module.exports = {
122122
*/
123123
getExperimentId: function(projectConfig, experimentKey) {
124124
var experiment = projectConfig.experimentKeyMap[experimentKey];
125-
if (fns.isEmpty(experiment)) {
125+
if (!experiment) {
126126
throw new Error(sprintf(ERROR_MESSAGES.INVALID_EXPERIMENT_KEY, MODULE_NAME, experimentKey));
127127
}
128128
return experiment.id;
@@ -137,7 +137,7 @@ module.exports = {
137137
*/
138138
getLayerId: function(projectConfig, experimentId) {
139139
var experiment = projectConfig.experimentIdMap[experimentId];
140-
if (fns.isEmpty(experiment)) {
140+
if (!experiment) {
141141
throw new Error(sprintf(ERROR_MESSAGES.INVALID_EXPERIMENT_ID, MODULE_NAME, experimentId));
142142
}
143143
return experiment.layerId;
@@ -190,7 +190,7 @@ module.exports = {
190190
*/
191191
getExperimentStatus: function(projectConfig, experimentKey) {
192192
var experiment = projectConfig.experimentKeyMap[experimentKey];
193-
if (fns.isEmpty(experiment)) {
193+
if (!experiment) {
194194
throw new Error(sprintf(ERROR_MESSAGES.INVALID_EXPERIMENT_KEY, MODULE_NAME, experimentKey));
195195
}
196196
return experiment.status;
@@ -224,7 +224,7 @@ module.exports = {
224224
*/
225225
getExperimentAudienceConditions: function(projectConfig, experimentKey) {
226226
var experiment = projectConfig.experimentKeyMap[experimentKey];
227-
if (fns.isEmpty(experiment)) {
227+
if (!experiment) {
228228
throw new Error(sprintf(ERROR_MESSAGES.INVALID_EXPERIMENT_KEY, MODULE_NAME, experimentKey));
229229
}
230230

@@ -286,7 +286,7 @@ module.exports = {
286286
*/
287287
getTrafficAllocation: function(projectConfig, experimentKey) {
288288
var experiment = projectConfig.experimentKeyMap[experimentKey];
289-
if (fns.isEmpty(experiment)) {
289+
if (!experiment) {
290290
throw new Error(sprintf(ERROR_MESSAGES.INVALID_EXPERIMENT_KEY, MODULE_NAME, experimentKey));
291291
}
292292
return experiment.trafficAllocation;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ Optimizely.prototype.getVariation = function(experimentKey, userId, attributes)
375375
}
376376

377377
var experiment = configObj.experimentKeyMap[experimentKey];
378-
if (fns.isEmpty(experiment)) {
378+
if (!experiment) {
379379
this.logger.log(LOG_LEVEL.DEBUG, sprintf(ERROR_MESSAGES.INVALID_EXPERIMENT_KEY, MODULE_NAME, experimentKey));
380380
return null;
381381
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ module.exports = {
2424
currentTimestamp: function() {
2525
return Math.round(new Date().getTime());
2626
},
27-
isEmpty: require('lodash/isEmpty'),
2827
isFinite: function(number) {
2928
return _isFinite(number) && Math.abs(number) <= MAX_NUMBER_LIMIT;
3029
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ describe('lib/utils/fns', function() {
3838
});
3939
});
4040
});
41-
});
41+
});

0 commit comments

Comments
 (0)
0