Skip to content

Commit d89802e

Browse files
committed
Merge remote-tracking branch 'krausest/master' into master
2 parents 73c57bf + f0841b2 commit d89802e

21 files changed

+6472
-1004
lines changed

frameworks/keyed/whatsup/.babelrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/env",
5+
{
6+
"useBuiltIns": "usage",
7+
"corejs": 3,
8+
"targets": { "browsers": ["chrome>80"] }
9+
}
10+
],
11+
"@babel/typescript"
12+
],
13+
"plugins": ["@babel/transform-typescript", "@babel/proposal-class-properties", "@whatsup/transform-jsx"]
14+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"printWidth": 120,
3+
"tabWidth": 4,
4+
"singleQuote": true,
5+
"semi": false
6+
}
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>WhatsUp</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>

frameworks/keyed/whatsup/package-lock.json

Lines changed: 5164 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "js-framework-benchmark-whatsup",
3+
"version": "1.0.0",
4+
"description": "Benchmark for WhatsUp framework",
5+
"author": "Denis Churbanov",
6+
"license": "MIT",
7+
"js-framework-benchmark": {
8+
"frameworkVersionFromPackage": "whatsup"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/krausest/js-framework-benchmark.git"
13+
},
14+
"scripts": {
15+
"build-dev": "webpack -w -d",
16+
"build-prod": "webpack -p"
17+
},
18+
"dependencies": {
19+
"whatsup": "1.1.1",
20+
"@whatsup/jsx": "0.1.4"
21+
},
22+
"devDependencies": {
23+
"@babel/cli": "7.10.4",
24+
"@babel/core": "7.10.4",
25+
"@babel/plugin-proposal-class-properties": "7.12.1",
26+
"@babel/plugin-transform-runtime": "7.10.4",
27+
"@babel/plugin-transform-typescript": "7.10.4",
28+
"@babel/preset-env": "7.10.4",
29+
"@babel/preset-typescript": "7.10.4",
30+
"@whatsup/babel-plugin-transform-jsx": "0.2.2",
31+
"babel-loader": "8.1.0",
32+
"core-js": "3.6.5",
33+
"prettier": "2.0.5",
34+
"typescript": "3.9.6",
35+
"webpack": "4.44.2",
36+
"webpack-cli": "3.3.12"
37+
}
38+
}
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
import { conse, cause, list, Stream, Fractal, Conse, Event, List, Context } from 'whatsup'
2+
import { render } from '@whatsup/jsx'
3+
4+
// prettier-ignore
5+
const A = ['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']
6+
// prettier-ignore
7+
const C = ['red', 'yellow', 'blue', 'green', 'pink', 'brown', 'purple', 'brown', 'white', 'black', 'orange']
8+
// prettier-ignore
9+
const N = ['table', 'chair', 'house', 'bbq', 'desk', 'car', 'pony', 'cookie', 'sandwich', 'burger', 'pizza', 'mouse', 'keyboard']
10+
11+
function rnd(max: number) {
12+
return Math.round(Math.random() * 1000) % max
13+
}
14+
15+
class SelectRowEvent extends Event {
16+
constructor(readonly row: Row) {
17+
super()
18+
}
19+
}
20+
21+
class DeleteRowEvent extends Event {
22+
constructor(readonly row: Row) {
23+
super()
24+
}
25+
}
26+
27+
class SelectedRowId extends Conse<number> {}
28+
29+
class Row extends Fractal<JSX.Element> {
30+
readonly id: number
31+
readonly label: Conse<string>
32+
33+
constructor(id: number, label: string) {
34+
super()
35+
this.id = id
36+
this.label = conse(label)
37+
}
38+
39+
*whatsUp(ctx: Context) {
40+
const { id } = this
41+
const selected = ctx.find(SelectedRowId)!
42+
const className = cause(function* () {
43+
while (true) {
44+
yield (yield* selected) === id ? 'danger' : ''
45+
}
46+
})
47+
const selectClickHandler = () => ctx.dispath(new SelectRowEvent(this))
48+
const deleteClickHandler = () => ctx.dispath(new DeleteRowEvent(this))
49+
50+
while (true) {
51+
yield (
52+
<tr key={id} className={yield* className}>
53+
<td className="col-md-1">{id}</td>
54+
<td className="col-md-4">
55+
<a onClick={selectClickHandler}>{yield* this.label}</a>
56+
</td>
57+
<td className="col-md-1">
58+
<a onClick={deleteClickHandler}>
59+
<span className="glyphicon glyphicon-remove" ariaHidden="true"></span>
60+
</a>
61+
</td>
62+
<td className="col-md-6"></td>
63+
</tr>
64+
)
65+
}
66+
}
67+
}
68+
69+
class Main extends Fractal<JSX.Element> {
70+
readonly rows = list<Row>([])
71+
readonly selected = new SelectedRowId(NaN)
72+
private nextRowId = 1
73+
74+
private buildRows(count = 1000) {
75+
var rows = [] as Row[]
76+
for (var i = 0; i < count; i++) {
77+
const id = this.nextRowId++
78+
const label = A[rnd(A.length)] + ' ' + C[rnd(C.length)] + ' ' + N[rnd(N.length)]
79+
rows.push(new Row(id, label))
80+
}
81+
return rows
82+
}
83+
84+
delete(row: Row) {
85+
this.rows.delete(row)
86+
}
87+
88+
run() {
89+
const rows = this.buildRows()
90+
this.rows.set(rows)
91+
this.selected.set(NaN)
92+
}
93+
94+
add() {
95+
const rows = this.buildRows(1000)
96+
this.rows.insert(...rows)
97+
}
98+
99+
update() {
100+
const rows = this.rows.get()
101+
102+
for (let i = 0; i < rows.length; i += 10) {
103+
const label = rows[i].label.get()
104+
rows[i].label.set(label + ' !!!')
105+
}
106+
}
107+
108+
select(row: Row) {
109+
this.selected.set(row.id)
110+
}
111+
112+
runLots() {
113+
const rows = this.buildRows(10000)
114+
this.rows.set(rows)
115+
this.selected.set(NaN)
116+
}
117+
118+
clear() {
119+
this.rows.set([])
120+
this.selected.set(NaN)
121+
}
122+
123+
swapRows() {
124+
const rows = this.rows.get().slice()
125+
126+
if (rows.length > 998) {
127+
;[rows[1], rows[998]] = [rows[998], rows[1]]
128+
this.rows.set(rows)
129+
}
130+
}
131+
132+
*whatsUp(ctx: Context) {
133+
ctx.share(this.selected)
134+
ctx.on(SelectRowEvent, (e) => this.select(e.row))
135+
ctx.on(DeleteRowEvent, (e) => this.delete(e.row))
136+
137+
const runHandler = () => this.run()
138+
const runLotsHandler = () => this.runLots()
139+
const addHandler = () => this.add()
140+
const updateHandler = () => this.update()
141+
const clearHandler = () => this.clear()
142+
const swapRowsHandler = () => this.swapRows()
143+
144+
while (true) {
145+
yield (
146+
<div className="container">
147+
<div className="jumbotron">
148+
<div className="row">
149+
<div className="col-md-6">
150+
<h1>WhatsUp</h1>
151+
</div>
152+
<div className="col-md-6">
153+
<div className="row">
154+
<div className="col-sm-6 smallpad">
155+
<button
156+
type="button"
157+
className="btn btn-primary btn-block"
158+
id="run"
159+
onClick={runHandler}
160+
>
161+
Create 1,000 rows
162+
</button>
163+
</div>
164+
<div className="col-sm-6 smallpad">
165+
<button
166+
type="button"
167+
className="btn btn-primary btn-block"
168+
id="runlots"
169+
onClick={runLotsHandler}
170+
>
171+
Create 10,000 rows
172+
</button>
173+
</div>
174+
<div className="col-sm-6 smallpad">
175+
<button
176+
type="button"
177+
className="btn btn-primary btn-block"
178+
id="add"
179+
onClick={addHandler}
180+
>
181+
Append 1,000 rows
182+
</button>
183+
</div>
184+
<div className="col-sm-6 smallpad">
185+
<button
186+
type="button"
187+
className="btn btn-primary btn-block"
188+
id="update"
189+
onClick={updateHandler}
190+
>
191+
Update every 10th row
192+
</button>
193+
</div>
194+
<div className="col-sm-6 smallpad">
195+
<button
196+
type="button"
197+
className="btn btn-primary btn-block"
198+
id="clear"
199+
onClick={clearHandler}
200+
>
201+
Clear
202+
</button>
203+
</div>
204+
<div className="col-sm-6 smallpad">
205+
<button
206+
type="button"
207+
className="btn btn-primary btn-block"
208+
id="swaprows"
209+
onClick={swapRowsHandler}
210+
>
211+
Swap Rows
212+
</button>
213+
</div>
214+
</div>
215+
</div>
216+
</div>
217+
</div>
218+
<table className="table table-hover table-striped test-data">
219+
<tbody>{yield* connect(this.rows)}</tbody>
220+
</table>
221+
<span className="preloadicon glyphicon glyphicon-remove" ariaHidden="true" />
222+
</div>
223+
)
224+
}
225+
}
226+
}
227+
228+
function* connect<T>(list: List<Stream<T>>) {
229+
const acc = [] as T[]
230+
231+
for (const item of yield* list) {
232+
acc.push(yield* item)
233+
}
234+
235+
return acc
236+
}
237+
238+
render(new Main(), document.getElementById('main')!)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"module": "esnext",
4+
"target": "esnext",
5+
"moduleResolution": "node",
6+
"importHelpers": true,
7+
"declaration": true,
8+
"sourceMap": true,
9+
"strict": true,
10+
"noUnusedLocals": true,
11+
"noUnusedParameters": true,
12+
"noImplicitReturns": true,
13+
"noFallthroughCasesInSwitch": true,
14+
"allowSyntheticDefaultImports": true,
15+
"lib": ["esnext", "dom"],
16+
"jsx": "preserve",
17+
"rootDir": "./src",
18+
"baseUrl": "./"
19+
}
20+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const path = require('path')
2+
3+
module.exports = {
4+
entry: {
5+
main: './src/main.tsx',
6+
},
7+
output: {
8+
path: path.resolve(__dirname, './dist'),
9+
filename: '[name].js',
10+
sourceMapFilename: '[file].map',
11+
},
12+
resolve: {
13+
modules: [path.resolve(__dirname, './src'), path.resolve(__dirname, 'node_modules')],
14+
extensions: ['.js', '.jsx', '.ts', '.tsx'],
15+
},
16+
resolveLoader: {
17+
modules: [path.resolve(__dirname, 'node_modules')],
18+
},
19+
module: {
20+
rules: [
21+
{
22+
test: /\.tsx?$/,
23+
use: ['babel-loader'],
24+
exclude: /node_modules/,
25+
},
26+
],
27+
},
28+
}

frameworks/non-keyed/seed/.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ node_modules
22
target
33
Cargo.lock
44
bundled-dist/*
5-
!bundled-dist/js-framework-benchmark-seed.js
6-
!bundled-dist/js-framework-benchmark-seed_bg.wasm
5+
!bundled-dist/js-framework-benchmark-non-keyed-seed.js
6+
!bundled-dist/js-framework-benchmark-non-keyed-seed_bg.wasm
77
!bundled-dist/index.html

0 commit comments

Comments
 (0)