-
Notifications
You must be signed in to change notification settings - Fork 834
/
main.imba
executable file
·116 lines (95 loc) · 3.03 KB
/
main.imba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
var A = ["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"]
var C = ["red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black", "orange"]
var N = ["table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger", "pizza", "mouse", "keyboard"]
extend tag element
attr aria-hidden
tag Row < tr
def select
trigger('select',@data)
def remove
trigger('remove',@data)
def render
return if @data === @prev
@prev = @data
<self>
<td.col-md-1 text=@data:id>
<td.col-md-4> <a :tap.select text=@data:label>
<td.col-md-1> <a :tap.remove> <span.glyphicon.glyphicon-remove aria-hidden=true>
<td.col-md-6>
var items = []
var selected = 0
var nextId = 1
tag Main
def run
items = buildData(1000)
selected = 0
Imba.commit
def runLots
items = buildData(10000)
selected = 0
def add
items = items.concat(buildData(1000))
def update
var i = 0
while i < items:length
var item = items[i]
items[i] = { id: item:id, label: item:label + ' !!!' }
i = i + 10
Imba.commit
def select item
selected = item:id
def remove item
items.splice(items.indexOf(item), 1)
Imba.commit
def onselect e
select(e.data)
def onremove e
remove(e.data)
def clear
items = []
selected = 0
def swapRows
if (items:length > 998)
var temp = items[1]
items[1] = items[998]
items[998] = temp
Imba.commit
def buildData(count)
var newItems = Array.new(count)
var i = 0
while i < count
newItems[i] = {
id: nextId ,
label: "{A[random(A:length)]} {C[random(C:length)]} {N[random(N:length)]}"
}
i = i + 1
nextId = nextId + 1
newItems
def random max
Math.round(Math.random * 1000) % max
def render
<self>
<div.container>
<div.jumbotron>
<div.row>
<div.col-md-6>
<h1> 'Imba keyed'
<div.col-md-6>
<div.row>
<div.col-sm-6.smallpad>
<button.btn.btn-primary.btn-block type='button' id='run' :tap.run> 'Create 1,000 rows'
<div.col-sm-6.smallpad>
<button.btn.btn-primary.btn-block type='button' id="runlots" :tap.runLots> "Create 10,000 rows"
<div.col-sm-6.smallpad>
<button.btn.btn-primary.btn-block type='button' id="add" :tap.add> "Append 1,000 rows"
<div.col-sm-6.smallpad>
<button.btn.btn-primary.btn-block type='button' id="update" :tap.update> "Update every 10th row"
<div.col-sm-6.smallpad>
<button.btn.btn-primary.btn-block type='button' id="clear" :tap.clear> "Clear"
<div.col-sm-6.smallpad>
<button.btn.btn-primary.btn-block type='button' id="swaprows" :tap.swapRows> "Swap Rows"
<table.table.table-hover.table-striped.test-data>
<tbody> for item in items
<Row@{item:id} data=item .danger=(selected === item:id)>
<span.glyphicon.glyphicon-remove.preloadicon aria-hidden=true>
Imba.mount <Main>