-
-
Notifications
You must be signed in to change notification settings - Fork 640
Expand file tree
/
Copy pathapp.js
More file actions
173 lines (141 loc) · 3.89 KB
/
Copy pathapp.js
File metadata and controls
173 lines (141 loc) · 3.89 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import { linkEvent, render, version } from 'inferno';
/*
* The purpose of this benchmark is to test performance regressions in normalization process.
* This benchmark is slow intentionally. There are nested arrays and other "bad code".
*/
uibench.init('Inferno (normalization test)', version);
function TreeLeaf({ children }) {
return <li className="TreeLeaf">{children}</li>;
}
function shouldDataUpdate(lastProps, nextProps) {
return lastProps !== nextProps;
}
function TreeNode({ data }) {
var length = data.children.length;
var children = new Array(length);
for (var i = 0; i < length; i++) {
var n = data.children[i];
var id = n.id;
if (n.container) {
children[i] = <TreeNode onComponentShouldUpdate={shouldDataUpdate} data={n} key={id} />;
} else {
children[i] = (
<TreeLeaf onComponentShouldUpdate={shouldDataUpdate} key={id}>
{id}
</TreeLeaf>
);
}
}
return <ul className="TreeNode">{children}</ul>;
}
function tree(data) {
return (
<div className="Tree">
<TreeNode data={data.root} onComponentShouldUpdate={shouldDataUpdate} />
</div>
);
}
function AnimBox({ data }) {
var time = data.time % 10;
var style = 'border-radius:' + time + 'px;' + 'background:rgba(0,0,0,' + (0.5 + time / 10) + ')';
return <div data-id={data.id} style={style} className="AnimBox" />;
}
function anim(data) {
var items = data.items;
var length = items.length;
var children = new Array(length);
for (var i = 0; i < length; i++) {
var item = items[i];
// Here we are using onComponentShouldUpdate functional Component hook, to short circuit rendering process of AnimBox Component
// When the data does not change
children[i] = <AnimBox data={item} onComponentShouldUpdate={shouldDataUpdate} key={item.id} />;
}
return <div className="Anim">{children}</div>;
}
function onClick(text, e) {
console.log('Clicked', text);
e.stopPropagation();
}
function TableCell({ children }) {
/*
* The carbage code is intentional
*/
return (
<td onClick={linkEvent(children, onClick)} className="TableCell">
{null}
{false}
{[children]}
</td>
);
}
function TableRow({ data }) {
var classes = 'TableRow';
if (data.active) {
classes = 'TableRow active';
}
var cells = data.props;
var length = cells.length + 1;
var children = new Array(length);
children[0] = <TableCell onComponentShouldUpdate={shouldDataUpdate}>{'#' + data.id}</TableCell>;
for (var i = 1; i < length; i++) {
children[i] = <TableCell onComponentShouldUpdate={shouldDataUpdate}>{cells[i - 1]}</TableCell>;
}
/*
* The carbage code is intentional
*/
return (
<tr data-id={data.id} className={classes}>
{null}
{children}
{false}
</tr>
);
}
function table(data) {
var items = data.items;
var length = items.length;
var children = new Array(length);
for (var i = 0; i < length; i++) {
var item = items[i];
children[i] = (
<TableRow data={item} onComponentShouldUpdate={shouldDataUpdate} key={item.id}>
{item}
</TableRow>
);
}
/*
* The carbage code is intentional
*/
return (
<table className="Table">
{[]}
{children}
{[[]]}
</table>
);
}
var lastMainData;
function main(data) {
lastMainData = data;
var location = data.location;
var section;
if (location === 'table') {
section = table(data.table);
} else if (location === 'anim') {
section = anim(data.anim);
} else if (location === 'tree') {
section = tree(data.tree);
}
return <div className="Main">{section}</div>;
}
document.addEventListener('DOMContentLoaded', function (e) {
var container = document.querySelector('#App');
uibench.run(
function (state) {
render(main(state), container);
},
function (samples) {
render(<pre>{JSON.stringify(samples, null, ' ')}</pre>, container);
}
);
});