Last active
February 22, 2018 03:59
-
-
Save jonathantneal/fba8689eaa288aeee11b to your computer and use it in GitHub Desktop.
Document `interactive` and `complete` promises
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 onstate(readyStates, resolve) { | |
function handler() { | |
if (readyStates.includes(document.readyState)) { | |
document.removeEventListener('readystatechange', handler); | |
resolve(); | |
} | |
} | |
document.addEventListener('readystatechange', handler); | |
handler(); | |
} | |
document.interactive = new Promise(function (resolve) { | |
onstate(['interactive', 'complete'], resolve); | |
}); | |
document.complete = new Promise(function (resolve) { | |
onstate(['complete'], resolve); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment