Skip to content

Instantly share code, notes, and snippets.

@VitorLuizC
Last active March 1, 2018 18:59
Show Gist options
  • Save VitorLuizC/740db4c716946994be26fac28cd581f3 to your computer and use it in GitHub Desktop.
Save VitorLuizC/740db4c716946994be26fac28cd581f3 to your computer and use it in GitHub Desktop.
const FutureSelect = (selector, parent = document) => {
let request = null
return new Promise((resolve) => {
const select = () => {
const elements = parent && [ ...parent.querySelectorAll(selector) ] || []
if (!elements.length) {
request = requestAnimationFrame(select)
return
}
cancelAnimationFrame(request)
resolve(elements)
}
select()
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment