question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[lit-helpers] appendTemplate

See original GitHub issue

Usually 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:open
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
LarsDenBakkercommented, Jan 20, 2020

Lit html has a new template content directive. Sounds like that should be used here + a test fixture?

0reactions
LarsDenBakkercommented, Jan 31, 2020

To me render implies displaying something on the screen, not that it creates an element that isnt commected.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found