Skip to content

Commit 6ba6a85

Browse files
committed
- slightly more favorable options
- shallower propref chains
1 parent a2cff34 commit 6ba6a85

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

frameworks/non-keyed/mutraction/src/index.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
11
import { track, defaultTracker, ForEach } from "mutraction-dom";
22
import { buildData, type RowItem } from "./build-dummy-data.js";
3+
defaultTracker.setOptions({ trackHistory: false, compactOnCommit: false });
34

45
const model = track({
5-
items: [] as RowItem[],
66
selected: undefined as RowItem | undefined,
77
});
8+
const items = track([] as RowItem[]);
89

910
function select(item: RowItem) {
1011
model.selected = item;
1112
}
1213

1314
function create(n: number) {
14-
model.items.splice(0, model.items.length, ...buildData(n));
15+
items.splice(0, items.length, ...buildData(n));
1516
}
1617

1718
function append(n: number) {
18-
model.items.push(...buildData(n));
19+
items.push(...buildData(n));
1920
}
2021

2122
function update() {
2223
defaultTracker.startTransaction();
23-
for (let i = 0; i < model.items.length; i += 10) {
24-
model.items[i].label += " !!!";
24+
for (let i = 0; i < items.length; i += 10) {
25+
items[i].label += " !!!";
2526
}
2627
defaultTracker.commit();
2728
}
2829

2930
function clear() {
30-
model.items.length = 0;
31+
items.length = 0;
3132
}
3233

3334
function swapRows() {
34-
if (model.items.length > 998) {
35+
if (items.length > 998) {
3536
const i1 = 1, i2 = 998;
36-
[model.items[i1], model.items[i2]] = [model.items[i2], model.items[i1]];
37+
[items[i1], items[i2]] = [items[i2], items[i1]];
3738
}
3839
}
3940

4041
function remove(i: number) {
41-
model.items.splice(i, 1);
42+
delete items[i];
4243
}
4344

4445
const app =
@@ -74,7 +75,7 @@ const app =
7475
</div>
7576
<table className="table table-hover table-striped test-data">
7677
<tbody id="tbody">
77-
{ ForEach(model.items, (item, i) =>
78+
{ ForEach(items, (item, i) =>
7879
<tr classList={{ danger: item === model.selected }}>
7980
<td className="col-md-1">{ item.id }</td>
8081
<td className="col-md-4">

0 commit comments

Comments
 (0)