Created
August 27, 2021 04:29
-
-
Save pfftdammitchris/e9be6cb702659bbf73ff3d07ca5e409d 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
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