1
1
import {
2
2
createBlock ,
3
- createFragment ,
4
- // make sure you import your local version of million
5
- } from '/Users/aidenybai/Projects/aidenybai/million/packages/next/index' ;
3
+ fragment ,
4
+ } from '/Users/aidenybai/Projects/aidenybai/million/packages/block/index' ;
6
5
7
6
const adjectives = [
8
7
'pretty' ,
@@ -86,24 +85,28 @@ const buildData = (count) => {
86
85
return data ;
87
86
} ;
88
87
89
- const create1k = ( ) => {
88
+ const create1k = ( event ) => {
89
+ event . stopPropagation ( ) ;
90
90
if ( list . length ) clear ( ) ;
91
91
list = buildData ( 1000 ) ;
92
92
update ( ) ;
93
93
} ;
94
94
95
- const create10k = ( ) => {
95
+ const create10k = ( event ) => {
96
+ event . stopPropagation ( ) ;
96
97
if ( list . length ) clear ( ) ;
97
98
list = buildData ( 10000 ) ;
98
99
update ( ) ;
99
100
} ;
100
101
101
- const append1k = ( ) => {
102
+ const append1k = ( event ) => {
103
+ event . stopPropagation ( ) ;
102
104
list = list . concat ( buildData ( 1000 ) ) ;
103
105
update ( ) ;
104
106
} ;
105
107
106
- const updateEvery10 = ( ) => {
108
+ const updateEvery10 = ( event ) => {
109
+ event . stopPropagation ( ) ;
107
110
let i = 0 ;
108
111
while ( i < list . length ) {
109
112
list [ i ] . label = `${ list [ i ] . label } !!!` ;
@@ -112,7 +115,8 @@ const updateEvery10 = () => {
112
115
update ( ) ;
113
116
} ;
114
117
115
- const swapRows = ( ) => {
118
+ const swapRows = ( event ) => {
119
+ event . stopPropagation ( ) ;
116
120
if ( list . length > 998 ) {
117
121
const item = list [ 1 ] ;
118
122
list [ 1 ] = list [ 998 ] ;
@@ -134,6 +138,13 @@ const remove = (id) => {
134
138
update ( ) ;
135
139
} ;
136
140
141
+ const shouldUpdate = ( oldProps , newProps ) => {
142
+ return (
143
+ oldProps . label !== newProps . label ||
144
+ oldProps . className !== newProps . className
145
+ ) ;
146
+ } ;
147
+
137
148
const Main = createBlock ( ( { rows } ) => (
138
149
< div class = "container" >
139
150
< div class = "jumbotron" >
@@ -188,7 +199,8 @@ const Main = createBlock(({ rows }) => (
188
199
type = "button"
189
200
class = "btn btn-primary btn-block"
190
201
id = "clear"
191
- onClick = { ( ) => {
202
+ onClick = { ( event ) => {
203
+ event . stopPropagation ( ) ;
192
204
clear ( ) ;
193
205
update ( ) ;
194
206
} }
@@ -238,7 +250,7 @@ const Row = createBlock(({ className, id, select, remove, label }) => {
238
250
} ) ;
239
251
240
252
function Rows ( { oldCache, newCache } ) {
241
- return createFragment (
253
+ return fragment (
242
254
list . map ( ( item ) => {
243
255
const isSelected = selected === item . id ;
244
256
const cachedItem = oldCache [ item . id ] ;
@@ -253,12 +265,19 @@ function Rows({ oldCache, newCache }) {
253
265
id = { item . id }
254
266
label = { item . label }
255
267
className = { isSelected ? 'danger' : '' }
256
- remove = { ( ) => remove ( item . id ) }
257
- select = { ( ) => select ( item . id ) }
268
+ remove = { ( event ) => {
269
+ event . stopPropagation ( ) ;
270
+ remove ( item . id ) ;
271
+ } }
272
+ select = { ( event ) => {
273
+ event . stopPropagation ( ) ;
274
+ select ( item . id ) ;
275
+ } }
258
276
/>
259
277
) ;
260
278
row . _data = [ item . label , isSelected ] ;
261
279
row . key = String ( item . id ) ;
280
+ row . shouldUpdate = shouldUpdate ;
262
281
newCache [ item . id ] = row ;
263
282
return row ;
264
283
} )
0 commit comments