Skip to content

Commit b50b96e

Browse files
committed
Simplify selectRow
1 parent 2e956fa commit b50b96e

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

frameworks/non-keyed/bau/main.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ const buildData = (count) => {
6868
};
6969

7070
const dataState = bau.state([]);
71-
const selectedRowState = bau.state();
71+
let selectedRow = null;
7272

7373
const run = () => {
7474
dataState.val = buildData(1000);
75-
selectedRowState.val = null;
75+
selectedRow = null;
7676
};
7777

7878
const runLots = () => {
7979
dataState.val = buildData(10000);
80-
selectedRowState.val = null;
80+
selectedRow = null;
8181
};
8282

8383
const add = () => {
@@ -103,7 +103,7 @@ const swapRows = () => {
103103

104104
const clear = () => {
105105
dataState.val = [];
106-
selectedRowState.val = null;
106+
selectedRow = null;
107107
};
108108

109109
const remove = (id) => () => {
@@ -114,15 +114,13 @@ const remove = (id) => () => {
114114
};
115115

116116
const selectRow = (event) => {
117-
selectedRowState.val = event.target.closest("tr");
117+
if (selectedRow) {
118+
selectedRow.className = "";
119+
}
120+
selectedRow = event.target.parentNode.parentNode;
121+
selectedRow.className = "danger";
118122
};
119123

120-
bau.derive(() => {
121-
let { val, oldVal } = selectedRowState;
122-
if (oldVal) oldVal.className = "";
123-
if (val) val.className = "danger";
124-
});
125-
126124
const Row = ({ id, label }) => {
127125
const tdIdEl = td({ class: "col-md-1" }, id);
128126
const aLabelEl = a({ onclick: selectRow }, label);

0 commit comments

Comments
 (0)