Skip to content

Commit e615b74

Browse files
committed
Merge branch 'yysun-master'
2 parents 0e0321a + eeef08e commit e615b74

File tree

8 files changed

+62
-74
lines changed

8 files changed

+62
-74
lines changed

frameworks/keyed/apprun/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "js-framework-benchmark-apprun-v1.7.0",
2+
"name": "js-framework-benchmark-apprun-v2.23.10",
33
"version": "1.0.0",
44
"description": "AppRun demo",
55
"main": "index.js",
@@ -23,12 +23,12 @@
2323
},
2424
"devDependencies": {
2525
"json-loader": "0.5.7",
26-
"ts-loader": "6.0.2",
27-
"typescript": "3.5.2",
28-
"webpack": "4.34.0",
29-
"webpack-cli": "^3.1.0"
26+
"ts-loader": "6.2.2",
27+
"typescript": "3.8.3",
28+
"webpack": "4.42.1",
29+
"webpack-cli": "^3.3.11"
3030
},
3131
"dependencies": {
32-
"apprun": "1.20.6"
32+
"apprun": "2.23.12"
3333
}
3434
}

frameworks/keyed/apprun/src/main.tsx

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import app, { Component } from 'apprun'
1+
import { app, Component } from 'apprun';
22
import Store from './store';
33

44
const store = new Store();
55

