1
+ const reactive = window . reactive ;
2
+ const html = window . html ;
3
+ let data = reactive ( {
4
+ items : [ ] ,
5
+ selected : undefined ,
6
+ } ) ;
7
+
8
+ let rowId = 1 ;
9
+ const add = ( ) => data . items = data . items . concat ( buildData ( 1000 ) ) ,
10
+ clear = ( ) => {
11
+ data . items = [ ] ;
12
+ data . selected = undefined ;
13
+ } ,
14
+ partialUpdate = ( ) => {
15
+ for ( let i = 0 ; i < data . items . length ; i += 10 ) {
16
+ data . items [ i ] . label += ' !!!' ;
17
+ }
18
+ } ,
19
+ remove = ( num ) => {
20
+ console . log ( num ) ;
21
+ const idx = data . items . findIndex ( d => d . id === num ) ;
22
+ data . items . splice ( idx , 1 ) ;
23
+ } ,
24
+ run = ( ) => {
25
+ data . items = buildData ( 1000 ) ;
26
+ data . selected = undefined ;
27
+ } ,
28
+ runLots = ( ) => {
29
+ data . items = buildData ( 10000 ) ;
30
+ data . selected = undefined ;
31
+ } ,
32
+ select = ( id ) => data . selected = id ,
33
+ swapRows = ( ) => {
34
+ if ( data . items . length > 998 ) {
35
+ data . items = [ data . items [ 0 ] , data . items [ 998 ] , ...data . items . slice ( 2 , 998 ) , data . items [ 1 ] , data . items [ 999 ] ] ;
36
+ }
37
+ } ;
38
+
39
+ function _random ( max ) { return Math . round ( Math . random ( ) * 1000 ) % max ; } ;
40
+
41
+ function buildData ( count = 1000 ) {
42
+ 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" ] ,
43
+ colours = [ "red" , "yellow" , "blue" , "green" , "pink" , "brown" , "purple" , "brown" , "white" , "black" , "orange" ] ,
44
+ nouns = [ "table" , "chair" , "house" , "bbq" , "desk" , "car" , "pony" , "cookie" , "sandwich" , "burger" , "pizza" , "mouse" , "keyboard" ] ,
45
+ data = new Array ( count ) ;
46
+ for ( var i = 0 ; i < count ; i ++ )
47
+ data [ i ] = { id : rowId ++ , label : adjectives [ _random ( adjectives . length ) ] + " " + colours [ _random ( colours . length ) ] + " " + nouns [ _random ( nouns . length ) ] } ;
48
+ return data ;
49
+ }
50
+ html `< div >
51
+ < div class ="jumbotron ">
52
+ < div class ="row ">
53
+ < div class ="col-md-6 ">
54
+ < h1 > Arrowjs (keyed)</ h1 >
55
+ </ div >
56
+ < div class ="col-md-6 ">
57
+ < div class ="row ">
58
+ < div class ="col-sm-6 smallpad ">
59
+ < button type ="button " class ="btn btn-primary btn-block " id ="run " @click ="${ run } "> Create 1,000 rows</ button >
60
+ </ div >
61
+ < div class ="col-sm-6 smallpad ">
62
+ < button type ="button " class ="btn btn-primary btn-block " id ="runlots " @click ="${ runLots } "> Create 10,000
63
+ rows</ button >
64
+ </ div >
65
+ < div class ="col-sm-6 smallpad ">
66
+ < button type ="button " class ="btn btn-primary btn-block " id ="add " @click ="${ add } "> Append 1,000 rows</ button >
67
+ </ div >
68
+ < div class ="col-sm-6 smallpad ">
69
+ < button type ="button " class ="btn btn-primary btn-block " id ="update " @click ="${ partialUpdate } "> Update every
70
+ 10th row</ button >
71
+ </ div >
72
+ < div class ="col-sm-6 smallpad ">
73
+ < button type ="button " class ="btn btn-primary btn-block " id ="clear " @click ="${ clear } "> Clear</ button >
74
+ </ div >
75
+ < div class ="col-sm-6 smallpad ">
76
+ < button type ="button " class ="btn btn-primary btn-block " id ="swaprows " @click ="${ swapRows } "> Swap Rows</ button >
77
+ </ div >
78
+ </ div >
79
+ </ div >
80
+ </ div >
81
+ </ div >
82
+ < table class ="table table-hover table-striped test-data ">
83
+ < tbody >
84
+ ${ ( ) =>
85
+ data . items . map ( ( row ) => html `< tr class ="${ ( ) => data . selected === row . id ? 'danger' : '' } ">
86
+ < td class ="col-md-1 "> ${ row . id } </ td >
87
+ < td class ="col-md-4 ">
88
+ < a @click ="${ ( ) => select ( row . id ) } "> ${ row . label } </ a >
89
+ </ td >
90
+ < td class ="col-md-1 ">
91
+ < a @click ="${ ( ) => remove ( row . id ) } ">
92
+ < span class ="glyphicon glyphicon-remove " aria-hidden ="true " />
93
+ </ a >
94
+ </ td >
95
+ < td class ="col-md-6 "/>
96
+ </ tr > ` . key ( row . id )
97
+ ) }
98
+ </ tbody >
99
+ </ table >
100
+ < span class ="preloadicon glyphicon glyphicon-remove " aria-hidden ="true "> </ span >
101
+ </ div >
102
+ ` ( document . getElementById ( 'arrow' ) )
0 commit comments