Skip to content

Commit 812856f

Browse files
leontrolskioli-russell
authored andcommitted
add lit-html to docs
1 parent 38ad5b3 commit 812856f

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

benchmark/lit-html.html

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<link href="https://localvoid.github.io/uibench-base/0.1.0/styles.css" rel="stylesheet" />
6+
<title>UI Benchmark: Vanilla [innerHTML]</title>
7+
</head>
8+
<body>
9+
<div id="App"></div>
10+
<script src="https://localvoid.github.io/uibench-base/0.1.0/uibench.js"></script>
11+
<script type="module">
12+
import {html, render, nothing} from 'https://unpkg.com/lit-html?module';
13+
// UI
14+
function tableCellClick(e, prop){
15+
console.log(`Click${prop}`)
16+
e.preventDefault()
17+
e.stopPropagation()
18+
}
19+
const TableCell = prop=>html`<td
20+
class="TableCell"
21+
data-text=${prop}
22+
@click=${e=>tableCellClick(e, prop)}
23+
>${prop}</td>`
24+
const TableRow = data=>html`<tr
25+
class="TableRow ${data.active? 'active' : ''}"
26+
data-id=${data.id}
27+
>${TableCell(`#${data.id}`)} ${data.props.map(TableCell)}</tr>`
28+
const Table = data=>html`<table class="Table"><tbody>${data.table.items.map(TableRow)}</tbody></table>`
29+
const animBoxStyle = time=>`
30+
border-radius:${time % 10}px;
31+
background:rgba(0,0,0,${0.5 + ((time % 10) / 10)});
32+
`
33+
const AnimBox = props=>html`<div class="AnimBox" style=${animBoxStyle(props.time)} data-id=${props.id}></div>`
34+
const Anim =data=>html`<div class="Anim">${data.anim.items.map(AnimBox)}</div>`
35+
const TreeLeaf = props=>html`<li class="TreeLeaf">${props.id}</li>`
36+
const TreeNode = data=>html`<ul class="TreeNode">${data.children.map(n=>n.container? TreeNode(n) : TreeLeaf(n))}</ul>`
37+
const Tree = data=>html`<div class="Tree">${TreeNode(data.tree.root)}</div>`
38+
39+
// test
40+
// uibench.init in the html (one per framework)
41+
function renderState(container, state){
42+
const location = state && state.location
43+
const fs = {
44+
table: Table,
45+
anim: Anim,
46+
tree: Tree,
47+
}
48+
render(html`<div class="Main">${fs[location](state)}</div>`, container)
49+
}
50+
function renderSamples(samples){
51+
document.body.innerHTML = "<pre>" + JSON.stringify(samples, null, " ") + "</pre>"
52+
}
53+
54+
let container
55+
document.addEventListener("DOMContentLoaded", (e) => {
56+
container = document.querySelector("#App")
57+
uibench.run(state=>renderState(container, state), renderSamples)
58+
})
59+
</script>
60+
<script>uibench.init("lit-html", "0.0.1")</script>
61+
</body>
62+
</html>

0 commit comments

Comments
 (0)