|
1 | | -"use strict"; |
2 | | - |
3 | 1 | import Mikado from "../node_modules/mikado/src/mikado.js"; |
4 | 2 | import app from "./template/app.es6.js"; |
5 | 3 | import item from "./template/item.es6.js"; |
6 | 4 | import { buildData } from "./data.js"; |
7 | | -import { startMeasure, stopMeasure } from "./bench.js"; |
8 | 5 |
|
9 | | -const main = document.getElementById("main"); |
10 | | -new Mikado(main, app).render().destroy(true); |
| 6 | +Mikado.once(document.getElementById("main"), app); |
11 | 7 |
|
12 | | -const state = { "selected": -1 }; |
| 8 | +const state = { "selected": {} }; |
13 | 9 | const root = document.getElementById("tbody"); |
14 | 10 | const mikado = Mikado.new(root, item, { |
15 | | - |
16 | | - "store": true, |
17 | | - "loose": true, |
18 | | - "reuse": false, |
19 | | - "state": state // external reference |
20 | | -}) |
21 | | -.route("run", function(){ |
22 | | - if(DEBUG) startMeasure("run"); |
23 | | - mikado.render(buildData(1000)); |
24 | | - if(DEBUG) stopMeasure(); |
25 | | -}) |
26 | | -.route("runlots", function(){ |
27 | | - if(DEBUG) startMeasure("runlots"); |
28 | | - mikado.render(buildData(10000)); |
29 | | - if(DEBUG) stopMeasure(); |
| 11 | + "reuse": false, "state": state |
30 | 12 | }) |
31 | | -.route("add", function(){ |
32 | | - if(DEBUG) startMeasure("add"); |
33 | | - mikado.append(buildData(1000)); |
34 | | - if(DEBUG) stopMeasure(); |
35 | | -}) |
36 | | -.route("update", function(){ |
37 | | - if(DEBUG) startMeasure("update"); |
| 13 | +.route("run", () => { mikado.render(buildData(1000)) }) |
| 14 | +.route("runlots", () => { mikado.render(buildData(10000)) }) |
| 15 | +.route("add", () => { mikado.append(buildData(1000)) }) |
| 16 | +.route("update", () => { |
38 | 17 | for(let i = 0, len = mikado.length; i < len; i += 10){ |
39 | | - mikado.item(i).label += " !!!"; |
| 18 | + mikado.data(i).label += " !!!"; |
40 | 19 | mikado.refresh(i); |
41 | 20 | } |
42 | | - if(DEBUG) stopMeasure(); |
43 | | -}) |
44 | | -.route("clear", function(){ |
45 | | - if(DEBUG) startMeasure("clear"); |
46 | | - mikado.clear(); |
47 | | - if(DEBUG) stopMeasure(); |
48 | | -}) |
49 | | -.route("swaprows", function(){ |
50 | | - if(DEBUG) startMeasure("swaprows"); |
51 | | - mikado.swap(1, 998); |
52 | | - if(DEBUG) stopMeasure(); |
53 | | -}) |
54 | | -.route("remove", function(target){ |
55 | | - if(DEBUG) startMeasure("remove"); |
56 | | - mikado.remove(target); |
57 | | - if(DEBUG) stopMeasure(); |
58 | 21 | }) |
59 | | -.route("select", function(target){ |
60 | | - if(DEBUG) startMeasure("select"); |
61 | | - const selected = state["selected"]; |
62 | | - if(selected >= 0) mikado.node(selected).className = ""; |
63 | | - target.className = "danger"; |
64 | | - state["selected"] = mikado.index(target); |
65 | | - if(DEBUG) stopMeasure(); |
| 22 | +.route("clear", () => { mikado.clear() }) |
| 23 | +.route("swaprows", () => { mikado.swap(1, 998) }) |
| 24 | +.route("remove", target => { mikado.remove(target) }) |
| 25 | +.route("select", target => { |
| 26 | + state["selected"].className = ""; |
| 27 | + (state["selected"] = target).className = "danger"; |
66 | 28 | }) |
67 | 29 | .listen("click"); |
0 commit comments