Skip to content

Commit 7f0a0b5

Browse files
committed
Merge branch 'localvoid-master'
2 parents 11e3779 + 31055ce commit 7f0a0b5

File tree

7 files changed

+287
-2
lines changed

7 files changed

+287
-2
lines changed

ivi-v0.5.0/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
build
2+
dist
3+
4+
node_modules
5+
6+
.DS_Store
7+
.idea
8+
.vscode
9+
.npm-debug
10+
npm-debug.log

ivi-v0.5.0/gulpfile.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const gulp = require('gulp');
2+
const del = require('del');
3+
const rollup = require('rollup');
4+
const rollupReplace = require('rollup-plugin-replace');
5+
const rollupNodeResolve = require('rollup-plugin-node-resolve');
6+
const closureCompiler = require('google-closure-compiler-js').gulp();
7+
8+
gulp.task('clean', function () {
9+
return del(['build', 'dist']);
10+
});
11+
12+
gulp.task('bundle', ['clean'], function (done) {
13+
return rollup.rollup({
14+
format: 'es6',
15+
entry: 'src/main.js',
16+
plugins: [
17+
rollupNodeResolve(),
18+
rollupReplace({
19+
values: {
20+
__IVI_DEV__: false,
21+
__IVI_BROWSER__: true
22+
}
23+
})
24+
]
25+
}).then(function (bundle) {
26+
return bundle.write({
27+
format: 'es',
28+
dest: 'build/bundle.js'
29+
});
30+
});
31+
});
32+
33+
gulp.task('build', ['bundle'], function () {
34+
return gulp.src(['build/bundle.js'])
35+
.pipe(closureCompiler({
36+
js_output_file: 'main.js',
37+
compilation_level: 'ADVANCED',
38+
language_in: 'ECMASCRIPT6_STRICT',
39+
language_out: 'ECMASCRIPT5_STRICT',
40+
use_types_for_optimization: true,
41+
assume_function_wrapper: true,
42+
output_wrapper: '(function(){%output%}).call(this);',
43+
warning_level: 'QUIET',
44+
rewrite_polyfills: false
45+
}))
46+
.pipe(gulp.dest('dist'));
47+
});

ivi-v0.5.0/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>ivi v0.5.0</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>

ivi-v0.5.0/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"private": true,
3+
"name": "js-framework-benchmark-ivi",
4+
"version": "0.5.0",
5+
"description": "Benchmark for ivi",
6+
"author": "Stefan Krause",
7+
"license": "Apache-2",
8+
"homepage": "https://github.com/krausest/js-framework-benchmark",
9+
"repository": "https://github.com/krausest/js-framework-benchmark",
10+
"keywords": [],
11+
"scripts": {
12+
"build-dev": "gulp build",
13+
"build-prod": "gulp build"
14+
},
15+
"dependencies": {
16+
"ivi": "0.5.0"
17+
},
18+
"devDependencies": {
19+
"del": "2.2.2",
20+
"google-closure-compiler-js": "20170218.0.0",
21+
"gulp": "3.9.1",
22+
"rollup": "0.41.5",
23+
"rollup-plugin-node-resolve": "2.0.0",
24+
"rollup-plugin-replace": "1.1.1"
25+
}
26+
}

