Last active
March 1, 2018 18:59
-
-
Save VitorLuizC/740db4c716946994be26fac28cd581f3 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
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