Last active
April 16, 2019 04:39
-
-
Save rgoytacaz/cf532207596e316f7fa80f2f3f694bcd to your computer and use it in GitHub Desktop.
Waiting data to be available dynamically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
//AVOIDS AN INFINITE LOOP | |
var tries=0; | |
var maxTries=5; | |
var callFunctionOrSetTimeout = function(){ | |
tries++; | |
if(window.vtexjs&&window.vtexjs.checkout&&window.vtexjs.checkout.orderForm){ | |
console.log('Data available'); | |
//DO STUFF | |
} | |
else if(tries < maxTries){ | |
setTimeout(callFunctionOrSetTimeout,2000); | |
} | |
}; | |
callFunctionOrSetTimeout(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment