Skip to content
This repository was archived by the owner on Mar 9, 2024. It is now read-only.

Commit 21d59ec

Browse files
committedOct 3, 2018
Make itemData generic in grids and lists
In this PR I am trying to achieve more sound implementation of itemData props in all grids and lists. To prevent `empty` type itemData is made optional with defaultProps. `flow` script is replaced with `flow:check` to allow running `yarn flow status` to view all errors and warnings.
1 parent 4cce96f commit 21d59ec

10 files changed

+261
-93
lines changed
 

‎.flowconfig

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
[lints]
88

99
[options]
10+
include_warnings=true
1011

1112
[strict]

‎.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ before_script:
55
- yarn
66
script:
77
- yarn lint
8-
- yarn flow
8+
- yarn flow:check
99
- yarn test

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"module": "dist/index.esm.js",
3939
"files": ["dist", "src/*.js"],
4040
"scripts": {
41-
"flow": "flow check src && flow check website",
41+
"flow:check": "flow check --max-warnings=0 src && flow check website",
4242
"precommit": "lint-staged",
4343
"prettier": "prettier --write '**/*.{js,json,css}'",
4444
"linc": "lint-staged",

‎src/FixedSizeGrid.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@ import createGridComponent from './createGridComponent';
55
import type { Props, ScrollToAlign } from './createGridComponent';
66

77
const FixedSizeGrid = createGridComponent({
8-
getColumnOffset: ({ columnWidth }: Props, index: number): number =>
8+
getColumnOffset: ({ columnWidth }: Props<any>, index: number): number =>
99
index * ((columnWidth: any): number),
1010

11-
getColumnWidth: ({ columnWidth }: Props, index: number): number =>
11+
getColumnWidth: ({ columnWidth }: Props<any>, index: number): number =>
1212
((columnWidth: any): number),
1313

14-
getRowOffset: ({ rowHeight }: Props, index: number): number =>
14+
getRowOffset: ({ rowHeight }: Props<any>, index: number): number =>
1515
index * ((rowHeight: any): number),
1616

17-
getRowHeight: ({ rowHeight }: Props, index: number): number =>
17+
getRowHeight: ({ rowHeight }: Props<any>, index: number): number =>
1818
((rowHeight: any): number),
1919

20-
getEstimatedTotalHeight: ({ rowCount, rowHeight }: Props) =>
20+
getEstimatedTotalHeight: ({ rowCount, rowHeight }: Props<any>) =>
2121
((rowHeight: any): number) * rowCount,
2222

23-
getEstimatedTotalWidth: ({ columnCount, columnWidth }: Props) =>
23+
getEstimatedTotalWidth: ({ columnCount, columnWidth }: Props<any>) =>
2424
((columnWidth: any): number) * columnCount,
2525

2626
getOffsetForColumnAndAlignment: (
27-
{ columnCount, columnWidth, width }: Props,
27+
{ columnCount, columnWidth, width }: Props<any>,
2828
columnIndex: number,
2929
align: ScrollToAlign,
3030
scrollLeft: number
@@ -63,7 +63,7 @@ const FixedSizeGrid = createGridComponent({
6363
},
6464

6565
getOffsetForRowAndAlignment: (
66-
{ rowHeight, height, rowCount }: Props,
66+
{ rowHeight, height, rowCount }: Props<any>,
6767
rowIndex: number,
6868
align: ScrollToAlign,
6969
scrollTop: number
@@ -102,7 +102,7 @@ const FixedSizeGrid = createGridComponent({
102102
},
103103

104104
getColumnStartIndexForOffset: (
105-
{ columnWidth, columnCount }: Props,
105+
{ columnWidth, columnCount }: Props<any>,
106106
scrollLeft: number
107107
): number =>
108108
Math.max(
@@ -114,7 +114,7 @@ const FixedSizeGrid = createGridComponent({
114114
),
115115

116116
getColumnStopIndexForStartIndex: (
117-
{ columnWidth, columnCount, width }: Props,
117+
{ columnWidth, columnCount, width }: Props<any>,
118118
startIndex: number,
119119
scrollLeft: number
120120
): number => {
@@ -132,7 +132,7 @@ const FixedSizeGrid = createGridComponent({
132132
},
133133

134134
getRowStartIndexForOffset: (
135-
{ rowHeight, rowCount }: Props,
135+
{ rowHeight, rowCount }: Props<any>,
136136
scrollTop: number
137137
): number =>
138138
Math.max(
@@ -141,7 +141,7 @@ const FixedSizeGrid = createGridComponent({
141141
),
142142

143143
getRowStopIndexForStartIndex: (
144-
{ rowHeight, rowCount, height }: Props,
144+
{ rowHeight, rowCount, height }: Props<any>,
145145
startIndex: number,
146146
scrollTop: number
147147
): number => {
@@ -156,13 +156,13 @@ const FixedSizeGrid = createGridComponent({
156156
);
157157
},
158158

159-
initInstanceProps(props: Props): any {
159+
initInstanceProps(props: Props<any>): any {
160160
// Noop
161161
},
162162

163163
shouldResetStyleCacheOnItemSizeChange: true,
164164

165-
validateProps: ({ columnWidth, rowHeight }: Props): void => {
165+
validateProps: ({ columnWidth, rowHeight }: Props<any>): void => {
166166
if (process.env.NODE_ENV !== 'production') {
167167
if (typeof columnWidth !== 'number') {
168168
throw Error(

‎src/FixedSizeList.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import createListComponent from './createListComponent';
55
import type { Props, ScrollToAlign } from './createListComponent';
66

77
const FixedSizeList = createListComponent({
8-
getItemOffset: ({ itemSize, size }: Props, index: number): number =>
8+
getItemOffset: ({ itemSize, size }: Props<any>, index: number): number =>
99
index * ((itemSize: any): number),
1010

11-
getItemSize: ({ itemSize, size }: Props, index: number): number =>
11+
getItemSize: ({ itemSize, size }: Props<any>, index: number): number =>
1212
((itemSize: any): number),
1313

14-
getEstimatedTotalSize: ({ itemCount, itemSize }: Props) =>
14+
getEstimatedTotalSize: ({ itemCount, itemSize }: Props<any>) =>
1515
((itemSize: any): number) * itemCount,
1616

1717
getOffsetForIndexAndAlignment: (
18-
{ direction, height, itemCount, itemSize, width }: Props,
18+
{ direction, height, itemCount, itemSize, width }: Props<any>,
1919
index: number,
2020
align: ScrollToAlign,
2121
scrollOffset: number
@@ -53,7 +53,7 @@ const FixedSizeList = createListComponent({
5353
},
5454

5555
getStartIndexForOffset: (
56-
{ itemCount, itemSize }: Props,
56+
{ itemCount, itemSize }: Props<any>,
5757
offset: number
5858
): number =>
5959
Math.max(
@@ -62,7 +62,7 @@ const FixedSizeList = createListComponent({
6262
),
6363

6464
getStopIndexForStartIndex: (
65-
{ direction, height, itemCount, itemSize, width }: Props,
65+
{ direction, height, itemCount, itemSize, width }: Props<any>,
6666
startIndex: number,
6767
scrollOffset: number
6868
): number => {
@@ -80,13 +80,13 @@ const FixedSizeList = createListComponent({
8080
);
8181
},
8282

83-
initInstanceProps(props: Props): any {
83+
initInstanceProps(props: Props<any>): any {
8484
// Noop
8585
},
8686

8787
shouldResetStyleCacheOnItemSizeChange: true,
8888

89-
validateProps: ({ itemSize }: Props): void => {
89+
validateProps: ({ itemSize }: Props<any>): void => {
9090
if (process.env.NODE_ENV !== 'production') {
9191
if (typeof itemSize !== 'number') {
9292
throw Error(

‎src/VariableSizeGrid.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const DEFAULT_ESTIMATED_ITEM_SIZE = 50;
99
type VariableSizeProps = {|
1010
estimatedColumnWidth: number,
1111
estimatedRowHeight: number,
12-
...Props,
12+
...Props<any>,
1313
|};
1414

1515
type itemSizeGetter = (index: number) => number;
@@ -30,7 +30,7 @@ type InstanceProps = {|
3030
|};
3131

3232
const getEstimatedTotalHeight = (
33-
{ rowCount }: Props,
33+
{ rowCount }: Props<any>,
3434
{ rowMetadataMap, estimatedRowHeight, lastMeasuredRowIndex }: InstanceProps
3535
) => {
3636
let totalSizeOfMeasuredRows = 0;
@@ -47,7 +47,7 @@ const getEstimatedTotalHeight = (
4747
};
4848

4949
const getEstimatedTotalWidth = (
50-
{ columnCount }: Props,
50+
{ columnCount }: Props<any>,
5151
{
5252
columnMetadataMap,
5353
estimatedColumnWidth,
@@ -69,7 +69,7 @@ const getEstimatedTotalWidth = (
6969

7070
const getItemMetadata = (
7171
itemType: ItemType,
72-
props: Props,
72+
props: Props<any>,
7373
index: number,
7474
instanceProps: InstanceProps
7575
): ItemMetadata => {
@@ -114,7 +114,7 @@ const getItemMetadata = (
114114

115115
const findNearestItem = (
116116
itemType: ItemType,
117-
props: Props,
117+
props: Props<any>,
118118
instanceProps: InstanceProps,
119119
offset: number
120120
) => {
@@ -156,7 +156,7 @@ const findNearestItem = (
156156

157157
const findNearestItemBinarySearch = (
158158
itemType: ItemType,
159-
props: Props,
159+
props: Props<any>,
160160
instanceProps: InstanceProps,
161161
high: number,
162162
low: number,
@@ -189,7 +189,7 @@ const findNearestItemBinarySearch = (
189189

190190
const findNearestItemExponentialSearch = (
191191
itemType: ItemType,
192-
props: Props,
192+
props: Props<any>,
193193
instanceProps: InstanceProps,
194194
index: number,
195195
offset: number
@@ -217,7 +217,7 @@ const findNearestItemExponentialSearch = (
217217

218218
const getOffsetForIndexAndAlignment = (
219219
itemType: ItemType,
220-
props: Props,
220+
props: Props<any>,
221221
index: number,
222222
align: ScrollToAlign,
223223
scrollOffset: number,
@@ -260,19 +260,19 @@ const getOffsetForIndexAndAlignment = (
260260

261261
const VariableSizeGrid = createGridComponent({
262262
getColumnOffset: (
263-
props: Props,
263+
props: Props<any>,
264264
index: number,
265265
instanceProps: InstanceProps
266266
): number => getItemMetadata('column', props, index, instanceProps).offset,
267267

268268
getColumnStartIndexForOffset: (
269-
props: Props,
269+
props: Props<any>,
270270
scrollLeft: number,
271271
instanceProps: InstanceProps
272272
): number => findNearestItem('column', props, instanceProps, scrollLeft),
273273

274274
getColumnStopIndexForStartIndex: (
275-
props: Props,
275+
props: Props<any>,
276276
startIndex: number,
277277
scrollLeft: number,
278278
instanceProps: InstanceProps
@@ -299,7 +299,7 @@ const VariableSizeGrid = createGridComponent({
299299
},
300300

301301
getColumnWidth: (
302-
props: Props,
302+
props: Props<any>,
303303
index: number,
304304
instanceProps: InstanceProps
305305
): number => instanceProps.columnMetadataMap[index].size,
@@ -308,7 +308,7 @@ const VariableSizeGrid = createGridComponent({
308308
getEstimatedTotalWidth,
309309

310310
getOffsetForColumnAndAlignment: (
311-
props: Props,
311+
props: Props<any>,
312312
index: number,
313313
align: ScrollToAlign,
314314
scrollOffset: number,
@@ -324,7 +324,7 @@ const VariableSizeGrid = createGridComponent({
324324
),
325325

326326
getOffsetForRowAndAlignment: (
327-
props: Props,
327+
props: Props<any>,
328328
index: number,
329329
align: ScrollToAlign,
330330
scrollOffset: number,
@@ -340,25 +340,25 @@ const VariableSizeGrid = createGridComponent({
340340
),
341341

342342
getRowOffset: (
343-
props: Props,
343+
props: Props<any>,
344344
index: number,
345345
instanceProps: InstanceProps
346346
): number => getItemMetadata('row', props, index, instanceProps).offset,
347347

348348
getRowHeight: (
349-
props: Props,
349+
props: Props<any>,
350350
index: number,
351351
instanceProps: InstanceProps
352352
): number => instanceProps.rowMetadataMap[index].size,
353353

354354
getRowStartIndexForOffset: (
355-
props: Props,
355+
props: Props<any>,
356356
scrollTop: number,
357357
instanceProps: InstanceProps
358358
): number => findNearestItem('row', props, instanceProps, scrollTop),
359359

360360
getRowStopIndexForStartIndex: (
361-
props: Props,
361+
props: Props<any>,
362362
startIndex: number,
363363
scrollTop: number,
364364
instanceProps: InstanceProps
@@ -384,7 +384,7 @@ const VariableSizeGrid = createGridComponent({
384384
return stopIndex;
385385
},
386386

387-
initInstanceProps(props: Props, instance: any): InstanceProps {
387+
initInstanceProps(props: Props<any>, instance: any): InstanceProps {
388388
const {
389389
estimatedColumnWidth,
390390
estimatedRowHeight,
@@ -451,7 +451,7 @@ const VariableSizeGrid = createGridComponent({
451451

452452
shouldResetStyleCacheOnItemSizeChange: false,
453453

454-
validateProps: ({ columnWidth, rowHeight }: Props): void => {
454+
validateProps: ({ columnWidth, rowHeight }: Props<any>): void => {
455455
if (process.env.NODE_ENV !== 'production') {
456456
if (typeof columnWidth !== 'function') {
457457
throw Error(

0 commit comments

Comments
 (0)