Skip to content
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

Added control and default treatment handling #3

Merged
merged 1 commit into from
Feb 19, 2016
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
6 changes: 3 additions & 3 deletions demos/browser-split/web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
console.log('SPLIT DEMO!');
console.log(
'Early evaluation of feature \'sdk\' before startup the engine =>',
splitio.getTreatment('sdk', 'default-treatment')
splitio.getTreatment('sdk')
);

splitio.start({
Expand All @@ -16,8 +16,8 @@ splitio.start({
}
}).then(function() {
console.log(
'Evaluation of feature \'sdk\' after startup the engine =>',
splitio.getTreatment('sdk', 'default-treatment')
"Evaluation of feature 'sdk' after startup the engine =>",
splitio.getTreatment('sdk')
);
}).catch(function(error) {
console.log(error);
Expand Down
2 changes: 1 addition & 1 deletion demos/express-split/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var splitEngine = null;

app.use(function (req, res, next) {
if (splitEngine) {
if (splitEngine.getTreatment('4a2c4490-ced1-11e5-9b97-d8a25e8b1578', 'sdk', 'off') === 'on') {
if (splitEngine.getTreatment('4a2c4490-ced1-11e5-9b97-d8a25e8b1578', 'sdk') === 'on') {
next();
} else {
res.sendStatus(403);
Expand Down
6 changes: 3 additions & 3 deletions packages/splitio-engine/es6/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ class Split {
return this.segments;
}

getTreatment(key, defaultTreatment) {
getTreatment(key) {
if (this.baseInfo.killed) {
return defaultTreatment;
return this.baseInfo.defaultTreatment;
}

let treatment = this.evaluator(key, this.baseInfo.seed);

return treatment !== undefined ? treatment : defaultTreatment;
return treatment !== undefined ? treatment : this.baseInfo.defaultTreatment;
}

isTreatment(key, treatment) {
Expand Down
2 changes: 1 addition & 1 deletion packages/splitio-metrics/es6/utils/now.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module.exports = (function () {
if (typeof performance === 'object' && typeof performance.now === 'function') {
return performance.now;
return performance.now.bind(performance);
} else if (typeof process === 'object' && typeof hrtime === 'function') {
return function now() {
return process.hrtime[0] * 1e3 + process.hrtime[1] * 1e-3; // convert it to milis
Expand Down
14 changes: 4 additions & 10 deletions packages/splitio/es6/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,21 @@ function splitio(settings /*: object */) /*: Promise */ {

return core.start().then(storage => {
return {
getTreatment(key /*: string */, featureName /*: string */, defaultTreatment /*: string */) /*: string */ {
getTreatment(key /*: string */, featureName /*: string */) /*: string */ {
let split = storage.splits.get(featureName);
let treatment = null;
let treatment = 'control';

let stop = tracker();
if (split) {
treatment = split.getTreatment(key, defaultTreatment);
treatment = split.getTreatment(key);

log(`feature ${featureName} key ${key} evaluated as ${treatment}`);
} else {
treatment = defaultTreatment;

log(`feature ${featureName} doesn't exist, using default ${treatment}`);
log(`feature ${featureName} doesn't exist`);
}
stop();

return treatment;
},

isTreatment(key /*: string */, featureName /*: string */, treatment /*: string */) /*: bool */ {
return this.getTreatment(key, featureName) === treatment;
}
};
});
Expand Down