Skip to content

Commit 2ca01fc

Browse files
committed
Merge branch 'destam-dom' of https://github.com/Nefsen402/js-framework-benchmark into Nefsen402-destam-dom
2 parents e7c7a6d + 594dc64 commit 2ca01fc

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

frameworks/keyed/destam-dom/package-lock.json

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

frameworks/keyed/destam-dom/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"scripts": {
1111
"dev": "rollup -c -w",
12+
"build": "rollup -c",
1213
"build-prod": "rollup -c --environment production"
1314
},
1415
"author": "Alexander Orzechowski",
@@ -20,7 +21,7 @@
2021
},
2122
"dependencies": {
2223
"destam": "^0.1.0",
23-
"destam-dom": "^0.4.0"
24+
"destam-dom": "^0.6.0"
2425
},
2526
"devDependencies": {
2627
"@babel/parser": "^7.24.1",

frameworks/keyed/destam-dom/rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const createTransform = (name, transform, jsx) => ({
1010
transform(code, id) {
1111
if (id.endsWith('.js') || (jsx && id.endsWith('.jsx'))) {
1212
const transformed = transform(code, {
13+
util_import: 'destam-dom',
1314
sourceFileName: id,
1415
plugins: id.endsWith('.jsx') ? ['jsx'] : [],
1516
});

frameworks/keyed/destam-dom/src/main.jsx

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,31 @@ const App = () => {
4242
clear = () => {
4343
array.splice(0, array.length);
4444
},
45-
remove = row => {
46-
const idx = array.indexOf(row);
45+
remove = idx => {
4746
array.splice(idx, 1);
47+
},
48+
select = idx => {
49+
selected.set(array[idx]);
4850
};
4951

5052
function appendData(count) {
51-
array.push(...Array.from(Array(count), () => {
53+
const arr = Array(count);
54+
for (let i = 0; i < count; i++) {
5255
let label = Observer.mutable(`${adjectives[_random(adjectives.length)]} ${colours[_random(colours.length)]} ${nouns[_random(nouns.length)]}`);
5356

5457
const dom =
5558
<tr class={selected.map(sel => sel === dom ? "danger": "")}>
5659
<td class='col-md-1' $textContent={ idCounter++ } />
57-
<td class='col-md-4'><a $onclick={() => selected.set(dom)} $textContent={ label } /></td>
58-
<td class='col-md-1'><a $onclick={() => remove(dom)}><span class='glyphicon glyphicon-remove' aria-hidden="true" /></a></td>
60+
<td class='col-md-4'><a $clickHandler={1} $textContent={ label } /></td>
61+
<td class='col-md-1'><a $clickHandler={2}><span class='glyphicon glyphicon-remove' aria-hidden="true" /></a></td>
5962
<td class='col-md-6'/>
6063
</tr>;
6164

6265
dom.label = label;
63-
return dom;
64-
}));
66+
arr[i] = dom;
67+
}
68+
69+
array.push(...arr);
6570
}
6671

6772
return <div class='container'>
@@ -76,7 +81,19 @@ const App = () => {
7681
<Button id='swaprows' text='Swap Rows' fn={ swapRows } />
7782
</div></div>
7883
</div></div>
79-
<table class='table table-hover table-striped test-data'><tbody>
84+
<table class='table table-hover table-striped test-data'><tbody $onclick={ev => {
85+
let handler;
86+
let e = ev.target;
87+
while (e.parentElement.tagName !== "TBODY") {
88+
if (e.clickHandler) handler = e.clickHandler;
89+
e = e.parentElement;
90+
}
91+
92+
if (!handler) return;
93+
94+
let i = Array.prototype.indexOf.call(e.parentElement.children, e);
95+
[null, select, remove][handler](i);
96+
}}>
8097
{array}
8198
</tbody></table>
8299
<span class='preloadicon glyphicon glyphicon-remove' aria-hidden="true" />

0 commit comments

Comments
 (0)