Skip to content

Commit acf3b77

Browse files
committed
Merge branch 'kalcifer-choo-v4.1.0'
2 parents 1c005bb + da11e69 commit acf3b77

File tree

7 files changed

+276
-1
lines changed

7 files changed

+276
-1
lines changed

choo-v4.1.0/index.html

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

choo-v4.1.0/package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "choo-v4.1.0",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "src/index.js",
6+
"scripts": {
7+
"build": "browserify src/index.js > dist/index.js",
8+
"build-prod": "rimraf dist && mkdirp dist && cross-env NODE_ENV=production browserify src/index.js -t envify -g yo-yoify -g unassertify -g es2020 -g uglifyify | uglifyjs > dist/index.js"
9+
},
10+
"keywords": [
11+
"choo"
12+
],
13+
"author": "Rahul Chanila",
14+
"license": "MIT",
15+
"dependencies": {
16+
"browserify": "^14.1.0",
17+
"choo": "^4.1.0",
18+
"cross-env": "^3.1.4",
19+
"envify": "^4.0.0",
20+
"es2020": "^1.1.9",
21+
"mkdirp": "^0.5.1",
22+
"rimraf": "^2.6.0",
23+
"uglify-js": "^2.7.5",
24+
"uglifyify": "^3.0.4",
25+
"unassertify": "^2.0.4",
26+
"yo-yoify": "^3.5.0"
27+
}
28+
}

choo-v4.1.0/src/index.js

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
const store = require('./store');
2+
const rowsView = require('./rowsView');
3+
const choo = require('choo');
4+
const html = require('choo/html');
5+
const app = choo();
6+
7+
app.model(store);
8+
9+
let startTime;
10+
let lastMeasure;
11+
function startMeasure(name) {
12+
startTime = performance.now();
13+
lastMeasure = name;
14+
};
15+
16+
function stopMeasure() {
17+
const last = lastMeasure;
18+
if (lastMeasure) {
19+
window.setTimeout(function metaStopMeasure() {
20+
lastMeasure = null;
21+
const stop = performance.now();
22+
const duration = 0;
23+
console.log(last+" took "+(stop-startTime));
24+
}, 0);
25+
}
26+
};
27+
28+
function view (state, prev, send) {
29+
function run() {
30+
startMeasure('run');
31+
send('run');
32+
}
33+
34+
function runLots() {
35+
startMeasure('runLots');
36+
send('runLots');
37+
}
38+
39+
function add() {
40+
startMeasure('add');
41+
send('add');
42+
}
43+
44+
function update() {
45+
startMeasure('update');
46+
send('update');
47+
}
48+
49+
function clear() {
50+
startMeasure('clear');
51+
send('clear');
52+
}
53+
54+
function swapRows() {
55+
startMeasure('swapRows');
56+
send('swapRows');
57+
}
58+
59+
function printDuration() {
60+
stopMeasure();
61+
}
62+
63+
printDuration();
64+
65+
return html`<div class="container">
66+
<div class="jumbotron">
67+
<div class="row">
68+
<div class="col-md-6">
69+
<h1>Choo v4.1.0</h1>
70+
</div>
71+
<div class="col-md-6">
72+
<div class="row">
73+
<div class="col-sm-6 smallpad">
74+
<button type="button" class="btn btn-primary btn-block" id="run" onclick=${run}>Create 1,000 rows</button>
75+
</div>
76+
<div class="col-sm-6 smallpad">
77+
<button type="button" class="btn btn-primary btn-block" id="runlots" onclick=${runLots}>Create 10,000 rows</button>
78+
</div>
79+
<div class="col-sm-6 smallpad">
80+
<button type="button" class="btn btn-primary btn-block" id="add" onclick=${add}>Append 1,000 rows</button>
81+
</div>
82+
<div class="col-sm-6 smallpad">
83+
<button type="button" class="btn btn-primary btn-block" id="update" onclick=${update}>Update every 10th row</button>
84+
</div>
85+
<div class="col-sm-6 smallpad">
86+
<button type="button" class="btn btn-primary btn-block" id="clear" onclick=${clear}>Clear</button>
87+
</div>
88+
<div class="col-sm-6 smallpad">
89+
<button type="button" class="btn btn-primary btn-block" id="swaprows" onclick=${swapRows}>Swap Rows</button>
90+
</div>
91+
</div>
92+
</div>
93+
</div>
94+
</div>
95+
<table class="table table-hover table-striped test-data">
96+
<tbody>
97+
${rowsView(state, prev, send)}
98+
</tbody>
99+
</table>
100+
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span>
101+
</div>`;
102+
};
103+
104+
app.router([
105+
['/', view],
106+
[':chooversion/', view],
107+
[':chooversion/index.html', view]
108+
]);
109+
110+
const tree = app.start();
111+
document.querySelector('#main').appendChild(tree);

