Last active
September 6, 2019 16:06
-
-
Save mrsharpoblunto/938e73631414fec4fa3e35ecf4128897 to your computer and use it in GitHub Desktop.
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
<script type="text/javascript"> | |
// the server will write out the paths of any API calls it plans to | |
// run server-side so the client knows to wait for the server, rather | |
// than doing its own XHR request for the data | |
window.__data = { | |
'/my/api/path': { | |
waiting: [], | |
} | |
}; | |
window.__dataLoaded = function(path, data) { | |
const cacheEntry = window.__data[path]; | |
if (cacheEntry) { | |
cacheEntry.data = data; | |
for (var i = 0;i < cacheEntry.waiting.length; ++i) { | |
cacheEntry.waiting[i].resolve(cacheEntry.data); | |
} | |
cacheEntry.waiting = []; | |
} | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment