Created
May 31, 2018 05:47
-
-
Save jossmac/9bdaad354b8d7c8ca85ea42250aeeb6f to your computer and use it in GitHub Desktop.
An async querySelector equivalent
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
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