choo-v4.1.0/src/rowsView.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const html = require('choo/html');
2+
3+
module.exports = function rowsView (state, prev, send) {
4+
const data = state.data;
5+
const selected = state.selected;
6+
function del(id) {
7+
return function(e) {
8+
send('delete', { id: id });
9+
};
10+
}
11+
12+
function click(id) {
13+
return function (e) {
14+
send('select', { id: id });
15+
};
16+
}
17+
18+
function className(id) {
19+
return id === selected ? 'danger' : '';
20+
}
21+
22+
return data.map((d, i) => {
23+
const id = d.id;
24+
const label = d.label;
25+
return html`
26+
<tr class=${className(id)}>
27+
<td class="col-md-1">${id}</td>
28+
<td class="col-md-4">
29+
<a onclick=${click(id)}>${label}</a>
30+
</td>
31+
<td class="col-md-1">
32+
<a onclick=${del(id)}>
33+
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
34+
</a>
35+
</td>
36+
<td class="col-md-6"></td>
37+
</tr>
38+
`;
39+
});
40+
};

choo-v4.1.0/src/store.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
let id = 1;
2+
3+
function _random(max) {
4+
return Math.round(Math.random()*1000)%max;
5+
}
6+
7+
function buildData(count) {
8+
count = count || 1000;
9+
const adjectives = ["pretty", "large", "big", "small", "tall", "short", "long", "handsome", "plain", "quaint", "clean", "elegant", "easy", "angry", "crazy", "helpful", "mushy", "odd", "unsightly", "adorable", "important", "inexpensive", "cheap", "expensive", "fancy"];
10+
const colours = ["red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black", "orange"];
11+
const nouns = ["table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger", "pizza", "mouse", "keyboard"];
12+
13+
return new Array(count).fill('').map(() => {
14+
return {
15+
id: id++,
16+
label: `${adjectives[_random(adjectives.length)]} ${colours[_random(colours.length)]} ${nouns[_random(nouns.length)]}`
17+
};
18+
});
19+
}
20+
21+
module.exports = {
22+
state: {
23+
data: [],
24+
selected: false
25+
},
26+
reducers: {
27+
run: function(state) {
28+
return { data: buildData(1000), selected: undefined };
29+
},
30+
add: function(state) {
31+
return {
32+
data: state.data.slice().concat(buildData(1000)),
33+
selected: undefined
34+
};
35+
},
36+
runLots: function(state) {
37+
return { data: buildData(10000), selected: undefined };
38+
},
39+
clear: function(state) {
40+
return { data: [], selected: undefined };
41+
},
42+
update: function(state) {
43+
return {
44+
data: state.data.slice()
45+
.map((d, i) => {
46+
if(i % 10 === 0) {
47+
d.label = `${d.label} !!!`;
48+
}
49+
return d;
50+
}),
51+
selected: undefined
52+
};
53+
},
54+
swapRows: function(state) {
55+
if(state.data.length > 10) {
56+
const newData = state.data.slice();
57+
const a = newData[4];
58+
newData[4] = newData[9];
59+
newData[9] = a;
60+
61+
return {
62+
data: newData,
63+
selected: state.selected
64+
};
65+
} else {
66+
return state;
67+
}
68+
},
69+
select: function(state, data) {
70+
return {
71+
data: state.data,
72+
selected: data.id
73+
};
74+
},
75+
delete: function(state, data) {
76+
return {
77+
data: state.data.filter((d) => d.id !== data.id),
78+
selected: data.id
79+
};
80+
}
81+
}
82+
};

webdriver-ts/src/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ export let frameworks = [
8080
f("vidom-v0.7.1", false),
8181
f("vue-v2.1.10-keyed", false),
8282
f("vue-v2.1.10-non-keyed", true),
83+
f("choo-v4.1.0", true)
8384
]

webdriver-ts/table.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)