Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfftdammitchris/fc5555a1eab2489af2c1bdf8e328cd96 to your computer and use it in GitHub Desktop.
Save pfftdammitchris/fc5555a1eab2489af2c1bdf8e328cd96 to your computer and use it in GitHub Desktop.
// 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