Skip to content

Instantly share code, notes, and snippets.

@rgoytacaz
Last active April 16, 2019 04:39
Show Gist options
  • Save rgoytacaz/cf532207596e316f7fa80f2f3f694bcd to your computer and use it in GitHub Desktop.
Save rgoytacaz/cf532207596e316f7fa80f2f3f694bcd to your computer and use it in GitHub Desktop.
Waiting data to be available dynamically
(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