1
1
import {
2
2
createBlock ,
3
- $wire ,
4
- fragment ,
5
- } from '/Users/aidenybai/Projects/aidenybai/million/packages/next/block ' ;
3
+ createFragment ,
4
+ // make sure you import your local version of million
5
+ } from '/Users/aidenybai/Projects/aidenybai/million/packages/next/index ' ;
6
6
7
7
const adjectives = [
8
8
'pretty' ,
@@ -64,11 +64,13 @@ const random = (max) => Math.round(Math.random() * 1000) % max;
64
64
65
65
let nextId = 1 ;
66
66
let list = [ ] ;
67
+ let main ;
67
68
let selected = 0 ;
68
69
69
70
const clear = ( ) => {
70
71
list = [ ] ;
71
- update ( ) ;
72
+ main . children = [ ] ;
73
+ main . remove ( ) ;
72
74
} ;
73
75
74
76
const buildData = ( count ) => {
@@ -85,19 +87,19 @@ const buildData = (count) => {
85
87
} ;
86
88
87
89
const create1k = ( ) => {
88
- clear ( ) ;
90
+ if ( list . length ) clear ( ) ;
89
91
list = buildData ( 1000 ) ;
90
92
update ( ) ;
91
93
} ;
92
94
93
95
const create10k = ( ) => {
94
- clear ( ) ;
96
+ if ( list . length ) clear ( ) ;
95
97
list = buildData ( 10000 ) ;
96
98
update ( ) ;
97
99
} ;
98
100
99
101
const append1k = ( ) => {
100
- list . concat ( buildData ( 1000 ) ) ;
102
+ list = list . concat ( buildData ( 1000 ) ) ;
101
103
update ( ) ;
102
104
} ;
103
105
@@ -218,29 +220,15 @@ const Main = createBlock(({ rows }) => (
218
220
</ div >
219
221
) ) ;
220
222
221
- const Row = createBlock ( ( { className, id, label } ) => {
223
+ const Row = createBlock ( ( { className, id, select , remove , label } ) => {
222
224
return (
223
225
< tr class = { className } >
224
226
< td class = "col-md-1" > { id } </ td >
225
227
< td class = "col-md-4" >
226
- < a
227
- onClick = { $wire ( ( { id } ) => {
228
- return ( ) => {
229
- select ( id ) ;
230
- } ;
231
- } , id ) }
232
- >
233
- { label }
234
- </ a >
228
+ < a onClick = { select } > { label } </ a >
235
229
</ td >
236
230
< td class = "col-md-1" >
237
- < a
238
- onClick = { $wire ( ( { id } ) => {
239
- return ( ) => {
240
- remove ( id ) ;
241
- } ;
242
- } , id ) }
243
- >
231
+ < a onClick = { remove } >
244
232
< span class = "glyphicon glyphicon-remove" aria-hidden = "true" > </ span >
245
233
</ a >
246
234
</ td >
@@ -250,7 +238,7 @@ const Row = createBlock(({ className, id, label }) => {
250
238
} ) ;
251
239
252
240
function Rows ( { oldCache, newCache } ) {
253
- return fragment (
241
+ return createFragment (
254
242
list . map ( ( item ) => {
255
243
const isSelected = selected === item . id ;
256
244
const cachedItem = oldCache [ item . id ] ;
@@ -265,11 +253,13 @@ function Rows({ oldCache, newCache }) {
265
253
id = { item . id }
266
254
label = { item . label }
267
255
className = { isSelected ? 'danger' : '' }
256
+ remove = { ( ) => remove ( item . id ) }
257
+ select = { ( ) => select ( item . id ) }
268
258
/>
269
259
) ;
270
260
row . _data = [ item . label , isSelected ] ;
271
261
row . key = String ( item . id ) ;
272
- newCache [ row . id ] = row ;
262
+ newCache [ item . id ] = row ;
273
263
return row ;
274
264
} )
275
265
) ;
@@ -281,7 +271,7 @@ function render(oldCache, newCache) {
281
271
282
272
let oldCache = { } ;
283
273
284
- const main = render ( { } , oldCache ) ;
274
+ main = render ( { } , oldCache ) ;
285
275
( < Main rows = { main } /> ) . mount ( document . getElementById ( 'main' ) ) ;
286
276
287
277
function update ( ) {
0 commit comments