|
| 1 | +import { jsx } from "butterfloat"; |
| 2 | +import { AppViewModel } from "./app-vm.js"; |
| 3 | +import { Row } from "./row.js"; |
| 4 | +import { map, withLatestFrom } from "rxjs"; |
| 5 | +function App(_props, { bindEffect, bindImmediateEffect, events }) { |
| 6 | + const vm = new AppViewModel(); |
| 7 | + const children = vm.rows.pipe(map((row) => () => /* @__PURE__ */ jsx(Row, { vm: row }))); |
| 8 | + bindImmediateEffect(events.run, () => vm.createRows(1e3)); |
| 9 | + bindImmediateEffect(events.runlots, () => vm.createRows(1e4)); |
| 10 | + bindImmediateEffect(events.add, () => vm.appendRows(1e3)); |
| 11 | + bindImmediateEffect(events.clear, () => vm.clear()); |
| 12 | + bindEffect( |
| 13 | + events.update.pipe(withLatestFrom(events.tbodyAttach)), |
| 14 | + ([_, tbody]) => { |
| 15 | + const rows = tbody.querySelectorAll("tr"); |
| 16 | + for (let i = 0; i < rows.length; i += 10) { |
| 17 | + const row = rows[i]; |
| 18 | + const id = Number.parseInt(row.dataset.id, 10); |
| 19 | + vm.updateRow(id); |
| 20 | + } |
| 21 | + } |
| 22 | + ); |
| 23 | + bindEffect( |
| 24 | + events.swaprows.pipe(withLatestFrom(events.tbodyAttach)), |
| 25 | + ([_, tbody]) => { |
| 26 | + const rows = tbody.querySelectorAll("tr"); |
| 27 | + if (rows.length > 998) { |
| 28 | + const row0 = rows[0]; |
| 29 | + const row1 = rows[1]; |
| 30 | + const row997 = rows[997]; |
| 31 | + const row998 = rows[998]; |
| 32 | + row0.after(row998); |
| 33 | + row997.after(row1); |
| 34 | + } |
| 35 | + } |
| 36 | + ); |
| 37 | + return /* @__PURE__ */ jsx("div", { class: "container" }, /* @__PURE__ */ jsx("div", { class: "jumbotron" }, /* @__PURE__ */ jsx("div", { class: "row" }, /* @__PURE__ */ jsx("div", { class: "col-md-6" }, /* @__PURE__ */ jsx("h1", null, "Butterfloat")), /* @__PURE__ */ jsx("div", { class: "col-md-6" }, /* @__PURE__ */ jsx("div", { class: "row" }, /* @__PURE__ */ jsx("div", { class: "col-sm-6 smallpad" }, /* @__PURE__ */ jsx( |
| 38 | + "button", |
| 39 | + { |
| 40 | + type: "button", |
| 41 | + class: "btn btn-primary btn-block", |
| 42 | + id: "run", |
| 43 | + events: { click: events.run } |
| 44 | + }, |
| 45 | + "Create 1,000 rows" |
| 46 | + )), /* @__PURE__ */ jsx("div", { class: "col-sm-6 smallpad" }, /* @__PURE__ */ jsx( |
| 47 | + "button", |
| 48 | + { |
| 49 | + type: "button", |
| 50 | + class: "btn btn-primary btn-block", |
| 51 | + id: "runlots", |
| 52 | + events: { click: events.runlots } |
| 53 | + }, |
| 54 | + "Create 10,000 rows" |
| 55 | + )), /* @__PURE__ */ jsx("div", { class: "col-sm-6 smallpad" }, /* @__PURE__ */ jsx( |
| 56 | + "button", |
| 57 | + { |
| 58 | + type: "button", |
| 59 | + class: "btn btn-primary btn-block", |
| 60 | + id: "add", |
| 61 | + events: { click: events.add } |
| 62 | + }, |
| 63 | + "Append 1,000 rows" |
| 64 | + )), /* @__PURE__ */ jsx("div", { class: "col-sm-6 smallpad" }, /* @__PURE__ */ jsx( |
| 65 | + "button", |
| 66 | + { |
| 67 | + type: "button", |
| 68 | + class: "btn btn-primary btn-block", |
| 69 | + id: "update", |
| 70 | + events: { click: events.update } |
| 71 | + }, |
| 72 | + "Update every 10th row" |
| 73 | + )), /* @__PURE__ */ jsx("div", { class: "col-sm-6 smallpad" }, /* @__PURE__ */ jsx( |
| 74 | + "button", |
| 75 | + { |
| 76 | + type: "button", |
| 77 | + class: "btn btn-primary btn-block", |
| 78 | + id: "clear", |
| 79 | + events: { click: events.clear } |
| 80 | + }, |
| 81 | + "Clear" |
| 82 | + )), /* @__PURE__ */ jsx("div", { class: "col-sm-6 smallpad" }, /* @__PURE__ */ jsx( |
| 83 | + "button", |
| 84 | + { |
| 85 | + type: "button", |
| 86 | + class: "btn btn-primary btn-block", |
| 87 | + id: "swaprows", |
| 88 | + events: { click: events.swaprows } |
| 89 | + }, |
| 90 | + "Swap Rows" |
| 91 | + )))))), /* @__PURE__ */ jsx("table", { class: "table table-hover table-striped test-data" }, /* @__PURE__ */ jsx( |
| 92 | + "tbody", |
| 93 | + { |
| 94 | + id: "tbody", |
| 95 | + childrenBind: children, |
| 96 | + childrenBindMode: "append", |
| 97 | + events: { bfDomAttach: events.tbodyAttach } |
| 98 | + } |
| 99 | + ))); |
| 100 | +} |
| 101 | +export { |
| 102 | + App |
| 103 | +}; |
0 commit comments