|  | 
| 1 |  | -import { define, html, render } from '../node_modules/heresy/esm/index.js'; | 
|  | 1 | +import {State} from 'js-framework-benchmark-utils'; | 
|  | 2 | +import {define, html, render} from 'heresy'; | 
| 2 | 3 | 
 | 
| 3 | 4 | import App from './ui/app.js'; | 
| 4 | 5 | define('App', App); | 
| 5 | 6 | 
 | 
| 6 |  | -let did = 1; | 
| 7 |  | -const buildData = (count) => { | 
| 8 |  | -    const adjectives = ["pretty", "large", "big", "small", "tall", "short", "long", "handsome", "plain", "quaint", "clean", "elegant", "easy", "angry", "crazy", "helpful", "mushy", "odd", "unsightly", "adorable", "important", "inexpensive", "cheap", "expensive", "fancy"]; | 
| 9 |  | -    const colours = ["red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black", "orange"]; | 
| 10 |  | -    const nouns = ["table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger", "pizza", "mouse", "keyboard"]; | 
| 11 |  | -    const data = []; | 
| 12 |  | -    for (let i = 0; i < count; i++) { | 
| 13 |  | -        data.push({ | 
| 14 |  | -            id: did++, | 
| 15 |  | -            label: adjectives[_random(adjectives.length)] + " " + colours[_random(colours.length)] + " " + nouns[_random(nouns.length)] | 
| 16 |  | -        }); | 
| 17 |  | -    } | 
| 18 |  | -    return data; | 
| 19 |  | -}; | 
| 20 |  | - | 
| 21 |  | -const _random = max => Math.round(Math.random() * 1000) % max; | 
| 22 |  | - | 
| 23 |  | -const scope = { | 
| 24 |  | -    add() { | 
| 25 |  | -        scope.data = scope.data.concat(buildData(1000)); | 
| 26 |  | -        update(main, scope); | 
| 27 |  | -    }, | 
| 28 |  | -    run() { | 
| 29 |  | -        scope.data = buildData(1000); | 
| 30 |  | -        update(main, scope); | 
| 31 |  | -    }, | 
| 32 |  | -    runLots() { | 
| 33 |  | -        scope.data = buildData(10000); | 
| 34 |  | -        update(main, scope); | 
| 35 |  | -    }, | 
| 36 |  | -    clear() { | 
| 37 |  | -        scope.data = []; | 
| 38 |  | -        update(main, scope); | 
| 39 |  | -    }, | 
| 40 |  | -    update() { | 
| 41 |  | -        const {data} = scope; | 
| 42 |  | -        for (let i = 0, {length} = data; i < length; i += 10) | 
| 43 |  | -            data[i].label += ' !!!'; | 
| 44 |  | -        update(main, scope); | 
| 45 |  | -    }, | 
| 46 |  | -    swapRows() { | 
| 47 |  | -        const {data} = scope; | 
| 48 |  | -        if (data.length > 998) { | 
| 49 |  | -            const tmp = data[1]; | 
| 50 |  | -            data[1] = data[998]; | 
| 51 |  | -            data[998] = tmp; | 
| 52 |  | -        } | 
| 53 |  | -        update(main, scope); | 
| 54 |  | -    }, | 
| 55 |  | -    interact(event) { | 
| 56 |  | -      event.preventDefault(); | 
| 57 |  | -      const a = event.target.closest('a'); | 
| 58 |  | -      const id = parseInt(a.closest('tr').id, 10); | 
| 59 |  | -      scope[a.dataset.action](id); | 
| 60 |  | -    }, | 
| 61 |  | -    delete(id) { | 
| 62 |  | -        const {data} = scope; | 
| 63 |  | -        const idx = data.findIndex(d => d.id === id); | 
| 64 |  | -        data.splice(idx, 1); | 
| 65 |  | -        update(main, scope); | 
| 66 |  | -    }, | 
| 67 |  | -    select(id) { | 
| 68 |  | -        scope.selected = id; | 
| 69 |  | -        update(main, scope); | 
| 70 |  | -    }, | 
| 71 |  | -    selected: -1, | 
| 72 |  | -    data: [], | 
| 73 |  | -}; | 
| 74 |  | - | 
|  | 7 | +const state = State(update); | 
| 75 | 8 | const main = document.getElementById('container'); | 
| 76 | 9 | 
 | 
| 77 |  | -update(main, scope); | 
|  | 10 | +update(state); | 
| 78 | 11 | 
 | 
| 79 |  | -function update(main, scope) { | 
| 80 |  | -  render(main, html`<App .scope=${scope} />`); | 
|  | 12 | +function update(state) { | 
|  | 13 | +  render(main, html`<App .state=${state} />`); | 
| 81 | 14 | } | 
0 commit comments