Code clean
This commit is contained in:
parent
e8261ca7e6
commit
174e9e09e8
|
@ -10,16 +10,15 @@ const DEFAULT_STATE = {
|
||||||
const reducer = (state = DEFAULT_STATE, action) => {
|
const reducer = (state = DEFAULT_STATE, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case TYPES.TOGGLE_EXPERIMENT:
|
case TYPES.TOGGLE_EXPERIMENT:
|
||||||
let experiments = [...state.experiments];
|
|
||||||
experiments = experiments.map((experiment) => {
|
|
||||||
if (experiment.name === action.experimentName) {
|
|
||||||
experiment.variation = action.newVariation;
|
|
||||||
}
|
|
||||||
return experiment;
|
|
||||||
});
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
experiments,
|
experiments: state.experiments.map((experiment) => ({
|
||||||
|
...experiment,
|
||||||
|
variation:
|
||||||
|
experiment.name === action.experimentName
|
||||||
|
? action.newVariation
|
||||||
|
: experiment.variation,
|
||||||
|
})),
|
||||||
};
|
};
|
||||||
case TYPES.SET_EXPERIMENTS:
|
case TYPES.SET_EXPERIMENTS:
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -7,25 +7,17 @@ import { EXPERIMENT_NAME_PREFIX } from './constants';
|
||||||
export function* getExperiments() {
|
export function* getExperiments() {
|
||||||
const storageItems = Object.entries({ ...window.localStorage }).filter(
|
const storageItems = Object.entries({ ...window.localStorage }).filter(
|
||||||
(item) => {
|
(item) => {
|
||||||
if (item[0].indexOf(EXPERIMENT_NAME_PREFIX) === 0) {
|
return item[0].indexOf(EXPERIMENT_NAME_PREFIX) === 0;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const experiments = [];
|
const experiments = storageItems.map((storageItem) => {
|
||||||
storageItems.forEach((storageItem) => {
|
|
||||||
const [key, value] = storageItem;
|
const [key, value] = storageItem;
|
||||||
const objectValue = JSON.parse(value);
|
const objectValue = JSON.parse(value);
|
||||||
|
return {
|
||||||
const experiment = {
|
|
||||||
name: key.replace(EXPERIMENT_NAME_PREFIX, ''),
|
name: key.replace(EXPERIMENT_NAME_PREFIX, ''),
|
||||||
variation: objectValue.variationName
|
variation: objectValue.variationName || 'control',
|
||||||
? objectValue.variationName
|
|
||||||
: 'control',
|
|
||||||
};
|
};
|
||||||
experiments.push(experiment);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
yield setExperiments(experiments);
|
yield setExperiments(experiments);
|
||||||
|
|
Loading…
Reference in New Issue