66
const update = {
7-
'#benchmark': (store) => store,
87

98
run(store) {
109
store.run();
@@ -17,20 +16,16 @@ const update = {
1716
},
1817

1918
remove(store, id) {
20-
document.getElementById(id).remove();
2119
store.delete(id);
22-
store.no_render = true;
23-
return store;
20+
document.getElementById(id).remove();
2421
},
2522

2623
select(store, id) {
2724
if (store.selected) {
2825
document.getElementById(store.selected).className = '';
2926
}
30-
document.getElementById(id).className = 'danger';
3127
store.select(id);
32-
store.no_render = true;
33-
return store;
28+
document.getElementById(id).className = 'danger';
3429
},
3530

3631
update(store) {
@@ -45,7 +40,7 @@ const update = {
4540

4641
clear(store) {
4742
store.clear();
48-
return store;
43+
document.getElementById("main-table").innerHTML = "";
4944
},
5045

5146
swaprows(store) {
@@ -55,12 +50,8 @@ const update = {
5550
}
5651

5752
const view = (model) => {
58-
if (model.no_render) {
59-
delete model.no_render;
60-
return;
61-
}
6253
const rows = model.data.map((curr) => {
63-
const selected = curr.id == model.selected ? 'danger' : '';
54+
const selected = curr.id == model.selected ? 'danger' : undefined;
6455
const id = curr.id;
6556
return <tr className={selected} id={id} key={id}>
6657
<td className="col-md-1">{id}</td>
@@ -76,7 +67,7 @@ const view = (model) => {
7667
</tr>;
7768
});
7869

79-
return (<div className="container">
70+
return (<div className="container" onclick={click}>
8071
<div className="jumbotron">
8172
<div className="row">
8273
<div className="col-md-6">
@@ -106,7 +97,7 @@ const view = (model) => {
10697
</div>
10798
</div>
10899
</div>
109-
<table className="table table-hover table-striped test-data">
100+
<table className="table table-hover table-striped test-data" id="main-table">
110101
<tbody>
111102
{rows}
112103
</tbody>
@@ -125,7 +116,7 @@ const getId = (elem) => {
125116
return undefined;
126117
}
127118

128-
document.body.addEventListener('click', e => {
119+
const click = (e) => {
129120
const t = e.target as HTMLElement;
130121
if (!t) return;
131122
if (t.tagName === 'BUTTON' && t.id) {
@@ -138,10 +129,11 @@ document.body.addEventListener('click', e => {
138129
e.preventDefault();
139130
component.run('select', getId(t));
140131
}
141-
});
132+
};
142133

143-
app.on('//', _ => { })
144-
app.on('#', _ => { })
145-
146-
let component = new Component(store, view, update);
134+
const component = new Component(store, view, update);
135+
component['-patch-vdom-on'] = true;
136+
component.rendered = () => {
137+
store.selected && (document.getElementById(store.selected).className = 'danger');
138+
}
147139
component.start(document.getElementById('main'));

frameworks/keyed/apprun/src/store.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ export default class Store {
2020
}
2121
updateData(mod = 10) {
2222
for (let i=0;i<this.data.length;i+=10) {
23-
// this.data[i].label += ' !!!';
24-
this.data[i] = { ...this.data[i], label: this.data[i].label + ' !!!' };
23+
this.data[i].label += ' !!!';
24+
// this.data[i] = Object.assign({}, this.data[i], {label: this.data[i].label +' !!!'});
2525
}
2626
}
2727
delete(id) {
2828
// const idx = this.data.findIndex(d => d.id==id);
29-
this.data = this.data.filter((e,i) => e.id!=id);
30-
if (this.selected === id) this.selected = null;
29+
this.data = this.data.filter((e, i) => e.id != id);
30+
if (id === this.selected) this.selected = null;
3131
}
3232
run() {
3333
this.data = this.buildData();
@@ -39,7 +39,6 @@ export default class Store {
3939
}
4040
update() {
4141
this.updateData();
42-
this.selected = null;
4342
}
4443
select(id) {
4544
this.selected = id;
@@ -63,10 +62,11 @@ export default class Store {
6362
this.selected = null;
6463
}
6564
swapRows() {
66-
if (this.data.length > 998) {
65+
if (this.data.length > 4) {
66+
var idx = this.data.length - 2;
6767
var a = this.data[1];
68-
this.data[1] = this.data[998];
69-
this.data[998] = a;
68+
this.data[1] = this.data[idx];
69+
this.data[idx] = a;
7070
}
7171
}
7272
}

frameworks/keyed/apprun/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
3+
"target": "es2015",
4+
"module": "es2015",
5+
"moduleResolution": "node",
46
"jsx": "react",
57
"reactNamespace": "app",
68
"lib": ["dom", "es2015.promise", "es5"]

frameworks/non-keyed/apprun/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "js-framework-benchmark-apprun-v1.7.0",
2+
"name": "js-framework-benchmark-apprun-v2.23.10",
33
"version": "1.0.0",
44
"description": "AppRun demo",
55
"main": "index.js",
@@ -23,12 +23,12 @@
2323
},
2424
"devDependencies": {
2525
"json-loader": "0.5.7",
26-
"ts-loader": "6.0.2",
27-
"typescript": "3.5.2",
28-
"webpack": "4.34.0",
29-
"webpack-cli": "3.3.4"
26+
"ts-loader": "6.2.2",
27+
"typescript": "3.8.3",
28+
"webpack": "4.42.1",
29+
"webpack-cli": "^3.3.11"
3030
},
3131
"dependencies": {
32-
"apprun": "1.20.6"
32+
"apprun": "2.23.12"
3333
}
3434
}

frameworks/non-keyed/apprun/src/main.tsx

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import app, { Component } from 'apprun'
1+
import { app, Component } from 'apprun';
22
import Store from './store';
33

44
const store = new Store();
55

66
const update = {
7-
'#benchmark': (store) => store,
87

98
run(store) {
109
store.run();
@@ -17,20 +16,16 @@ const update = {
1716
},
1817

1918
remove(store, id) {
20-
document.getElementById(id).remove();
2119
store.delete(id);
22-
store.no_render = true;
23-
return store;
20+
document.getElementById(id).remove();
2421
},
2522

2623
select(store, id) {
2724
if (store.selected) {
2825
document.getElementById(store.selected).className = '';
2926
}
30-
document.getElementById(id).className = 'danger';
3127
store.select(id);
32-
store.no_render = true;
33-
return store;
28+
document.getElementById(id).className = 'danger';
3429
},
3530

3631
update(store) {
@@ -45,7 +40,7 @@ const update = {
4540

4641
clear(store) {
4742
store.clear();
48-
return store;
43+
document.getElementById("main-table").innerHTML = "";
4944
},
5045

5146
swaprows(store) {
@@ -55,12 +50,8 @@ const update = {
5550
}
5651

5752
const view = (model) => {
58-
if (model.no_render) {
59-
delete model.no_render;
60-
return;
61-
}
6253
const rows = model.data.map((curr) => {
63-
const selected = curr.id == model.selected ? 'danger' : '';
54+
const selected = curr.id == model.selected ? 'danger' : undefined;
6455
const id = curr.id;
6556
return <tr className={selected} id={id}>
6657
<td className="col-md-1">{id}</td>
@@ -76,7 +67,7 @@ const view = (model) => {
7667
</tr>;
7768
});
7869

79-
return (<div className="container">
70+
return (<div className="container" onclick={click}>
8071
<div className="jumbotron">
8172
<div className="row">
8273
<div className="col-md-6">
@@ -106,7 +97,7 @@ const view = (model) => {
10697
</div>
10798
</div>
10899
</div>
109-
<table className="table table-hover table-striped test-data">
100+
<table className="table table-hover table-striped test-data" id="main-table">
110101
<tbody>
111102
{rows}
112103
</tbody>
@@ -125,7 +116,7 @@ const getId = (elem) => {
125116
return undefined;
126117
}
127118

128-
document.body.addEventListener('click', e => {
119+
const click = (e) => {
129120
const t = e.target as HTMLElement;
130121
if (!t) return;
131122
if (t.tagName === 'BUTTON' && t.id) {
@@ -138,10 +129,11 @@ document.body.addEventListener('click', e => {
138129
e.preventDefault();
139130
component.run('select', getId(t));
140131
}
141-
});
132+
};
142133

143-
app.on('//', _ => { })
144-
app.on('#', _ => { })
145-
146-
let component = new Component(store, view, update);
134+
const component = new Component(store, view, update);
135+
component['-patch-vdom-on'] = true;
136+
component.rendered = () => {
137+
store.selected && (document.getElementById(store.selected).className = 'danger');
138+
}
147139
component.start(document.getElementById('main'));

frameworks/non-keyed/apprun/src/store.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ export default class Store {
2020
}
2121
updateData(mod = 10) {
2222
for (let i=0;i<this.data.length;i+=10) {
23-
// this.data[i].label += ' !!!';
24-
this.data[i] = { ...this.data[i], label: this.data[i].label + ' !!!' };
23+
this.data[i].label += ' !!!';
24+
// this.data[i] = Object.assign({}, this.data[i], {label: this.data[i].label +' !!!'});
2525
}
2626
}
2727
delete(id) {
2828
// const idx = this.data.findIndex(d => d.id==id);
29-
this.data = this.data.filter((e,i) => e.id!=id);
30-
if (this.selected === id) this.selected = null;
29+
this.data = this.data.filter((e, i) => e.id != id);
30+
if (id === this.selected) this.selected = null;
3131
}
3232
run() {
3333
this.data = this.buildData();
@@ -39,7 +39,6 @@ export default class Store {
3939
}
4040
update() {
4141
this.updateData();
42-
this.selected = null;
4342
}
4443
select(id) {
4544
this.selected = id;
@@ -63,10 +62,11 @@ export default class Store {
6362
this.selected = null;
6463
}
6564
swapRows() {
66-
if (this.data.length > 998) {
65+
if (this.data.length > 4) {
66+
var idx = this.data.length - 2;
6767
var a = this.data[1];
68-
this.data[1] = this.data[998];
69-
this.data[998] = a;
68+
this.data[1] = this.data[idx];
69+
this.data[idx] = a;
7070
}
7171
}
7272
}

frameworks/non-keyed/apprun/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
3+
"target": "es2015",
4+
"module": "es2015",
5+
"moduleResolution": "node",
46
"jsx": "react",
57
"reactNamespace": "app",
68
"lib": ["dom", "es2015.promise", "es5"]

0 commit comments

Comments
 (0)