Skip to content

Commit

Permalink
Move parseMepParam
Browse files Browse the repository at this point in the history
  • Loading branch information
markpadbe authored and vgoodric committed Jun 11, 2024
1 parent 54e04cb commit 4a71225
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions libs/features/personalization/personalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ const createDefaultExperiment = (manifest) => ({
variants: {},
});

export async function getPersConfig(info, override = false) {
export async function getPersConfig(info, variantOverride = false) {
const {
name,
manifestData,
Expand All @@ -624,7 +624,7 @@ export async function getPersConfig(info, override = false) {
disabled,
event,
} = info;
if (disabled && !override) {
if (disabled && !variantOverride) {
return createDefaultExperiment(info);
}
let data = manifestData;
Expand Down Expand Up @@ -746,12 +746,12 @@ export async function categorizeActions(experiment) {
commands: selectedVariant.commands,
};
}
function parseMepParam(config) {
const mepObject = Object.create(null);

if (!config.mep?.override) return mepObject;

config.mep.override.split('---').forEach((item) => {
function parseMepParam(mepParam) {
if (!mepParam) return false;
const mepObject = Object.create(null);
const decodedParam = decodeURIComponent(mepParam);
decodedParam.split('---').forEach((item) => {
const pair = item.trim().split('--');
if (pair.length > 1) {
const [manifestPath, selectedVariant] = pair;
Expand Down Expand Up @@ -828,19 +828,17 @@ export async function applyPers(manifests, postLCP = false) {
handleFragmentCommand,
preview: (mepButton !== 'off'
&& (config.env?.name !== 'prod' || mepParam || mepParam === '' || mepButton)),
override: mepParam ? decodeURIComponent(mepParam) : '',
variantOverride: parseMepParam(mepParam),
highlight: (mepHighlight !== undefined && mepHighlight !== 'false'),
mepParam,
targetEnabled: config.mep?.targetEnabled,
};
}

config.mep.variantOverride = parseMepParam(config);

if (!manifests?.length) return;
let experiments = manifests;
for (let i = 0; i < experiments.length; i += 1) {
experiments[i] = await getPersConfig(experiments[i], config.mep?.override);
experiments[i] = await getPersConfig(experiments[i], config.mep?.variantOverride);
}

experiments = cleanAndSortManifestList(experiments);
Expand Down

0 comments on commit 4a71225

Please sign in to comment.