-
Notifications
You must be signed in to change notification settings - Fork 83
feat(api): Decision Notification Listener for isFeatureEnabled and getEnabledFeatures APIs. #245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
32b9719
1b6e3be
3b2b61b
26aef1a
c30da19
b139eec
e7e5252
126ce3b
04376c8
7e23dce
d8b6504
9c3ec8a
6365632
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -502,26 +502,46 @@ Optimizely.prototype.isFeatureEnabled = function(featureKey, userId, attributes) | |||
return false; | ||||
} | ||||
|
||||
var featureEnabled = false; | ||||
var experimentKey = null; | ||||
var variationKey = null; | ||||
var decision = this.decisionService.getVariationForFeature(feature, userId, attributes); | ||||
var variation = decision.variation; | ||||
|
||||
if (!!variation) { | ||||
featureEnabled = variation.featureEnabled; | ||||
if (decision.decisionSource === DECISION_SOURCES.EXPERIMENT) { | ||||
experimentKey = decision.experiment.key; | ||||
variationKey = decision.variation.key; | ||||
// got a variation from the exp, so we track the impression | ||||
this._sendImpressionEvent(decision.experiment.key, decision.variation.key, userId, attributes); | ||||
} | ||||
if (variation.featureEnabled === true) { | ||||
this.logger.log( | ||||
LOG_LEVEL.INFO, | ||||
sprintf(LOG_MESSAGES.FEATURE_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId) | ||||
); | ||||
return true; | ||||
} | ||||
} | ||||
this.logger.log( | ||||
LOG_LEVEL.INFO, | ||||
sprintf(LOG_MESSAGES.FEATURE_NOT_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId) | ||||
|
||||
if (featureEnabled === true) { | ||||
this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.FEATURE_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId)); | ||||
} else { | ||||
this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.FEATURE_NOT_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId)); | ||||
featureEnabled = false; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this value already be false? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it can be undefined when featureEnabled property is missing from the variation as specified in this test
|
||||
} | ||||
|
||||
this.notificationCenter.sendNotifications( | ||||
enums.NOTIFICATION_TYPES.DECISION, | ||||
{ | ||||
type: DECISION_INFO_TYPES.FEATURE, | ||||
userId: userId, | ||||
attributes: attributes || {}, | ||||
decisionInfo: { | ||||
featureKey: featureKey, | ||||
featureEnabled: featureEnabled, | ||||
source: decision.decisionSource, | ||||
sourceExperimentKey: experimentKey, | ||||
sourceVariationKey: variationKey, | ||||
} | ||||
} | ||||
); | ||||
return false; | ||||
|
||||
return featureEnabled; | ||||
} catch (e) { | ||||
this.logger.log(LOG_LEVEL.ERROR, e.message); | ||||
this.errorHandler.handleError(e); | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DECISION_SOURCES.EXPERIMENT is experiment (lower case) and not EXPERIMENT (upper case). Similarly, DECISION_SOURCES.ROLLOUT is rollout (lower case) and not ROLLOUT (upper case). We should update that,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitalized decision source values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused about this comment. @aliabbasrizvi are you saying that the values (not the enum key) should be lower case or upper case.
This PR is changing it from lowercase to uppercase.
It's unclear what we want the final state to be (uppercase or lowercase)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, should have been clear. The value should be EXPERIMENT/ROLLOUT.