Last active
August 8, 2017 19:03
-
-
Save enjikaka/599fa5aadd75b95c885bd744a58a0c48 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class TemplateComponent extends HTMLElement { | |
| /*...*/ | |
| async getTemplate (data) { | |
| const templator = (t, d) => new Function('return `' + t + '`').call(d); | |
| async function loadTemplate () { | |
| return new Promise(resolve => { | |
| document.currentScript.ownerDocument.addEventListener('DOMContentLoaded', event => { | |
| resolve(event.target.querySelector('template')); | |
| }, false); | |
| }); | |
| } | |
| const template = await loadTemplate(); | |
| template.innerHTML = templator(template.innerHTML, data); | |
| return template; | |
| } | |
| /*...*/ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment