20. the job of a templating system
• balance between
• developer experience
• fast boot
• fast update
21. What does the platform provide?
• template element
• (tagged) template literals
22. The template element
• holds “inert” DOM
• scripts don’t run
• styles don’t apply
• easily cloned
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template
23.
24. Template literals
• instead of quotes uses backticks - `
• can span multiple lines
• can embed expressions
• can be tagged…
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
25.
26. tagged template literals
• a tag is a function that processes the template literal - both the literal and the
expressive parts. Can return anything
27.
28. tagged template literals
• a tag is a function that processes the template literal - both the literal and the
expressive parts. Can return anything.
• the literal parts-array will be the same (===) in consecutive calls
29.
30. can we use this for creating a cool
templating system?
31. the job of a templating system
• balance between
• developer experience
• fast boot
• fast update
32. a solution?
• template in js means tools
• create template to stamp out clone
• identity of staticParts as caching-key
• We know what changed…
34. lit-html
• A tag-function (called html) that returns templating instructions (called
TemplateResult)
• A render method to produce and maintain dom from TemplateResult
• <2kb gzipped and super fast
https://github.com/Polymer/lit-html
53. Performance
• 2 aproaches to rendering/updating
• Be smart (Polymer) - scales with complexity (no of changes)
• Be fast (React) - scales with number of nodes (but very fast because of
vdom)
54. Performance
• 2 aproaches to rendering/updating
• Be smart (Polymer) - scales with complexity (no of changes)
• Be fast (React) - scales with number of nodes (but very fast because of
vdom)
• Lit-html tries to sit in the middle (scales with expressions)
62. Lit-html and webcomponents
• Lit is build to be a great fit with web-components
• make a render-method that returns a TemplateResult
• use property setters to invalidate
• re-render when invalidated
• dispatch native DOM-events