Skip to content

Commit 20d5a05

Browse files
committed
Merge branch 'Havunen-master'
2 parents 70478ca + d8cf504 commit 20d5a05

File tree

23 files changed

+970
-27
lines changed

23 files changed

+970
-27
lines changed

inferno-v3.10.1-keyed/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
"devDependencies": {
2020
"babel-core": "6.26.0",
2121
"babel-loader": "7.1.2",
22-
"babel-plugin-inferno": "3.3.0",
22+
"babel-plugin-inferno": "3.3.1",
2323
"babel-plugin-syntax-jsx": "6.18.0",
2424
"babel-preset-es2015": "6.24.1",
2525
"babel-preset-stage-0": "6.24.1",
26-
"webpack": "3.8.1"
26+
"webpack": "3.10.0"
2727
},
2828
"dependencies": {
2929
"inferno": "3.10.1",

inferno-v3.10.1-keyed/webpack.config.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ module.exports = [{
4141
path.resolve(__dirname, "src"),
4242
"node_modules"
4343
],
44-
extensions: extensions,
45-
alias: {
46-
"inferno": __dirname+"/node_modules/inferno/dist/inferno.min.js",
47-
"inferno-component": __dirname+"/node_modules/inferno-component/dist/inferno-component.min.js"
48-
}
44+
extensions: extensions
4945
}
5046
}];

inferno-v3.10.1-non-keyed/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
"devDependencies": {
2020
"babel-core": "6.26.0",
2121
"babel-loader": "7.1.2",
22-
"babel-plugin-inferno": "3.3.0",
22+
"babel-plugin-inferno": "3.3.1",
2323
"babel-plugin-syntax-jsx": "6.18.0",
2424
"babel-preset-es2015": "6.24.1",
2525
"babel-preset-stage-0": "6.24.1",
26-
"webpack": "3.8.1"
26+
"webpack": "3.10.0"
2727
},
2828
"dependencies": {
2929
"inferno": "3.10.1",

inferno-v3.10.1-non-keyed/src/controller.jsx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,6 @@ var stopMeasure = function() {
3333
}
3434
}
3535

36-
function handleClick(e) {
37-
let func;
38-
let id;
39-
let val = e.target.defaultValue;
40-
41-
if (val) {
42-
func = val.func;
43-
id = val.id;
44-
} else {
45-
val = e.target.parentNode.defaultValue;
46-
if (val) {
47-
func = val.func;
48-
id = val.id;
49-
}
50-
}
51-
func && func(id);
52-
}
53-
5436
const span = <span className="glyphicon glyphicon-remove" aria-hidden="true" noNormalize></span>;
5537
const td = <td className="col-md-6" noNormalize></td>;
5638

inferno-v4.0.0-keyed/.babelrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"plugins": [
3+
["inferno", {"imports": true}],
4+
["transform-es2015-template-literals", {"loose": true }],
5+
"transform-es2015-sticky-regex",
6+
["transform-es2015-spread", {"loose": true }],
7+
"transform-es2015-shorthand-properties",
8+
"transform-es2015-parameters",
9+
"transform-es2015-object-super",
10+
"transform-es2015-block-scoping",
11+
"transform-es2015-block-scoped-functions",
12+
["transform-es2015-destructuring", {"loose": true }],
13+
["transform-es2015-computed-properties", {"loose": true }],
14+
"transform-es2015-arrow-functions",
15+
["transform-es2015-classes", {"loose": true }],
16+
["transform-object-rest-spread", {"useBuiltIns": true }]
17+
]
18+
}

inferno-v4.0.0-keyed/index.html

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

inferno-v4.0.0-keyed/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-inferno",
3+
"version": "1.0.0",
4+
"description": "Benchmark for inferno framework",
5+
"scripts": {
6+
"build-dev": "rollup -c",
7+
"build-prod": "rollup -c --environment production"
8+
},
9+
"keywords": [
10+
"ractive"
11+
],
12+
"author": "Stefan Krause",
13+
"license": "Apache-2.0",
14+
"homepage": "https://github.com/krausest/js-framework-benchmark",
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/krausest/js-framework-benchmark.git"
18+
},
19+
"devDependencies": {
20+
"babel-core": "6.26.0",
21+
"babel-loader": "7.1.2",
22+
"babel-plugin-inferno": "4.0.0-26",
23+
"babel-plugin-syntax-jsx": "6.18.0",
24+
"babel-preset-es2015": "6.24.1",
25+
"babel-preset-stage-0": "6.24.1",
26+
"rollup": "^0.54.0",
27+
"rollup-plugin-alias": "^1.4.0",
28+
"rollup-plugin-babel": "^3.0.3",
29+
"rollup-plugin-commonjs": "^8.2.6",
30+
"rollup-plugin-node-resolve": "^3.0.2",
31+
"rollup-plugin-replace": "^2.0.0",
32+
"rollup-plugin-uglify": "^2.0.1"
33+
},
34+
"dependencies": {
35+
"inferno": "4.0.0-12"
36+
}
37+
}