ivi-v0.5.0/src/main.js

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
import { Component, connect, Events, $h, $c, selectorData, createStore, render, update, mut } from "ivi";
2+
3+
let startTime = 0;
4+
let lastMeasure = null;
5+
6+
function startMeasure(name) {
7+
startTime = performance.now();
8+
lastMeasure = name;
9+
}
10+
11+
function stopMeasure() {
12+
const last = lastMeasure;
13+
if (lastMeasure) {
14+
window.setTimeout(function () {
15+
const now = performance.now();
16+
lastMeasure = null;
17+
console.log(`${last} took ${now - startTime}`);
18+
}, 0);
19+
}
20+
}
21+
22+
function random(max) {
23+
return Math.round(Math.random() * 1000) % max;
24+
}
25+
26+
const A = ["pretty", "large", "big", "small", "tall", "short", "long", "handsome", "plain", "quaint", "clean",
27+
"elegant", "easy", "angry", "crazy", "helpful", "mushy", "odd", "unsightly", "adorable",
28+
"important", "inexpensive", "cheap", "expensive", "fancy"];
29+
const C = ["red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black", "orange"];
30+
const N = ["table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger", "pizza",
31+
"mouse", "keyboard"];
32+
33+
let nextId = 1;
34+
35+
function buildData(count = 1000) {
36+
const data = new Array(count);
37+
for (let i = 0; i < count; i++) {
38+
data[i] = {
39+
id: nextId++,
40+
label: `${A[random(A.length)]} ${C[random(C.length)]} ${N[random(N.length)]}`,
41+
};
42+
}
43+
return data;
44+
}
45+
46+
const store = createStore(
47+
{ data: mut([]), selected: null },
48+
function (state, action) {
49+
const data = state.data.ref;
50+
switch (action.type) {
51+
case "delete":
52+
data.splice(data.indexOf(action.item), 1);
53+
return Object.assign({}, state, { data: mut(data) });
54+
case "run":
55+
return { data: mut(buildData(1000)), selected: null };
56+
case "add":
57+
return Object.assign({}, state, { data: mut(state.data.ref.concat(buildData(1000))) });
58+
case "update":
59+
for (let i = 0; i < data.length; i += 10) {
60+
const r = data[i];
61+
data[i] = { id: r.id, label: r.label + " !!!" };
62+
}
63+
return Object.assign({}, state);
64+
case "select":
65+
return Object.assign({}, state, { selected: action.item });
66+
case "runlots":
67+
return { data: mut(buildData(10000)), selected: null };
68+
case "clear":
69+
return { data: mut([]), selected: null };
70+
case "swaprows":
71+
if (data.length > 10) {
72+
const a = data[4];
73+
data[4] = data[9];
74+
data[9] = a;
75+
}
76+
return Object.assign({}, state, { data: mut(data) });
77+
}
78+
return state;
79+
},
80+
function () {
81+
update();
82+
stopMeasure();
83+
}
84+
);
85+
86+
class Row extends Component {
87+
constructor(props) {
88+
super(props);
89+
this.click = Events.onClick(this.click.bind(this));
90+
this.del = Events.onClick(this.del.bind(this));
91+
}
92+
93+
click() {
94+
startMeasure("select");
95+
store.dispatch({ type: "select", item: this.props.item });
96+
}
97+
98+
del() {
99+
startMeasure("delete");
100+
store.dispatch({ type: "delete", item: this.props.item });
101+
}
102+
103+
render() {
104+
const { selected, item } = this.props;
105+
return $h("tr", selected ? "danger" : null)
106+
.children([
107+
$h("td", "col-md-1").children(item.id),
108+
$h("td", "col-md-4").children(
109+
$h("a").events(this.click).children(item.label)
110+
),
111+
$h("td", "col-md-1").children(
112+
$h("a").events(this.del).children(
113+
$h("span", "glyphicon glyphicon-remove").props({ "aria-hidden": "true" })
114+
)
115+
),
116+
$h("td", "col-md-6")
117+
]);
118+
}
119+
}
120+
121+
const $Row = connect(
122+
function (prev, id) {
123+
const item = store.getState().data.ref[id];
124+
const selected = store.getState().selected === item;
125+
if (prev && prev.in.item === item && prev.in.selected === selected) {
126+
return prev;
127+
}
128+
return selectorData({ item, selected });
129+
},
130+
Row
131+
);
132+
133+
function RowList(rows) {
134+
const children = new Array(rows.length);
135+
for (let i = 0; i < children.length; i++) {
136+
children[i] = $Row(i).key(rows[i].id);
137+
}
138+
return $h("tbody").children(children);
139+
}
140+
141+
const $RowList = connect(
142+
function (prev) {
143+
const rows = store.getState().data;
144+
if (prev && prev.in === rows) {
145+
return prev;
146+
}
147+
return selectorData(rows, rows.ref);
148+
},
149+
RowList
150+
);
151+
152+
function $Button(text, id) {
153+
return $h("div", "col-sm-6 smallpad").children(
154+
$h("button", "btn btn-primary btn-block")
155+
.events(Events.onClick(() => {
156+
startMeasure(id);
157+
store.dispatch({ type: id });
158+
}))
159+
.props({ "type": "button", "id": id })
160+
.children(text)
161+
);
162+
}
163+
164+
function Controller() {
165+
return $h("div", "container")
166+
.children([
167+
$h("div", "jumbotron").children(
168+
$h("div", "row").children([
169+
$h("div", "col-md-6").children(
170+
$h("h1").children("ivi v0.5.0")
171+
),
172+
$h("div", "col-md-6").children(
173+
$h("div", "row").children([
174+
$Button("Create 1,000 rows", "run"),
175+
$Button("Create 10,000 rows", "runlots"),
176+
$Button("Append 1,000 rows", "add"),
177+
$Button("Update every 10th row", "update"),
178+
$Button("Clear", "clear"),
179+
$Button("Swap Rows", "swaprows")
180+
])
181+
)
182+
])
183+
),
184+
$h("table", "table table-hover table-striped test-data").children($RowList()),
185+
$h("span", "preloadicon glyphicon glyphicon-remove").props({ "aria-hidden": "true" })
186+
]);
187+
}
188+
189+
render($c(Controller), document.getElementById("main"));

webdriver-ts/src/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export let frameworks = [
5050
f("hyperapp-v0.6.0", true),
5151
f("inferno-v1.3.0-rc3-non-keyed", true),
5252
f("inferno-v1.3.0-rc3-keyed", false),
53+
f("ivi-v0.5.0", false),
5354
f("kivi-v1.0.0-rc2", false),
5455
f("knockout-v3.4.1", false),
5556
f("marionette-v3.1.0", false),

webdriver-ts/table.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)