Skip to content

Commit 4a7dbb3

Browse files
committed
Merge branch 'master' of https://github.com/Lxxyx/js-framework-benchmark into Lxxyx-master
2 parents e86ef08 + 4ce1d20 commit 4a7dbb3

File tree

4 files changed

+290
-0
lines changed

4 files changed

+290
-0
lines changed

frameworks/keyed/rax/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8" />
6+
<title>Rax</title>
7+
<link href="/css/currentStyle.css" rel="stylesheet" />
8+
</head>
9+
10+
<body>
11+
<div id='main'></div>
12+
<script src='dist/main.js'></script>
13+
</body>
14+
15+
</html>

frameworks/keyed/rax/package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "js-framework-benchmark-rax",
3+
"version": "1.1.1",
4+
"description": "Rax demo",
5+
"main": "index.js",
6+
"js-framework-benchmark": {
7+
"frameworkVersionFromPackage": "rax"
8+
},
9+
"scripts": {
10+
"build-dev": "webpack --watch",
11+
"build-prod": "webpack"
12+
},
13+
"keywords": [
14+
"rax",
15+
"webpack"
16+
],
17+
"author": "Stefan Krause",
18+
"license": "Apache-2.0",
19+
"homepage": "https://github.com/krausest/js-framework-benchmark",
20+
"repository": {
21+
"type": "git",
22+
"url": "https://github.com/krausest/js-framework-benchmark.git"
23+
},
24+
"devDependencies": {
25+
"@babel/core": "7.1.2",
26+
"@babel/preset-env": "7.1.0",
27+
"@babel/preset-react": "7.0.0",
28+
"@babel/plugin-proposal-class-properties": "7.1.0",
29+
"babel-loader": "8.0.4",
30+
"terser-webpack-plugin": "1.1.0",
31+
"webpack": "4.22.0",
32+
"webpack-cli": "3.1.2"
33+
},
34+
"dependencies": {
35+
"rax": "0.6.7"
36+
}
37+
}

