Skip to content

Commit dafa0cc

Browse files
committed
Merge branch 'master' of https://github.com/adamhaile/js-framework-benchmark into adamhaile-master
2 parents cd35593 + 63f2cb0 commit dafa0cc

File tree

5 files changed

+31
-25
lines changed

5 files changed

+31
-25
lines changed

surplus-v0.4.0/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
},
2424
"dependencies": {
2525
"s-js": "^0.4.0",
26-
"s-array": "^0.4.0",
26+
"s-array": "^0.4.2",
2727
"surplus": "^0.4.0"
2828
},
2929
"devDependencies": {
3030
"ts-loader": "0.8.2",
3131
"typescript": "2.2.1",
32-
"surplus-loader": "^0.4.0",
32+
"surplus-loader": "^0.4.2",
3333
"webpack": "2.2.1"
3434
}
3535
}

surplus-v0.4.0/src/controller.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ var stopMeasure = function() {
2020

2121
export class App {
2222
constructor(public store : Store) { }
23-
run() {
23+
run(clear : boolean) {
2424
startMeasure("run");
25-
this.store.run();
25+
this.store.run(clear);
2626
stopMeasure();
2727
}
2828
add() {
@@ -45,9 +45,9 @@ export class App {
4545
this.store.delete(idx);
4646
stopMeasure();
4747
}
48-
runLots() {
48+
runLots(clear : boolean) {
4949
startMeasure("runLots");
50-
this.store.runLots();
50+
this.store.runLots(clear);
5151
stopMeasure();
5252
}
5353
clear() {

surplus-v0.4.0/src/store.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export class Store {
3838
const idx = (this.data() as any).findIndex((d : Row) => d.id == id);
3939
this.data.splice(idx, 1);
4040
}
41-
run() {
41+
run(clear : boolean) {
42+
if (clear) this.data([]);
4243
S.freeze(() => {
4344
this.data(this.buildData());
4445
this.selected(undefined);
@@ -53,7 +54,8 @@ export class Store {
5354
select(id : number) {
5455
this.selected(id);
5556
}
56-
runLots() {
57+
runLots(clear : boolean) {
58+
if (clear) this.data([]);
5759
S.freeze(() => {
5860
this.data(this.buildData(10000));
5961
this.selected(undefined);

surplus-v0.4.0/src/view.tsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ export let AppView = (app : App) =>
1818
<div className="col-md-6">
1919
<div className="row">
2020
<div className="col-sm-6 smallpad">
21-
<button type="button" className="btn btn-primary btn-block" id="run" onClick={e => app.run()}>Create 1,000 rows</button>
21+
<button type="button" className="btn btn-primary btn-block" id="run" onClick={e => app.run(!USE_NON_KEYED_TBODY)}>Create 1,000 rows</button>
2222
</div>
2323
<div className="col-sm-6 smallpad">
24-
<button type="button" className="btn btn-primary btn-block" id="runlots" onClick={e => app.runLots()}>Create 10,000 rows</button>
24+
<button type="button" className="btn btn-primary btn-block" id="runlots" onClick={e => app.runLots(!USE_NON_KEYED_TBODY)}>Create 10,000 rows</button>
2525
</div>
2626
<div className="col-sm-6 smallpad">
2727
<button type="button" className="btn btn-primary btn-block" id="add" onClick={e => app.add()}>Append 1,000 rows</button>
@@ -49,19 +49,24 @@ export let AppView = (app : App) =>
4949
while (el.tagName !== 'TR') el = el.parentElement!;
5050
return +el.childNodes[0].textContent!;
5151
},
52-
TBodyKeyed = (app : App) =>
53-
<tbody>
54-
{app.store.data.mapSample(row =>
55-
<tr className={row.id === app.store.selected() ? 'danger' : ''}>
56-
<td className="col-md-1" innerText={row.id}></td>
57-
<td className="col-md-4">
58-
<a innerText={row.label()}></a>
59-
</td>
60-
<td className="col-md-1"><a><span className="glyphicon glyphicon-remove delete"></span></a></td>
61-
<td className="col-md-6"></td>
62-
</tr>
63-
)}
64-
</tbody>,
52+
TBodyKeyed = (app : App) => {
53+
let trs = app.store.data.mapSample(row =>
54+
<tr>
55+
<td className="col-md-1" innerText={row.id}></td>
56+
<td className="col-md-4">
57+
<a innerText={row.label()}></a>
58+
</td>
59+
<td className="col-md-1"><a><span className="glyphicon glyphicon-remove delete"></span></a></td>
60+
<td className="col-md-6"></td>
61+
</tr>);
62+
63+
S.on(app.store.selected, () => {
64+
let sel = app.store.selected(), data = app.store.data();
65+
trs().forEach((tr, i) => tr.className = data[i].id === sel ? 'danger' : '');
66+
});
67+
68+
return <tbody>{trs}</tbody>;
69+
},
6570
TBodyNonKeyed = (app : App) => {
6671
var tbody = <tbody></tbody>,
6772
trs = [] as RowTr[];

surplus-v0.4.0/webpack.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ module.exports = {
1212
rules: [
1313
{ test: /\.tsx?$/, loader: 'surplus-loader!ts-loader' },
1414
]
15-
},
16-
externals: [ { '@types/react' : 'this'} ]
15+
}
1716
};

0 commit comments

Comments
 (0)