MCPcopy
hub / github.com/ampproject/amphtml / toggleExperiment_

Function toggleExperiment_

tools/experiments/experiments.js:313–343  ·  view source on GitHub ↗

* Toggles the experiment. * @param {string} id * @param {string} name * @param {boolean=} opt_on

(id, name, opt_on)

Source from the content-addressed store, hash-verified

311 * @param {boolean=} opt_on
312 */
313function toggleExperiment_(id, name, opt_on) {
314 const currentlyOn = isExperimentOn_(id);
315 const on = opt_on === undefined ? !currentlyOn : opt_on;
316 // Protect against accidental choice.
317 const confirmMessage = on
318 ? 'Do you really want to activate the AMP experiment?'
319 : 'Do you really want to deactivate the AMP experiment?';
320
321 showConfirmation_(`${confirmMessage}: "${name}"`, () => {
322 switch (id) {
323 case EXPERIMENTAL_CHANNEL_ID:
324 setAmpOptInCookie_(
325 on ? AMP_OPT_IN_COOKIE.EXPERIMENTAL : AMP_OPT_IN_COOKIE.DISABLED
326 );
327 break;
328 case BETA_CHANNEL_ID:
329 setAmpOptInCookie_(
330 on ? AMP_OPT_IN_COOKIE.BETA : AMP_OPT_IN_COOKIE.DISABLED
331 );
332 break;
333 case NIGHTLY_CHANNEL_ID:
334 setAmpOptInCookie_(
335 on ? AMP_OPT_IN_COOKIE.NIGHTLY : AMP_OPT_IN_COOKIE.DISABLED
336 );
337 break;
338 default:
339 toggleExperiment(window, id, on);
340 }
341 update();
342 });
343}
344
345/**
346 * Shows confirmation and calls callback if it's approved.

Callers

nothing calls this directly

Calls 5

isExperimentOn_Function · 0.85
showConfirmation_Function · 0.85
setAmpOptInCookie_Function · 0.85
toggleExperimentFunction · 0.85
updateFunction · 0.70

Tested by

no test coverage detected