-
Notifications
You must be signed in to change notification settings - Fork 316
/
increasing-items.html
54 lines (40 loc) · 934 Bytes
/
increasing-items.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!doctype html>
<html>
<head>
<title>simple virtual dom example</title>
</head>
<body>
</body>
<script src="../dist/bundle.js"></script>
<script>
var el = svd.el
var diff = svd.diff
var patch = svd.patch
var count = 0
function renderTree () {
count++
var items = []
var color = (count % 2 === 0)
? 'blue'
: 'red'
for (var i = 0; i < count; i++) {
items.push(el('li', ['Item #' + i]))
}
return el('div', {'id': 'container'}, [
el('h1', {style: 'color: ' + color}, ['simple virtal dom']),
el('p', ['the count is :' + count]),
el('ul', items)
])
}
var tree = renderTree()
var root = tree.render()
document.body.appendChild(root)
setInterval(function () {
var newTree = renderTree()
var patches = diff(tree, newTree)
console.log(patches)
patch(root, patches)
tree = newTree
}, 1000)
</script>
</html>