SHARE
TWEET

Untitled

a guest Feb 23rd, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. console.clear();
  2. window.AB = undefined;
  3. (() => {
  4.  
  5. window.AB = window.AB || {
  6.   push(test){
  7.     this.tests.push(test);
  8.   },
  9.   tests: [],
  10.   isEnabled(){
  11.     return false;
  12.   },
  13.   getEnabledVariantIds(){
  14.     return [];
  15.   },
  16. };
  17.  
  18. const { AB } = window;
  19.  
  20. AB.push('largeButtons');
  21. AB.push('sortByPrice');
  22. AB.push('showRecentlyViewed');
  23.  
  24. setTimeout(() => {
  25.   const { AB } = window;
  26.  
  27.   if(!AB){return;}
  28.  
  29.   const ABLib = {
  30.     isEnabled(test){
  31.       const foundTest = findTestByName(this.tests, test);
  32.       if(! foundTest){ return false; }
  33.       return this.getEnabledVariantIds().includes(foundTest.id);
  34.     },
  35.     getEnabledVariantIds(){
  36.       return this.enabledVariants;
  37.     },
  38.     tests: [],
  39.     enabledVariants: [],
  40.     push(){},
  41.   };
  42.  
  43.   ABLib.tests = getVariantsWithIds(AB.tests);
  44.    
  45.   getEnabledVariants(ABLib.tests).then((response) => {
  46.     ABLib.enabledVariants = response;
  47.     window.AB = ABLib;
  48.   });
  49.  
  50.   function findTestByName(tests, name){
  51.     return tests.find(item => item.test === name);
  52.   }
  53.  
  54.   function getVariantsWithIds(tests){
  55.     const letters = ['A', 'B', 'C', 'D', 'E'];
  56.     return tests.map((item, index) => ({
  57.       test: item,
  58.       id: letters[index]
  59.     }));
  60.   };
  61.  
  62.   function getEnabledVariants(tests){
  63.     return Promise.resolve([tests[0].id, tests[1].id]);
  64.   }
  65. },100);
  66. })()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top