Created
December 9, 2018 11:34
-
-
Save gbrits/7cb07d890faf7faa8468c5a003899bbc to your computer and use it in GitHub Desktop.
How to retrieve from an API sequentially via AXIOS. Open to improvement.
This file contains 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 retrievePagesSequentially() { | |
var index = 1; | |
function request() { | |
return window.axios.get(`/api/cache/${index}`).then((response) => { | |
let dataSet = response.data.length; | |
jQuery('#headerTop').text(`${((index - 1) * 250) + dataSet} Orders`); | |
ShopifyApp.flashNotice(`Page ${index} retrieved...`); | |
index++; | |
if (dataSet < 250) { | |
setTimeout(() => { | |
ShopifyApp.Bar.loadingOff(); | |
ShopifyApp.flashNotice('All orders retrieved successfully!'); | |
location.reload(); | |
}, 1000); | |
return 'done' | |
} | |
return request(); | |
}); | |
} | |
return request(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment