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

feat: Add JS experiment client #26

Merged
merged 1 commit into from
May 6, 2024
Merged

feat: Add JS experiment client #26

merged 1 commit into from
May 6, 2024

Conversation

ayushjain17
Copy link
Collaborator

Problem

Experimentation client not present in JS

Solution

Add Experimentation client in JS

@ayushjain17 ayushjain17 requested a review from a team as a code owner May 3, 2024 13:25
@ayushjain17 ayushjain17 force-pushed the jsExpClient branch 2 times, most recently from 51009ee to 9607799 Compare May 4, 2024 06:01
if (toss >= range) {
return undefined;
}
let buckets = Array.apply(null, Array(variant_count)).map(function (_, i) { return traffic * (i + 1); });
Copy link
Collaborator

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 NULLs, 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.

@@ -39,3 +39,61 @@ export class CacReader {
return deepMerge(targetConfig, ...requiredOverrides);
}
}

export class ExperimentReader {
experiments: ExperimentStore;
Copy link
Collaborator

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

const experiments = [];
const iter = this.experiments.values();

while (true) {
Copy link
Collaborator

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> {
Copy link
Collaborator

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?

Copy link
Collaborator

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?

clients/js/src/index.ts Show resolved Hide resolved
clients/js/src/types.ts Show resolved Hide resolved
@ayushjain17 ayushjain17 force-pushed the jsExpClient branch 2 times, most recently from d793442 to 859be27 Compare May 6, 2024 08:18
clients/js/src/index.ts Show resolved Hide resolved
this.experiments = new Map(experiments.map(exp => [exp.id, exp]));
}

public getApplicableVariant(data: IObject, toss: number): Array<String> {
Copy link
Collaborator

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?

@ayushjain17 ayushjain17 merged commit dbd101e into main May 6, 2024
4 checks passed
@ayushjain17 ayushjain17 deleted the jsExpClient branch May 6, 2024 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants