-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: Add JS experiment client #26
Conversation
51009ee
to
9607799
Compare
clients/js/src/index.ts
Outdated
if (toss >= range) { | ||
return undefined; | ||
} | ||
let buckets = Array.apply(null, Array(variant_count)).map(function (_, i) { return traffic * (i + 1); }); |
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.
This is fine, but too computations happening here, making an array of NULL
s, mapping over it, and then in the finding the index of the bucket and finally using the index to get the variant/bucket.
I think this can be just written in one single for
loop.
clients/js/src/index.ts
Outdated
@@ -39,3 +39,61 @@ export class CacReader { | |||
return deepMerge(targetConfig, ...requiredOverrides); | |||
} | |||
} | |||
|
|||
export class ExperimentReader { | |||
experiments: ExperimentStore; |
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.
ExperimentStore
is not really required, you could just use Experiments
here
clients/js/src/index.ts
Outdated
const experiments = []; | ||
const iter = this.experiments.values(); | ||
|
||
while (true) { |
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.
Can we just use a for loop? Infinite loops are dangerous and there are a limited number of experiments
this.experiments = new Map(experiments.map(exp => [exp.id, exp])); | ||
} | ||
|
||
public getApplicableVariant(data: IObject, toss: number): Array<String> { |
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.
the type number
allows floating point values too, can we add an assertion that toss is always a positive integer?
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.
Can we add the toss isInteger check here?
d793442
to
859be27
Compare
this.experiments = new Map(experiments.map(exp => [exp.id, exp])); | ||
} | ||
|
||
public getApplicableVariant(data: IObject, toss: number): Array<String> { |
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.
Can we add the toss isInteger check here?
Problem
Experimentation client not present in JS
Solution
Add Experimentation client in JS