forked from domvm/domvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff-patch.html
50 lines (43 loc) · 875 Bytes
/
diff-patch.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
<!doctype html>
<html>
<head>
<title>domvm - diff / patch optim</title>
</head>
<body>
<script src="../dist/nano/domvm.nano.js"></script>
<script>
var el = domvm.defineElement;
var idle = false;
function View(vm) {
return {
diff: {
vals: function(vm) {
return {idle: idle};
},
then: function(vm, o, n) {
if (o.idle != n.idle) {
if (n.idle)
vm.node.patch({class: "yyy", style: "display: none;"});
else
vm.node.patch({class: "xxx", style: "display: block;"});
return false;
}
}
},
render: function() {
return el(".moo", "HI");
}
};
}
var vm = domvm.createView(View).mount(document.body);
setTimeout(function() {
idle = true;
vm.redraw();
}, 1000);
setTimeout(function() {
idle = false;
vm.redraw();
}, 3000);
</script>
</body>
</html>