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

Exposes experiment variants as variable for URL replacement. #3868

Merged
merged 5 commits into from
Jul 7, 2016

Conversation

lannka
Copy link
Contributor

@lannka lannka commented Jul 1, 2016

For #1411

@cramforce
Copy link
Member

Over to @erwinmombay. I'll take a look later.

user.assert(variants,
'To use variable VARIANT, amp-experiment should be configured');
user.assert(variants[experiment] !== undefined,
`The value passed to VARIANT() is not a valid experiment name:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is new line intentional here? this will add a \n

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought IDE would be smart here :-). Fixed.

if (variantName) {
results[experimentName] = variantName;
}
results[experimentName] = variantName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think we can return results here then we can get rid of .then(() => results)

cc @jridgewell

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, we're inside a Promise.all here, so we'd get an array of [results, results, results, ...].

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah gotcha, didnt see we were inside a .map. thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very legit questioning. It's indeed a bit overwhelming here. Let me break some inlining to gain some readability :-)

results[experimentName] = variantName;
});
});
this.experimentVariants = Promise.all(variants).then(() => results);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much more readable. much appreciated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a type declaration for experimentVariants ? and does it need to be public?

@erwinmombay
Copy link
Member

LGTM, deferring to @cramforce for final LGTM

// Returns assigned variant name for the given experiment.
this.set_('VARIANT', experiment => {
return this.variants_.then(variants => {
user.assert(variants,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For better or worse, we only report errors for substitutions. This allows e.g. analytics vendors to have generic configuration that works with and without variants.

Return null if none is defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean:

if (error) {
  user.error(...);
  return null;
}

If returning null will end up with an empty string, it's identical to user.assert. Because in the replace logic, we catch all errors. See one of my test cases for example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are correct. Disregard.

@cramforce
Copy link
Member

LGTM

@lannka lannka merged commit d445cd4 into ampproject:master Jul 7, 2016
@lannka lannka deleted the experiment_variable branch July 7, 2016 19:46
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.

None yet

4 participants