-
-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathfuzzysort.html
97 lines (66 loc) · 2.24 KB
/
fuzzysort.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script defer src="https://unpkg.com/hyperhtml@latest/min.js"></script>
<script>
this.onload = () => {
const numberOfElements = 10000;
const items = Array.apply(null, Array(numberOfElements)).map((el, i) => ({text: i})).sort(() => .5 < Math.random())
const sortMethods = [
() => 0,
(a, b) => a.text - b.text,
(a, b) => b.text - a.text
];
function hyperHtmlTest() {
const $node = document.createElement('div');
const $div = document.createElement('div');
const $button = document.createElement('button');
const bound = hyperHTML.bind($div);
const wire = hyperHTML.wire;
let sortMethodIndex = 0;
function render () {
const sortMethod = sortMethods[sortMethodIndex++ % sortMethods.length];
bound`${items.concat().sort(sortMethod).map(
item => wire(item)`<p>${item.text}</p>`
)}`;
}
$node.appendChild($button);
$node.appendChild($div);
$button.textContent = 'HyperHTml Sort';
$button.onclick = render;
return $node;
}
function normalHtmlTest() {
const $node = document.createElement('div')
const $div = document.createElement('div')
const $button = document.createElement('button')
let sortMethodIndex = 0
function render () {
const sortMethod = sortMethods[sortMethodIndex++ % sortMethods.length];
while($div.childNodes.length)
$div.removeChild($div.childNodes[0]);
const frag = document.createDocumentFragment();
items.concat().sort(sortMethod).forEach(item => {
const p = document.createElement('p');
p.textContent = item.text;
frag.appendChild(p);
})
$div.appendChild(frag);
}
$node.appendChild($button);
$node.appendChild($div);
$button.textContent = 'NormalHtml Sort';
$button.onclick = render;
return $node;
}
document.body.appendChild(normalHtmlTest());
document.body.appendChild(hyperHtmlTest());
};
</script>
</head>
<body>
</body>
</html>