Skip to content

Instantly share code, notes, and snippets.

@ezekielchentnik
Created July 7, 2019 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezekielchentnik/c67d6b4e379e47b5b4175cfd2d36372f to your computer and use it in GitHub Desktop.
Save ezekielchentnik/c67d6b4e379e47b5b4175cfd2d36372f to your computer and use it in GitHub Desktop.
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