Repository URL to install this package:
|
Version:
3.8.1-rc0 ▾
|
/**
* Tries to retrieve an experiment id from the current store state, when one is present.
* This only takes into account experiments mounted by experiments.
*
* This is a selector used with the select effect.
*
* @param {*} state
* @param {string} testName
*/
export function getFirstExperimentId(state, testName) {
// Mounted experiments are these experiments currently mounted with withAbTest wrapped components
const mountedExperiments = state.ab && state.ab.mountedExperiments;
// Experiments are all experiments send to the client from Optimize
const experiments = state.ab && state.ab.experiments;
if (mountedExperiments && mountedExperiments[testName]) {
return experiments[testName].experimentId;
}
return undefined;
}
/**
* Tries to retrieve an experiment id from the current store state, when one is present.
* This checks global experiments, set by isGlobal flag.
*
* This is a selector used with the select effect.
*
* @param {*} state
* @param {string} testName
*/
export function getFirstGlobalExperimentId(state, testName) {
// Experiments are all experiments send to the client from Optimize
const experiments = state.ab && state.ab.experiments;
const experiment =
Boolean(experiments) &&
Object.keys(experiments).find(
exper => exper === testName && Boolean(experiments[exper].experimentId) && Boolean(experiments[exper].isGlobal)
);
if (experiment) {
return experiments[experiment].experimentId;
}
return undefined;
}