Created
July 7, 2019 19:26
-
-
Save ezekielchentnik/c67d6b4e379e47b5b4175cfd2d36372f to your computer and use it in GitHub Desktop.
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
const microtask = () => { | |
let node = document.createTextNode(''), | |
queue = [], | |
i = 0 | |
new window.MutationObserver(() => { | |
while (queue.length) queue.shift()() | |
}).observe(node, { characterData: true }) | |
return fn => { | |
queue.push(fn) | |
node.data = (i = 1 - i) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment