1
+ <svelte:options immutable />
2
+
3
+ <script >
4
+ let rowId = 1 ;
5
+ let data = [];
6
+ let selected = undefined ;
7
+ const adjectives = [
8
+ " pretty" ,
9
+ " large" ,
10
+ " big" ,
11
+ " small" ,
12
+ " tall" ,
13
+ " short" ,
14
+ " long" ,
15
+ " handsome" ,
16
+ " plain" ,
17
+ " quaint" ,
18
+ " clean" ,
19
+ " elegant" ,
20
+ " easy" ,
21
+ " angry" ,
22
+ " crazy" ,
23
+ " helpful" ,
24
+ " mushy" ,
25
+ " odd" ,
26
+ " unsightly" ,
27
+ " adorable" ,
28
+ " important" ,
29
+ " inexpensive" ,
30
+ " cheap" ,
31
+ " expensive" ,
32
+ " fancy" ,
33
+ ];
34
+ const colours = [
35
+ " red" ,
36
+ " yellow" ,
37
+ " blue" ,
38
+ " green" ,
39
+ " pink" ,
40
+ " brown" ,
41
+ " purple" ,
42
+ " brown" ,
43
+ " white" ,
44
+ " black" ,
45
+ " orange" ,
46
+ ];
47
+ const nouns = [
48
+ " table" ,
49
+ " chair" ,
50
+ " house" ,
51
+ " bbq" ,
52
+ " desk" ,
53
+ " car" ,
54
+ " pony" ,
55
+ " cookie" ,
56
+ " sandwich" ,
57
+ " burger" ,
58
+ " pizza" ,
59
+ " mouse" ,
60
+ " keyboard" ,
61
+ ];
62
+ const add = () => (data = [... data, ... buildData (1000 )]),
63
+ clear = () => {
64
+ data = [];
65
+ },
66
+ partialUpdate = () => {
67
+ const clone = data .slice ();
68
+ for (let i = 0 ; i < data .length ; i += 10 ) {
69
+ // clone[i].label += " !!!";
70
+ clone[i] = {... clone[i], label: clone[i].label + ` !!!` }
71
+ }
72
+ data = clone;
73
+ },
74
+ remove = (row ) => {
75
+ const clone = data .slice ();
76
+ clone .splice (clone .indexOf (row), 1 );
77
+ data = clone;
78
+ },
79
+ run = () => {
80
+ data = buildData (1000 );
81
+ },
82
+ runLots = () => {
83
+ data = buildData (10000 );
84
+ },
85
+ swapRows = () => {
86
+ if (data .length > 998 ) {
87
+ const clone = data .slice ();
88
+ const tmp = clone[1 ];
89
+ clone[1 ] = data[998 ];
90
+ clone[998 ] = tmp;
91
+ data = clone;
92
+ }
93
+ };
94
+ function _random (max ) {
95
+ return Math .round (Math .random () * 1000 ) % max;
96
+ }
97
+ function createItem () {
98
+ let label = ` ${ adjectives[_random (adjectives .length )]} ${
99
+ colours[_random (colours .length )]
100
+ } ${ nouns[_random (nouns .length )]} ` ;
101
+ return {
102
+ id: rowId++ ,
103
+ label,
104
+ };
105
+ }
106
+ function buildData (count = 1000 ) {
107
+ const data = new Array (count);
108
+ for (let i = 0 ; i < count; i++ ) {
109
+ data[i] = createItem ();
110
+ }
111
+ return data;
112
+ }
113
+ </script >
114
+
115
+ <div class =" jumbotron" >
116
+ <div class =" row" >
117
+ <div class =" col-md-6" >
118
+ <h1 >Svelte Classic (keyed)</h1 >
119
+ </div >
120
+ <div class =" col-md-6" >
121
+ <div class =" row" >
122
+ <div class =" col-sm-6 smallpad" >
123
+ <button
124
+ type =" button"
125
+ class =" btn btn-primary btn-block"
126
+ id =" run"
127
+ on:click ={run }>Create 1,000 rows</button
128
+ >
129
+ </div >
130
+ <div class =" col-sm-6 smallpad" >
131
+ <button
132
+ type =" button"
133
+ class =" btn btn-primary btn-block"
134
+ id =" runlots"
135
+ on:click ={runLots }>Create 10,000 rows</button
136
+ >
137
+ </div >
138
+ <div class =" col-sm-6 smallpad" >
139
+ <button
140
+ type =" button"
141
+ class =" btn btn-primary btn-block"
142
+ id =" add"
143
+ on:click ={add }>Append 1,000 rows</button
144
+ >
145
+ </div >
146
+ <div class =" col-sm-6 smallpad" >
147
+ <button
148
+ type =" button"
149
+ class =" btn btn-primary btn-block"
150
+ id =" update"
151
+ on:click ={partialUpdate }>Update every 10th row</button
152
+ >
153
+ </div >
154
+ <div class =" col-sm-6 smallpad" >
155
+ <button
156
+ type =" button"
157
+ class =" btn btn-primary btn-block"
158
+ id =" clear"
159
+ on:click ={clear }>Clear</button
160
+ >
161
+ </div >
162
+ <div class =" col-sm-6 smallpad" >
163
+ <button
164
+ type =" button"
165
+ class =" btn btn-primary btn-block"
166
+ id =" swaprows"
167
+ on:click ={swapRows }>Swap Rows</button
168
+ >
169
+ </div >
170
+ </div >
171
+ </div >
172
+ </div >
173
+ </div >
174
+ <table class =" table table-hover table-striped test-data" >
175
+ <tbody >
176
+ {#each data as row (row .id )}
177
+ <tr class ={selected === row .id ? " danger" : " " }
178
+ ><td class ="col-md-1" >{row .id }</td ><td class =" col-md-4"
179
+ ><a on:click ={() => (selected = row .id )}>{row .label }</a ></td
180
+ ><td class =" col-md-1"
181
+ ><a on:click ={() => remove (row )}
182
+ ><span class =" glyphicon glyphicon-remove" aria-hidden =" true" /></a
183
+ ></td
184
+ ><td class =" col-md-6" /></tr
185
+ >
186
+ {/each }
187
+ </tbody >
188
+ </table >
189
+ <span class =" preloadicon glyphicon glyphicon-remove" aria-hidden =" true" />
0 commit comments