Created
August 27, 2021 04:29
-
-
Save pfftdammitchris/fc5555a1eab2489af2c1bdf8e328cd96 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
// elements.js | |
function getIframe(container = document.body) { | |
return new Promise((resolve, reject) => { | |
const attributes = { src: 'http://www.google.com/abc.png' } | |
const elem = document.createElement('iframe') | |
// Assuming "attributes" also includes the "src" | |
Object.entries(attributes).forEach(([attr, value]) => { | |
elem.setAttribute(attr, value) | |
}) | |
elem.addEventListener('load', function (evt) { | |
resolve(elem) | |
}) | |
elem.addEventListener('error', reject) | |
}) | |
} | |
// app.js | |
import { getIframe } from '../elements' | |
async function initContainer({ children, tagName = 'div' } = {}) { | |
const container = document.createElement(tagName) | |
if (children) { | |
container.appendChild(await children(container)) | |
} | |
return container | |
} | |
async function startApp() { | |
await initContainer({ children: getIframe }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment