Skip to content

Commit 516bf14

Browse files
committed
Merge branch 'kobold-09' of https://github.com/maciejhirsz/js-framework-benchmark into maciejhirsz-kobold-09
2 parents a5af288 + 9030479 commit 516bf14

File tree

10 files changed

+72
-61
lines changed

10 files changed

+72
-61
lines changed

frameworks/non-keyed/kobold/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77
crate-type = ["cdylib"]
88

99
[dependencies]
10-
kobold = "0.7.1"
10+
kobold = "0.9.1"
1111
wasm-bindgen = "0.2.84"
1212
js-sys = "0.3.61"
1313

@@ -18,4 +18,4 @@ codegen-units = 1
1818
panic = "abort"
1919

2020
[package.metadata.wasm-pack.profile.release]
21-
wasm-opt = ['-O4']
21+
wasm-opt = ['-O4']

frameworks/non-keyed/kobold/bundled-dist/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span>
1313
<div id='main'></div>
1414
<script type="module">
15-
import init from './js-framework-benchmark-kobold.js';
15+
import init, { koboldCallback } from './js-framework-benchmark-kobold.js';
1616
init('./js-framework-benchmark-kobold_bg.wasm');
17+
window.koboldCallback = koboldCallback;
1718
</script>
1819
</body>
1920
</html>

frameworks/non-keyed/kobold/bundled-dist/js-framework-benchmark-kobold.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

frameworks/non-keyed/kobold/bundled-dist/snippets/kobold-1aefc3738a915e71/js/util.js

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const fragmentDecorators = new WeakMap();
2+
3+
export function appendChild(n,c) { n.appendChild(c); }
4+
export function appendBefore(n,i) { n.before(i); }
5+
export function removeNode(n) { n.remove(); }
6+
export function replaceNode(o,n) { o.replaceWith(n); }
7+
export function emptyNode() { return document.createTextNode(""); }
8+
export function fragment()
9+
{
10+
let f = document.createDocumentFragment();
11+
f.append("", "");
12+
return f;
13+
};
14+
export function fragmentDecorate(f) {
15+
fragmentDecorators.set(f, [f.firstChild, f.lastChild]);
16+
return f.lastChild;
17+
}
18+
export function fragmentUnmount(f)
19+
{
20+
let [b, e] = fragmentDecorators.get(f);
21+
while (b.nextSibling !== e) f.appendChild(b.nextSibling);
22+
f.appendChild(e);
23+
f.insertBefore(b, f.firstChild);
24+
}
25+
export function fragmentReplace(f,n)
26+
{
27+
let [b, e] = fragmentDecorators.get(f);
28+
while (b.nextSibling !== e) f.appendChild(b.nextSibling);
29+
b.replaceWith(n);
30+
f.appendChild(e);
31+
f.insertBefore(b, f.firstChild);
32+
}
33+
export function setTextContent(n,t) { n.textContent = t; }
34+
export function setAttribute(n,a,v) { n.setAttribute(a, v); }
35+
36+
export function setChecked(n,v) { if (n.checked !== v) n.checked = v; }
37+
export function setClassName(n,v) { n.className = v; }
38+
export function setHref(n,v) { n.href = v; }
39+
export function setStyle(n,v) { n.style = v; }
40+
export function setValue(n,v) { n.value = v; }
41+
42+
export function addClass(n,v) { n.classList.add(v); }
43+
export function removeClass(n,v) { n.classList.remove(v); }
44+
export function replaceClass(n,o,v) { n.classList.replace(o,v); }
45+
export function toggleClass(n,c,v) { n.classList.toggle(c,v); }
46+
47+
export function makeEventHandler(c,f) { return (e) => koboldCallback(e,c,f); }
48+
export function checkEventHandler() { if (typeof koboldCallback !== "function") console.error(
49+
`Missing \`koboldCallback\` in global scope.
50+
Add the following to your Trunk.toml:
51+
52+
[build]
53+
pattern_script = "<script type=\\"module\\">import init, { koboldCallback } from '{base}{js}';init('{base}{wasm}');window.koboldCallback = koboldCallback;</script>"
54+
`) }

frameworks/non-keyed/kobold/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span>
1313
<div id='main'></div>
1414
<script type="module">
15-
import init from './js-framework-benchmark-kobold.js';
15+
import init, { koboldCallback } from './js-framework-benchmark-kobold.js';
1616
init('./js-framework-benchmark-kobold_bg.wasm');
17+
window.koboldCallback = koboldCallback;
1718
</script>
1819
</body>
1920
</html>

frameworks/non-keyed/kobold/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frameworks/non-keyed/kobold/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Benchmark for Kobold",
55
"license": "MPL-2.0",
66
"js-framework-benchmark": {
7-
"frameworkVersion": "0.7.1",
7+
"frameworkVersion": "0.9.1",
88
"frameworkHomeURL": "https://github.com/maciejhirsz/kobold",
99
"issues": [
1010
1139
@@ -30,4 +30,4 @@
3030
"esbuild": "^0.14.47",
3131
"npm-run-all": "4.1.5"
3232
}
33-
}
33+
}

frameworks/non-keyed/kobold/src/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use js_sys::Math;
2+
use kobold::diff::VString;
23
use kobold::prelude::*;
34
use wasm_bindgen::prelude::*;
45

@@ -47,10 +48,10 @@ fn random(max: usize) -> usize {
4748
(Math::random() * 1000.0) as usize % max
4849
}
4950

50-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
51+
#[derive(Debug)]
5152
struct RowData {
5253
id: usize,
53-
label: String,
54+
label: VString,
5455
}
5556

5657
struct State {
@@ -83,7 +84,7 @@ impl State {
8384
label.push_str(noun);
8485
self.rows.push(RowData {
8586
id: i + d,
86-
label,
87+
label: label.into(),
8788
});
8889
}
8990
self.last += count;
@@ -137,7 +138,7 @@ fn Row<'a>(num: usize, row: &'a RowData, state: &'a Hook<State>) -> impl View +
137138
view! {
138139
<tr.{is_in_danger}>
139140
<td class="col-md-1">{id}</td>
140-
<td class="col-md-4"><a onclick={select}>{row.label.to_owned()}</a></td>
141+
<td class="col-md-4"><a onclick={select}>{&row.label}</a></td>
141142
<td class="col-md-1"><a onclick={remove}><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td>
142143
<td class="col-md-6"/>
143144
</tr>
@@ -211,7 +212,7 @@ fn App() -> impl View {
211212
</div>
212213
<table class="table table-hover table-striped test-data">
213214
<tbody>
214-
{ for state.rows.iter().enumerate().map(|(num,row)| view! { <Row {state} {num} {row} /> }) }
215+
{ for state.rows.iter().enumerate().map(|(num,row)| view! { <Row {state} {num} {row} /> }) }
215216
</tbody>
216217
</table>
217218
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true" />
@@ -225,4 +226,4 @@ pub fn start() {
225226
kobold::start(view! {
226227
<App />
227228
});
228-
}
229+
}

0 commit comments

Comments
 (0)