[lit-helpers] appendTemplate
See original GitHub issueUsually you want to render
a template to a container, and let lit-html handle subsequent updates.
Other times, you just want a quick-and-easy way to generate a chunk of DOM from some state, and then append it to some container, without caring about future updates.
for that, we could provide appendTemplate
function appendTemplate(template, target) {
const tmp = document.createElement('div');
render(template, tmp);
const { firstElementChild } = tmp;
target.appendChild(firstElementChild);
tmp.remove();
return firstElementChild;
}
A good reason not to do this is that it breaks one of lit-html’s main advantages, namely targetted updates. We could call it expensiveAppendTemplate
or something?
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Allow injection of static content into templates · Issue #78 · lit/lit
With current implementation I propose in Add UnsafeStatic extension #568 we are unable to use React-style approach to change tag's name depending on...
Read more >Writing templates - Lit.dev
The lit-html template is a tagged template literal. The template itself ... The render function actually creates DOM nodes and appends them to...
Read more >Testing: Helpers - Open Web Components
Test fixtures can be set up by using a string or a lit template. You don't need to use lit-html in your project...
Read more >Bind dictionary of attributes on element definition
I can not bind them one by one declaring the attribute name and value manually as they are user given parameters. I have...
Read more >Glyph-components NPM | npm.io
Run npm install my-component --save · Add an import to the npm packages import my-component; · Then you can use the element anywhere...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Lit html has a new template content directive. Sounds like that should be used here + a test fixture?
To me render implies displaying something on the screen, not that it creates an element that isnt commected.