frameworks/keyed/rax/src/main.jsx

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/**
2+
* @jsx Rax.createElement
3+
*/
4+
var Rax = require('rax');
5+
6+
function random(max) {
7+
return Math.round(Math.random() * 1000) % max;
8+
}
9+
10+
const A = ["pretty", "large", "big", "small", "tall", "short", "long", "handsome", "plain", "quaint", "clean",
11+
"elegant", "easy", "angry", "crazy", "helpful", "mushy", "odd", "unsightly", "adorable", "important", "inexpensive",
12+
"cheap", "expensive", "fancy"];
13+
const C = ["red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black", "orange"];
14+
const N = ["table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger", "pizza", "mouse",
15+
"keyboard"];
16+
17+
let nextId = 1;
18+
19+
function buildData(count) {
20+
const data = new Array(count);
21+
for (let i = 0; i < count; i++) {
22+
data[i] = {
23+
id: nextId++,
24+
label: `${A[random(A.length)]} ${C[random(C.length)]} ${N[random(N.length)]}`,
25+
};
26+
}
27+
return data;
28+
}
29+
30+
const GlyphIcon = <span className="glyphicon glyphicon-remove" aria-hidden="true"></span>;
31+
32+
class Row extends Rax.Component {
33+
onSelect = () => {
34+
this.props.select(this.props.item);
35+
}
36+
37+
onRemove = () => {
38+
this.props.remove(this.props.item);
39+
}
40+
41+
shouldComponentUpdate(nextProps) {
42+
return nextProps.item !== this.props.item || nextProps.selected !== this.props.selected;
43+
}
44+
45+
render() {
46+
let { selected, item } = this.props;
47+
return (<tr className={selected ? "danger" : ""}>
48+
<td className="col-md-1">{item.id}</td>
49+
<td className="col-md-4"><a onClick={this.onSelect}>{item.label}</a></td>
50+
<td className="col-md-1"><a onClick={this.onRemove}>{GlyphIcon}</a></td>
51+
<td className="col-md-6"></td>
52+
</tr>);
53+
}
54+
}
55+
56+
function Button({ id, cb, title }) {
57+
return (
58+
<div className="col-sm-6 smallpad">
59+
<button type="button" className="btn btn-primary btn-block" id={id} onClick={cb}>{title}</button>
60+
</div>
61+
);
62+
}
63+
64+
class Jumbotron extends Rax.Component {
65+
shouldComponentUpdate() {
66+
return false;
67+
}
68+
69+
render() {
70+
const { run, runLots, add, update, clear, swapRows } = this.props;
71+
return (
72+
<div className="jumbotron">
73+
<div className="row">
74+
<div className="col-md-6">
75+
<h1>Rax keyed</h1>
76+
</div>
77+
<div className="col-md-6">
78+
<div className="row">
79+
<Button id="run" title="Create 1,000 rows" cb={run} />
80+
<Button id="runlots" title="Create 10,000 rows" cb={runLots} />
81+
<Button id="add" title="Append 1,000 rows" cb={add} />
82+
<Button id="update" title="Update every 10th row" cb={update} />
83+
<Button id="clear" title="Clear" cb={clear} />
84+
<Button id="swaprows" title="Swap Rows" cb={swapRows} />
85+
</div>
86+
</div>
87+
</div>
88+
</div>
89+
);
90+
}
91+
}
92+
93+
class Main extends Rax.Component {
94+
state = {
95+
data: [],
96+
selected: 0,
97+
};
98+
99+
run = () => {
100+
this.setState({ data: buildData(1000), selected: 0 });
101+
}
102+
103+
runLots = () => {
104+
this.setState({ data: buildData(10000), selected: 0 });
105+
}
106+
107+
add = () => {
108+
this.setState({ data: this.state.data.concat(buildData(1000)), selected: this.state.selected });
109+
}
110+
111+
update = () => {
112+
const data = this.state.data;
113+
for (let i = 0; i < data.length; i += 10) {
114+
const item = data[i];
115+
data[i] = { id: item.id, label: item.label + ' !!!' };
116+
}
117+
this.forceUpdate();
118+
}
119+
120+
select = (item) => {
121+
this.setState({ selected: item.id });
122+
}
123+
124+
remove = (item) => {
125+
const data = this.state.data;
126+
data.splice(data.indexOf(item), 1);
127+
this.forceUpdate();
128+
}
129+
130+
clear = () => {
131+
this.setState({ data: [], selected: 0 });
132+
}
133+
134+
swapRows = () => {
135+
const data = this.state.data;
136+
if (data.length > 998) {
137+
let temp = data[1];
138+
data[1] = data[998];
139+
data[998] = temp;
140+
}
141+
this.forceUpdate();
142+
}
143+
144+
render() {
145+
return (<div className="container">
146+
<Jumbotron run={this.run} runLots={this.runLots} add={this.add} update={this.update} clear={this.clear} swapRows={this.swapRows} />
147+
<table className="table table-hover table-striped test-data"><tbody>
148+
{this.state.data.map((item) => (
149+
<Row key={item.id} item={item} selected={this.state.selected === item.id} select={this.select} remove={this.remove}></Row>
150+
))}
151+
</tbody></table>
152+
<span className="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span>
153+
</div>);
154+
}
155+
}
156+
157+
Rax.render(
158+
<Main />,
159+
document.getElementById('main'),
160+
);
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
const path = require('path');
2+
const webpack = require('webpack');
3+
const TerserPlugin = require('terser-webpack-plugin');
4+
5+
module.exports = {
6+
mode: 'production',
7+
// mode: 'development',
8+
entry: {
9+
main: path.join(__dirname, 'src', 'main.jsx'),
10+
},
11+
output: {
12+
path: path.join(__dirname, 'dist'),
13+
filename: '[name].js'
14+
},
15+
resolve: {
16+
extensions: ['.js', '.jsx']
17+
},
18+
module: {
19+
rules: [{
20+
test: /\.jsx?$/,
21+
exclude: /node_modules/,
22+
use: [
23+
{
24+
loader: 'babel-loader',
25+
options: {
26+
presets: ['@babel/preset-env', '@babel/preset-react'],
27+
plugins: ['@babel/plugin-proposal-class-properties'],
28+
}
29+
}
30+
]
31+
}]
32+
},
33+
optimization: {
34+
minimizer: [
35+
new TerserPlugin({
36+
terserOptions: {
37+
parse: {
38+
// we want terser to parse ecma 8 code. However, we don't want it
39+
// to apply any minfication steps that turns valid ecma 5 code
40+
// into invalid ecma 5 code. This is why the 'compress' and 'output'
41+
// sections only apply transformations that are ecma 5 safe
42+
// https://github.com/facebook/create-react-app/pull/4234
43+
ecma: 8,
44+
},
45+
compress: {
46+
ecma: 5,
47+
warnings: false,
48+
// Disabled because of an issue with Uglify breaking seemingly valid code:
49+
// https://github.com/facebook/create-react-app/issues/2376
50+
// Pending further investigation:
51+
// https://github.com/mishoo/UglifyJS2/issues/2011
52+
comparisons: false,
53+
},
54+
mangle: {
55+
safari10: true,
56+
},
57+
output: {
58+
ecma: 5,
59+
comments: false,
60+
// Turned on because emoji and regex is not minified properly using default
61+
// https://github.com/facebook/create-react-app/issues/2488
62+
ascii_only: true,
63+
},
64+
},
65+
// Use multi-process parallel running to improve the build speed
66+
// Default number of concurrent runs: os.cpus().length - 1
67+
parallel: true,
68+
// Enable file caching
69+
cache: true,
70+
}),
71+
]
72+
},
73+
plugins: [
74+
new webpack.DefinePlugin({
75+
'process.env': { NODE_ENV: JSON.stringify('production') }
76+
}),
77+
],
78+
};

0 commit comments

Comments
 (0)