|
1 | 1 | import { track, defaultTracker, ForEach } from "mutraction-dom";
|
2 | 2 | import { buildData, type RowItem } from "./build-dummy-data.js";
|
| 3 | +defaultTracker.setOptions({ trackHistory: false, compactOnCommit: false }); |
3 | 4 |
|
4 | 5 | const model = track({
|
5 |
| - items: [] as RowItem[], |
6 | 6 | selected: undefined as RowItem | undefined,
|
7 | 7 | });
|
| 8 | +const items = track([] as RowItem[]); |
8 | 9 |
|
9 | 10 | function select(item: RowItem) {
|
10 | 11 | model.selected = item;
|
11 | 12 | }
|
12 | 13 |
|
13 | 14 | function create(n: number) {
|
14 |
| - model.items.splice(0, model.items.length, ...buildData(n)); |
| 15 | + items.splice(0, items.length, ...buildData(n)); |
15 | 16 | }
|
16 | 17 |
|
17 | 18 | function append(n: number) {
|
18 |
| - model.items.push(...buildData(n)); |
| 19 | + items.push(...buildData(n)); |
19 | 20 | }
|
20 | 21 |
|
21 | 22 | function update() {
|
22 | 23 | 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 += " !!!"; |
25 | 26 | }
|
26 | 27 | defaultTracker.commit();
|
27 | 28 | }
|
28 | 29 |
|
29 | 30 | function clear() {
|
30 |
| - model.items.length = 0; |
| 31 | + items.length = 0; |
31 | 32 | }
|
32 | 33 |
|
33 | 34 | function swapRows() {
|
34 |
| - if (model.items.length > 998) { |
| 35 | + if (items.length > 998) { |
35 | 36 | 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]]; |
37 | 38 | }
|
38 | 39 | }
|
39 | 40 |
|
40 | 41 | function remove(i: number) {
|
41 |
| - model.items.splice(i, 1); |
| 42 | + delete items[i]; |
42 | 43 | }
|
43 | 44 |
|
44 | 45 | const app =
|
@@ -74,7 +75,7 @@ const app =
|
74 | 75 | </div>
|
75 | 76 | <table className="table table-hover table-striped test-data">
|
76 | 77 | <tbody id="tbody">
|
77 |
| - { ForEach(model.items, (item, i) => |
| 78 | + { ForEach(items, (item, i) => |
78 | 79 | <tr classList={{ danger: item === model.selected }}>
|
79 | 80 | <td className="col-md-1">{ item.id }</td>
|
80 | 81 | <td className="col-md-4">
|
|
0 commit comments