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/e9be6cb702659bbf73ff3d07ca5e409d to your computer and use it in GitHub Desktop.
Save pfftdammitchris/e9be6cb702659bbf73ff3d07ca5e409d to your computer and use it in GitHub Desktop.
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: (container) => {
return new Promise((resolve, reject) => {
const attributes = { src: 'http://www.google.com/abc.png' }
const elem = document.createElement('iframe')
Object.entries(attributes).forEach(([attr, value]) => {
elem.setAttribute(attr, value)
})
elem.addEventListener('load', function (evt) {
resolve(elem)
})
elem.addEventListener('error', reject)
})
},
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment