Style fix

This commit is contained in:
moon 2022-05-11 12:25:07 -07:00
parent b395fb0ce9
commit dd6f161467
1 changed files with 14 additions and 14 deletions

View File

@ -9,42 +9,42 @@ import { apiFetch } from '@wordpress/data-controls';
import TYPES from './action-types';
import { EXPERIMENT_NAME_PREFIX, TRANSIENT_NAME_PREFIX } from './constants';
function toggleFrontendExperiment(experimentName, newVariation) {
function toggleFrontendExperiment( experimentName, newVariation ) {
const storageItem = JSON.parse(
window.localStorage.getItem(EXPERIMENT_NAME_PREFIX + experimentName)
window.localStorage.getItem( EXPERIMENT_NAME_PREFIX + experimentName )
);
storageItem.variationName = newVariation;
window.localStorage.setItem(
EXPERIMENT_NAME_PREFIX + experimentName,
JSON.stringify(storageItem)
JSON.stringify( storageItem )
);
}
function* toggleBackendExperiment(experimentName, newVariation) {
function* toggleBackendExperiment( experimentName, newVariation ) {
try {
const payload = {};
payload[TRANSIENT_NAME_PREFIX + experimentName] = newVariation;
yield apiFetch({
payload[ TRANSIENT_NAME_PREFIX + experimentName ] = newVariation;
yield apiFetch( {
method: 'POST',
path: '/wc-admin/options',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(payload),
});
} catch (error) {
body: JSON.stringify( payload ),
} );
} catch ( error ) {
throw new Error();
}
}
export function* toggleExperiment(experimentName, currentVariation, source) {
export function* toggleExperiment( experimentName, currentVariation, source ) {
const newVariation =
currentVariation === 'control' ? 'treatment' : 'control';
if (source === 'frontend') {
toggleFrontendExperiment(experimentName, newVariation);
if ( source === 'frontend' ) {
toggleFrontendExperiment( experimentName, newVariation );
} else {
yield toggleBackendExperiment(experimentName, newVariation);
yield toggleBackendExperiment( experimentName, newVariation );
}
return {
@ -55,7 +55,7 @@ export function* toggleExperiment(experimentName, currentVariation, source) {
};
}
export function setExperiments(experiments) {
export function setExperiments( experiments ) {
return {
type: TYPES.SET_EXPERIMENTS,
experiments,