in src/amo/withExperiment.js [223:260]
setupExperiment(props) {
const { _getVariant, dispatch, isUserExcluded, storedVariants } = props;
// If the experiment is not enabled, we return a null variant.
if (!this.isEnabled()) {
return null;
}
// Always use the variant from the cookie, if it exists.
let variant = this.readVariantFromCookie();
if (!variant) {
const variantFromStore = storedVariants[id];
// Look for a variant in the Redux store.
if (variantFromStore) {
variant = variantFromStore;
}
// Otherwise if the user is to be excluded, use the NOT_IN_EXPERIMENT
// variant.
else if (isUserExcluded) {
variant = NOT_IN_EXPERIMENT;
} else {
variant = _getVariant({ variants });
}
// Do we need to store the variant in the cookie?
if (!this.cookieIncludesExperiment() && !variantFromStore) {
// Store the variant in the Redux store for use during
// `componentDidMount()` and only when the user does not yet have a
// variant in a cookie. In this case, the `experiments` state would
// be empty, which is a bit unusual as we normally have consistent
// states.
dispatch(storeExperimentVariant({ id, variant }));
}
}
return variant;
}