inferno-v4.0.0-keyed/readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Inferno v4 Keyed
2+
This application provides example how to use JSX flags to optimize application level code for keyed algorithm.
3+
Bundle is done using Rollup.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const commonjsPlugin = require('rollup-plugin-commonjs');
2+
const nodeResolvePlugin = require('rollup-plugin-node-resolve');
3+
const babelPlugin = require('rollup-plugin-babel');
4+
const path = require('path');
5+
const replace = require('rollup-plugin-replace');
6+
const uglify = require('rollup-plugin-uglify');
7+
const alias = require('rollup-plugin-alias');
8+
9+
const isProduction = process.env.production;
10+
11+
const extensions = ['.mjs', '.js', '.jsx'];
12+
13+
// see below for details on the options
14+
const plugins = [
15+
nodeResolvePlugin({
16+
preferBuiltins: false,
17+
extensions: extensions
18+
}),
19+
replace({
20+
'process.env.NODE_ENV': isProduction ? JSON.stringify('production') : JSON.stringify('development'),
21+
sourcemap: false
22+
}),
23+
babelPlugin({
24+
exclude: 'node_modules/**',
25+
sourceMaps: false
26+
}),
27+
commonjsPlugin({
28+
sourceMap: false,
29+
extensions: extensions
30+
}),
31+
];
32+
33+
if (isProduction) {
34+
plugins.push(uglify());
35+
} else {
36+
// When in development, we want to use dev build of inferno.
37+
// DEV build has helper functionalities build for development only.
38+
// When we are shipping to production we don't want those checks to be included
39+
plugins.unshift(
40+
alias({
41+
resolve: extensions,
42+
'inferno': __dirname + '/node_modules/inferno/dist/index.dev.mjs'
43+
})
44+
)
45+
}
46+
47+
export default {
48+
input: path.join(__dirname, 'src/main.es6.js'),
49+
output: {
50+
name: 'inferno',
51+
format: 'iife',
52+
file: path.join(__dirname, 'dist', 'main.js'),
53+
sourcemap: false
54+
},
55+
plugins: plugins
56+
}
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
'use strict';
2+
3+
import { Store } from './store.es6'
4+
import { linkEvent, Component, render, createTextVNode } from 'inferno'
5+
6+
function Row({ d, id, styleClass, deleteFunc, selectFunc }) {
7+
/*
8+
* Only <td className="col-md-1"> and <a onClick={linkEvent(id, selectFunc)}/>, nodes needs $NoNormalize flags
9+
* Because they have dynamic children. We can pre-define children type by using $NoNormalize
10+
* default value for Non-normalized vNode is another vNode so we need to create virtual text node by hand
11+
*
12+
* other elements don't have children so $NoNormalize is not needed there
13+
*/
14+
return (
15+
<tr className={styleClass}>
16+
<td className="col-md-1" $NoNormalize>{createTextVNode(id + '')}</td>
17+
<td className="col-md-4">
18+
<a onClick={linkEvent(id, selectFunc)} $NoNormalize>{createTextVNode(d.label)}</a>
19+
</td>
20+
<td className="col-md-1">
21+
<a onClick={linkEvent(id, deleteFunc)}>
22+
<span className="glyphicon glyphicon-remove" aria-hidden="true"/>
23+
</a>
24+
</td>
25+
<td className="col-md-6"/>
26+
</tr>
27+
)
28+
}
29+
30+
function onComponentShouldUpdate(lastProps, nextProps) {
31+
return nextProps.d !== lastProps.d || nextProps.styleClass !== lastProps.styleClass;
32+
}
33+
34+
function createRows(store, deleteFunc, selectFunc) {
35+
const rows = [];
36+
const data = store.data;
37+
const selected = store.selected;
38+
39+
for (let i = 0; i < data.length; i++) {
40+
const d = data[i];
41+
const id = d.id;
42+
43+
rows.push(
44+
<Row
45+
styleClass={id === selected ? 'danger' : null}
46+
key={id}
47+
d={d}
48+
id={id}
49+
selected={selected}
50+
deleteFunc={deleteFunc}
51+
selectFunc={selectFunc}
52+
onComponentShouldUpdate={onComponentShouldUpdate}
53+
/>
54+
);
55+
}
56+
57+
/*
58+
* We can optimize rendering rows by pre-defining children types.
59+
* In this case all children are keyed: so we add flag $HasKeyedChildren and $NoNormalize
60+
* when $NoNormalize is used we need to make sure there are no holes in the array and are keys are unique
61+
*/
62+
return <tbody $HasKeyedChildren $NoNormalize>{rows}</tbody>;
63+
}
64+
65+
export class Controller extends Component {
66+
constructor(props) {
67+
super(props);
68+
this.state = { store: new Store() };
69+
this.select = this.select.bind(this);
70+
this.delete = this.delete.bind(this);
71+
this.add = this.add.bind(this);
72+
this.run = this.run.bind(this);
73+
this.update = this.update.bind(this);
74+
this.runLots = this.runLots.bind(this);
75+
this.clear = this.clear.bind(this);
76+
this.swapRows = this.swapRows.bind(this);
77+
this.start = 0;
78+
}
79+
80+
run() {
81+
event.stopPropagation();
82+
this.state.store.run();
83+
this.setState({ store: this.state.store });
84+
}
85+
86+
add() {
87+
event.stopPropagation();
88+
this.state.store.add();
89+
this.setState({ store: this.state.store });
90+
}
91+
92+
update() {
93+
event.stopPropagation();
94+
this.state.store.update();
95+
this.setState({ store: this.state.store });
96+
}
97+
98+
select(id, event) {
99+
event.stopPropagation();
100+
this.state.store.select(id);
101+
this.setState({ store: this.state.store });
102+
}
103+
104+
delete(id, event) {
105+
event.stopPropagation();
106+
this.state.store.delete(id);
107+
this.setState({ store: this.state.store });
108+
}
109+
110+
runLots() {
111+
event.stopPropagation();
112+
this.state.store.runLots();
113+
this.setState({ store: this.state.store });
114+
}
115+
116+
clear(event) {
117+
event.stopPropagation();
118+
this.state.store.clear();
119+
this.setState({ store: this.state.store });
120+
}
121+
122+
swapRows() {
123+
event.stopPropagation();
124+
this.state.store.swapRows();
125+
this.setState({ store: this.state.store });
126+
}
127+
128+
render() {
129+
/*
130+
* Only <table> needs $NoNormalize flag everything else is static
131+
* tables children is tbody so another vNode, no other flags needed
132+
*/
133+
return (<div className="container">
134+
<div className="jumbotron">
135+
<div className="row">
136+
<div className="col-md-6">
137+
<h1>Inferno - keyed</h1>
138+
</div>
139+
<div className="col-md-6">
140+
<div className="row">
141+
<div className="col-sm-6 smallpad">
142+
<button type="button" className="btn btn-primary btn-block" id="run" onClick={this.run}>Create 1,000
143+
rows
144+
</button>
145+
</div>
146+
<div className="col-sm-6 smallpad">
147+
<button type="button" className="btn btn-primary btn-block" id="runlots" onClick={this.runLots}>Create
148+
10,000 rows
149+
</button>
150+
</div>
151+
<div className="col-sm-6 smallpad">
152+
<button type="button" className="btn btn-primary btn-block" id="add" onClick={this.add}>Append 1,000
153+
rows
154+
</button>
155+
</div>
156+
<div className="col-sm-6 smallpad">
157+
<button type="button" className="btn btn-primary btn-block" id="update" onClick={this.update}>Update
158+
every 10th row
159+
</button>
160+
</div>
161+
<div className="col-sm-6 smallpad">
162+
<button type="button" className="btn btn-primary btn-block" id="clear" onClick={this.clear}>Clear
163+
</button>
164+
</div>
165+
<div className="col-sm-6 smallpad">
166+
<button type="button" className="btn btn-primary btn-block" id="swaprows" onClick={this.swapRows}>Swap
167+
Rows
168+
</button>
169+
</div>
170+
</div>
171+
</div>
172+
</div>
173+
</div>
174+
<table className="table table-hover table-striped test-data" $NoNormalize>
175+
{createRows(this.state.store, this.delete, this.select)}
176+
</table>
177+
<span className="preloadicon glyphicon glyphicon-remove" aria-hidden="true"/>
178+
</div>);
179+
}
180+
}
181+
182+
render(<Controller/>, document.getElementById("main"));

0 commit comments

Comments
 (0)