My goal here is to write a JS component which contains no markup, but takes the markup it needs from the DOM.
Oh I get it now. Nothing "lightweight" comes to mind.
I guess the closest thing that you could do with lit-html is evaluate the template somehow.
Don't do this at home.
<div id="app"></div> <template id="test-template"> hello ${data.name} </template> <script> import {html, render} from 'https://unpkg.com/lit-html?module'; var generator = function(string) { var fn = new Function( 'html', 'data', `return html\`${string}\`;` ); return fn.bind(null, html); }; var template = document.getElementById('test-template'); var helloComponent = generator(template.content.textContent); render( helloComponent({name: 'world'}), document.getElementById('app') ); </script>
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Oh I get it now. Nothing "lightweight" comes to mind.
I guess the closest thing that you could do with lit-html is evaluate the template somehow.
Don't do this at home.