Skip to content

Instantly share code, notes, and snippets.

@jossmac
Created May 31, 2018 05:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jossmac/9bdaad354b8d7c8ca85ea42250aeeb6f to your computer and use it in GitHub Desktop.
Save jossmac/9bdaad354b8d7c8ca85ea42250aeeb6f to your computer and use it in GitHub Desktop.
An async querySelector equivalent
import "babel-polyfill";
const asyncQuerySelector = async (node, query) => {
try {
return await (query ? node.querySelector(query) : node);
} catch (error) {
console.error(`Cannot find ${query ? `${query} in`: ''} ${node}.`, error);
return null;
}
};
/*
asyncQuerySelector(document, "#app").then(node => {
return node; // <div id="app>...</div>
})
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment