@@ -30,7 +30,7 @@ export interface ScrollInfo {
30
30
31
31
export interface ListProps < T > extends React . HTMLAttributes < any > {
32
32
children : RenderFunc < T > ;
33
- dataSource : T [ ] ;
33
+ data : T [ ] ;
34
34
height ?: number ;
35
35
itemHeight ?: number ;
36
36
itemKey : string ;
@@ -50,7 +50,7 @@ interface ListState<T> {
50
50
endIndex : number ;
51
51
/**
52
52
* Calculated by `scrollTop`.
53
- * We cache in the state since if `dataSource ` length change,
53
+ * We cache in the state since if `data ` length change,
54
54
* we need revert back to the located item index.
55
55
*/
56
56
startItemTop : number ;
@@ -80,7 +80,7 @@ interface ListState<T> {
80
80
class List < T > extends React . Component < ListProps < T > , ListState < T > > {
81
81
static defaultProps = {
82
82
itemHeight : 15 ,
83
- dataSource : [ ] ,
83
+ data : [ ] ,
84
84
} ;
85
85
86
86
state : ListState < T > = {
@@ -106,7 +106,7 @@ class List<T> extends React.Component<ListProps<T>, ListState<T>> {
106
106
107
107
/**
108
108
* Lock scroll process with `onScroll` event.
109
- * This is used for `dataSource ` length change and `scrollTop` restore
109
+ * This is used for `data ` length change and `scrollTop` restore
110
110
*/
111
111
lockScroll : boolean = false ;
112
112
@@ -124,8 +124,8 @@ class List<T> extends React.Component<ListProps<T>, ListState<T>> {
124
124
*/
125
125
public componentDidUpdate ( ) {
126
126
const { status } = this . state ;
127
- const { dataSource , height, itemHeight, disabled } = this . props ;
128
- const prevDataSource : T [ ] = this . cachedProps . dataSource || [ ] ;
127
+ const { data , height, itemHeight, disabled } = this . props ;
128
+ const prevData : T [ ] = this . cachedProps . data || [ ] ;
129
129
130
130
if ( disabled ) {
131
131
return ;
@@ -161,10 +161,10 @@ class List<T> extends React.Component<ListProps<T>, ListState<T>> {
161
161
}
162
162
163
163
/**
164
- * Re-calculate the item position since `dataSource ` length changed.
164
+ * Re-calculate the item position since `data ` length changed.
165
165
* [IMPORTANT] We use relative position calculate here.
166
166
*/
167
- if ( prevDataSource . length !== dataSource . length && height ) {
167
+ if ( prevData . length !== data . length && height ) {
168
168
const {
169
169
itemIndex : originItemIndex ,
170
170
itemOffsetPtg : originItemOffsetPtg ,
@@ -183,19 +183,15 @@ class List<T> extends React.Component<ListProps<T>, ListState<T>> {
183
183
itemElementHeights : this . itemElementHeights ,
184
184
scrollPtg : getScrollPercentage ( {
185
185
scrollTop : originScrollTop ,
186
- scrollHeight : prevDataSource . length * itemHeight ,
186
+ scrollHeight : prevData . length * itemHeight ,
187
187
clientHeight : this . listRef . current . clientHeight ,
188
188
} ) ,
189
189
clientHeight : this . listRef . current . clientHeight ,
190
190
getItemKey : ( index : number ) => this . getIndexKey ( index , this . cachedProps ) ,
191
191
} ) ;
192
192
193
193
// 2. Find the compare item
194
- const changedItemIndex : number = findListDiffIndex (
195
- prevDataSource ,
196
- dataSource ,
197
- this . getItemKey ,
198
- ) ;
194
+ const changedItemIndex : number = findListDiffIndex ( prevData , data , this . getItemKey ) ;
199
195
let originCompareItemIndex = changedItemIndex - 1 ;
200
196
// Use next one since there are not more item before removed
201
197
if ( originCompareItemIndex < 0 ) {
@@ -226,7 +222,7 @@ class List<T> extends React.Component<ListProps<T>, ListState<T>> {
226
222
* Phase 2: Trigger render since we should re-calculate current position.
227
223
*/
228
224
public onScroll = ( ) => {
229
- const { dataSource , height, itemHeight, disabled } = this . props ;
225
+ const { data , height, itemHeight, disabled } = this . props ;
230
226
231
227
const { scrollTop : originScrollTop , clientHeight, scrollHeight } = this . listRef . current ;
232
228
const scrollTop = alignScrollTop ( originScrollTop , scrollHeight - clientHeight ) ;
@@ -241,7 +237,7 @@ class List<T> extends React.Component<ListProps<T>, ListState<T>> {
241
237
242
238
const { itemIndex, itemOffsetPtg, startIndex, endIndex } = getRangeIndex (
243
239
scrollPtg ,
244
- dataSource . length ,
240
+ data . length ,
245
241
visibleCount ,
246
242
) ;
247
243
@@ -257,14 +253,14 @@ class List<T> extends React.Component<ListProps<T>, ListState<T>> {
257
253
258
254
public getIndexKey = ( index : number , props ?: Partial < ListProps < T > > ) => {
259
255
const mergedProps = props || this . props ;
260
- const { dataSource = [ ] } = mergedProps ;
256
+ const { data = [ ] } = mergedProps ;
261
257
262
258
// Return ghost key as latest index item
263
- if ( index === dataSource . length ) {
259
+ if ( index === data . length ) {
264
260
return GHOST_ITEM_KEY ;
265
261
}
266
262
267
- const item = dataSource [ index ] ;
263
+ const item = data [ index ] ;
268
264
if ( ! item ) {
269
265
console . error ( 'Not find index item. Please report this since it is a bug.' ) ;
270
266
}
@@ -296,7 +292,7 @@ class List<T> extends React.Component<ListProps<T>, ListState<T>> {
296
292
} else if ( typeof arg === 'object' ) {
297
293
const { itemIndex : compareItemIndex , relativeTop : compareItemRelativeTop } = arg ;
298
294
const { scrollTop : originScrollTop } = this . state ;
299
- const { dataSource , itemHeight, height } = this . props ;
295
+ const { data , itemHeight, height } = this . props ;
300
296
301
297
// 1. Find the best match compare item top
302
298
let bestSimilarity = Number . MAX_VALUE ;
@@ -308,7 +304,7 @@ class List<T> extends React.Component<ListProps<T>, ListState<T>> {
308
304
309
305
let missSimilarity = 0 ;
310
306
311
- const scrollHeight = dataSource . length * itemHeight ;
307
+ const scrollHeight = data . length * itemHeight ;
312
308
const { clientHeight } = this . listRef . current ;
313
309
const maxScrollTop = scrollHeight - clientHeight ;
314
310
@@ -320,7 +316,7 @@ class List<T> extends React.Component<ListProps<T>, ListState<T>> {
320
316
321
317
const { itemIndex, itemOffsetPtg, startIndex, endIndex } = getRangeIndex (
322
318
scrollPtg ,
323
- dataSource . length ,
319
+ data . length ,
324
320
visibleCount ,
325
321
) ;
326
322
@@ -418,7 +414,7 @@ class List<T> extends React.Component<ListProps<T>, ListState<T>> {
418
414
component : Component = 'div' ,
419
415
height,
420
416
itemHeight,
421
- dataSource ,
417
+ data ,
422
418
children,
423
419
itemKey,
424
420
...restProps
@@ -432,21 +428,21 @@ class List<T> extends React.Component<ListProps<T>, ListState<T>> {
432
428
} ;
433
429
434
430
// Render pure list if not set height or height is enough for all items
435
- if ( height === undefined || dataSource . length * itemHeight <= height ) {
431
+ if ( height === undefined || data . length * itemHeight <= height ) {
436
432
return (
437
433
< Component style = { mergedStyle } { ...restProps } >
438
- < Filler height = { height } > { this . renderChildren ( dataSource , 0 , children ) } </ Filler >
434
+ < Filler height = { height } > { this . renderChildren ( data , 0 , children ) } </ Filler >
439
435
</ Component >
440
436
) ;
441
437
}
442
438
443
439
const { status, startIndex, endIndex, startItemTop } = this . state ;
444
- const contentHeight = dataSource . length * itemHeight * ITEM_SCALE_RATE ;
440
+ const contentHeight = data . length * itemHeight * ITEM_SCALE_RATE ;
445
441
446
442
return (
447
443
< Component style = { mergedStyle } { ...restProps } onScroll = { this . onScroll } ref = { this . listRef } >
448
444
< Filler height = { contentHeight } offset = { status === 'MEASURE_DONE' ? startItemTop : 0 } >
449
- { this . renderChildren ( dataSource . slice ( startIndex , endIndex + 1 ) , startIndex , children ) }
445
+ { this . renderChildren ( data . slice ( startIndex , endIndex + 1 ) , startIndex , children ) }
450
446
</ Filler >
451
447
</ Component >
452
448
) ;
0 commit comments