Is lit has diff mechanism when render ? #3245
-
Is that mean lit will diff new template result to the old one ? can I treat it like a virtual-dom ? If the answer is 'Yes', can I just use it with a state management lib like mobx to develop large apps? I am tired of frameworks . What I do will like this:
I will put the whole data of the app in the stroe, so it could be very large, will this cause performance problems ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Yes, lit-html (the core rendering part of Lit) can be used in effectively the same way you would use a virtual DOM in that it isn't going to recreate that const f = (x) => html`<div>${x}</div>`;
render(f('This is the first render.'), document.body);
await new Promise(r => setTimeout(r, 3000));
render(f('This is the second render.'), document.body); In the example above, lit-html will recognize that it was asked to render a const f = (x) => html`
<div> You
<div> can
<div> do
<div> this
<div> and
<div> only
<div> the value of "${x}" </div>
</div> will
</div> ever
</div> be
</div> compared
</div> or
</div> updated.
`;
render(f('this text'), document.body);
await new Promise(r => setTimeout(r, 3000));
render(f('the thing here'), document.body); However, if your render(html`<div>${'This is the first render.'}</div>`, document.body);
await new Promise(r => setTimeout(r, 3000));
render(html`<div>${'This is the second render.'}</div>`, document.body); ... but it also isn't walking a structure that scales with the number of nodes it represents on every render to figure that out. You might be interested in this talk from CDS 2017 given by @justinfagnani. The timestamp in that link is when he describes how lit-html's coarser diffing compares with a virtual DOM and the rest of the video has more details about how it works. Footnotes |
Beta Was this translation helpful? Give feedback.
Yes, lit-html (the core rendering part of Lit) can be used in effectively the same way you would use a virtual DOM in that it isn't going to recreate that
<span>
every time you callrender
. However, Lit'shtml
template tag doesn't return a tree of virtual nodes, but aTemplateResult
, whichrender
uses to decide if all the static pieces of thathtml
call are already rendered into the destinationcontainer
.In the example above, lit-html will recognize that it was asked to render a
TemplateResult
t…