Skip to content

Commit b4531d5

Browse files
committed
destam-dom: Use selector
This optimizes O(n) to O(1) for select row
1 parent 0a41fe4 commit b4531d5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const App = () => {
1717
const
1818
array = OArray(),
1919
selected = Observer.mutable(null),
20+
selector = selected.selector('danger', null),
2021
run = () => {
2122
array.splice(0, array.length);
2223
appendData(1000);
@@ -46,7 +47,7 @@ const App = () => {
4647
array.splice(idx, 1);
4748
},
4849
select = idx => {
49-
selected.set(array[idx]);
50+
selected.set(array[idx].label);
5051
};
5152

5253
function appendData(count) {
@@ -55,7 +56,7 @@ const App = () => {
5556
let label = Observer.mutable(`${adjectives[_random(adjectives.length)]} ${colours[_random(colours.length)]} ${nouns[_random(nouns.length)]}`);
5657

5758
const dom =
58-
<tr class={selected.map(sel => sel === dom ? "danger": "")}>
59+
<tr class={selector(label)}>
5960
<td class='col-md-1' $textContent={ idCounter++ } />
6061
<td class='col-md-4'><a $clickHandler={select} $textContent={ label } /></td>
6162
<td class='col-md-1'><a $clickHandler={remove}><span class='glyphicon glyphicon-remove' aria-hidden="true" /></a></td>

0 commit comments

Comments
 (0)