Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between lit-element & lit-html?

I have been learning Polymer and this came in - The future of web (lit-element & lit-html)

I understood that lit-html is for HTML templating with a couple of efficient techniques. At the same time lit-element is a lightweight web component base class which has the lit-html inside it.

Question: If lit-element comes with lit-html, I would solely use the lit-element for all my purposes. What exactly does lit-html doing explicitly with its own separate context.

One should choose lit-element or lit-html while developing a standalone web application?

Any help on guiding through this would be of much help!

like image 445
Hitesh Misro Avatar asked Jun 16 '20 16:06

Hitesh Misro


People also ask

What is difference between lit and lit element?

I understood that lit-html is for HTML templating with a couple of efficient techniques. At the same time lit-element is a lightweight web component base class which has the lit-html inside it. Question: If lit-element comes with lit-html, I would solely use the lit-element for all my purposes.

What are lit elements?

Literary elements include plot, theme, character and tone. In contrast, literary techniques are non-universal features of literature and include figurative language, irony, and foreshadowing.

What is lit element used for?

Lit is a simple library for building fast, lightweight web components that work in any framework, or with no framework at all. With Lit you can build shareable components, applications, design systems, and more.

Is Lit element a library?

Simple.Lit is a simple library for building fast, lightweight web components. At Lit's core is a boilerplate-killing component base class that provides reactive state, scoped styles, and a declarative template system that's tiny, fast and expressive.


2 Answers

First, lets clarify the following points:

  • Web Components technologies are supported in modern browsers by default. You can build a Web Component application using the browser's API.

  • HTML templates has been around since 2013 at least.

lit-element library is a "lightweight" version of Web Components. You'd use it if you want to build an application in Web Component and if you do so, you'd be using its built-in lit-html via html to create HTML templates

On the other hand, Just like you stated, lit-html is a library which has efficient mechanism to create and update HTML templates. You can use it for whenever you'd need an HTML template irrespective of the framework/library you are using for your website, if any.

For an example, you could build a website with jQuery or vanilla Web Components and use lit-html to create the HTML templates.

like image 69
Matthew Barbara Avatar answered Sep 24 '22 04:09

Matthew Barbara


lit-html is a library which deals with dom rendering like other libraries e.g. React It uses the newest way of diffing the dom tree with help of native tagged templates.

var h1 = html`<h1>Header 1 <h1>`

like any other framework/library e.g. JSX it also provides you construct inside the tagged template and directives to help.

LitElement is a lightweight framework using lit-html as rendering engine. It provides you the observed properties, attributes and web components lifecycle callbacks

For a web application you should go with LitElement, if you do not want to reinvent the data binding, caching, callbacks etc. you would definitely require more like state tracking, routing etc. which you can employ from other libraries or develop your own.

like image 32
Kulvinder Avatar answered Sep 23 '22 04:09

Kulvinder