Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- console.clear();
- window.AB = undefined;
- (() => {
- window.AB = window.AB || {
- push(test){
- this.tests.push(test);
- },
- tests: [],
- isEnabled(){
- return false;
- },
- getEnabledVariantIds(){
- return [];
- },
- };
- const { AB } = window;
- AB.push('largeButtons');
- AB.push('sortByPrice');
- AB.push('showRecentlyViewed');
- setTimeout(() => {
- const { AB } = window;
- if(!AB){return;}
- const ABLib = {
- isEnabled(test){
- const foundTest = findTestByName(this.tests, test);
- if(! foundTest){ return false; }
- return this.getEnabledVariantIds().includes(foundTest.id);
- },
- getEnabledVariantIds(){
- return this.enabledVariants;
- },
- tests: [],
- enabledVariants: [],
- push(){},
- };
- ABLib.tests = getVariantsWithIds(AB.tests);
- getEnabledVariants(ABLib.tests).then((response) => {
- ABLib.enabledVariants = response;
- window.AB = ABLib;
- });
- function findTestByName(tests, name){
- return tests.find(item => item.test === name);
- }
- function getVariantsWithIds(tests){
- const letters = ['A', 'B', 'C', 'D', 'E'];
- return tests.map((item, index) => ({
- test: item,
- id: letters[index]
- }));
- };
- function getEnabledVariants(tests){
- return Promise.resolve([tests[0].id, tests[1].id]);
- }
- },100);
- })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement