Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make itemData generic in grids and lists #66

Merged
merged 1 commit into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
[lints]

[options]
include_warnings=true

[strict]
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ before_script:
- yarn
script:
- yarn lint
- yarn flow
- yarn flow:check
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

I prefer yarn flow since it's less to type and what I use in most of my other projects. 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run yarn flow often. The script with the same name overrides bin.

- yarn test
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"module": "dist/index.esm.js",
"files": ["dist", "src/*.js"],
"scripts": {
"flow": "flow check src && flow check website",
"flow:check": "flow check --max-warnings=0 src && flow check website",
"precommit": "lint-staged",
"prettier": "prettier --write '**/*.{js,json,css}'",
"linc": "lint-staged",
Expand Down
28 changes: 14 additions & 14 deletions src/FixedSizeGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ import createGridComponent from './createGridComponent';
import type { Props, ScrollToAlign } from './createGridComponent';

const FixedSizeGrid = createGridComponent({
getColumnOffset: ({ columnWidth }: Props, index: number): number =>
getColumnOffset: ({ columnWidth }: Props<any>, index: number): number =>
index * ((columnWidth: any): number),

getColumnWidth: ({ columnWidth }: Props, index: number): number =>
getColumnWidth: ({ columnWidth }: Props<any>, index: number): number =>
((columnWidth: any): number),

getRowOffset: ({ rowHeight }: Props, index: number): number =>
getRowOffset: ({ rowHeight }: Props<any>, index: number): number =>
index * ((rowHeight: any): number),

getRowHeight: ({ rowHeight }: Props, index: number): number =>
getRowHeight: ({ rowHeight }: Props<any>, index: number): number =>
((rowHeight: any): number),

getEstimatedTotalHeight: ({ rowCount, rowHeight }: Props) =>
getEstimatedTotalHeight: ({ rowCount, rowHeight }: Props<any>) =>
((rowHeight: any): number) * rowCount,

getEstimatedTotalWidth: ({ columnCount, columnWidth }: Props) =>
getEstimatedTotalWidth: ({ columnCount, columnWidth }: Props<any>) =>
((columnWidth: any): number) * columnCount,

getOffsetForColumnAndAlignment: (
{ columnCount, columnWidth, width }: Props,
{ columnCount, columnWidth, width }: Props<any>,
columnIndex: number,
align: ScrollToAlign,
scrollLeft: number
Expand Down Expand Up @@ -63,7 +63,7 @@ const FixedSizeGrid = createGridComponent({
},

getOffsetForRowAndAlignment: (
{ rowHeight, height, rowCount }: Props,
{ rowHeight, height, rowCount }: Props<any>,
rowIndex: number,
align: ScrollToAlign,
scrollTop: number
Expand Down Expand Up @@ -102,7 +102,7 @@ const FixedSizeGrid = createGridComponent({
},

getColumnStartIndexForOffset: (
{ columnWidth, columnCount }: Props,
{ columnWidth, columnCount }: Props<any>,
scrollLeft: number
): number =>
Math.max(
Expand All @@ -114,7 +114,7 @@ const FixedSizeGrid = createGridComponent({
),

getColumnStopIndexForStartIndex: (
{ columnWidth, columnCount, width }: Props,
{ columnWidth, columnCount, width }: Props<any>,
startIndex: number,
scrollLeft: number
): number => {
Expand All @@ -132,7 +132,7 @@ const FixedSizeGrid = createGridComponent({
},

getRowStartIndexForOffset: (
{ rowHeight, rowCount }: Props,
{ rowHeight, rowCount }: Props<any>,
scrollTop: number
): number =>
Math.max(
Expand All @@ -141,7 +141,7 @@ const FixedSizeGrid = createGridComponent({
),

getRowStopIndexForStartIndex: (
{ rowHeight, rowCount, height }: Props,
{ rowHeight, rowCount, height }: Props<any>,
startIndex: number,
scrollTop: number
): number => {
Expand All @@ -156,13 +156,13 @@ const FixedSizeGrid = createGridComponent({
);
},

initInstanceProps(props: Props): any {
initInstanceProps(props: Props<any>): any {
// Noop
},

shouldResetStyleCacheOnItemSizeChange: true,

validateProps: ({ columnWidth, rowHeight }: Props): void => {
validateProps: ({ columnWidth, rowHeight }: Props<any>): void => {
if (process.env.NODE_ENV !== 'production') {
if (typeof columnWidth !== 'number') {
throw Error(
Expand Down
16 changes: 8 additions & 8 deletions src/FixedSizeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import createListComponent from './createListComponent';
import type { Props, ScrollToAlign } from './createListComponent';

const FixedSizeList = createListComponent({
getItemOffset: ({ itemSize, size }: Props, index: number): number =>
getItemOffset: ({ itemSize, size }: Props<any>, index: number): number =>
index * ((itemSize: any): number),

getItemSize: ({ itemSize, size }: Props, index: number): number =>
getItemSize: ({ itemSize, size }: Props<any>, index: number): number =>
((itemSize: any): number),

getEstimatedTotalSize: ({ itemCount, itemSize }: Props) =>
getEstimatedTotalSize: ({ itemCount, itemSize }: Props<any>) =>
((itemSize: any): number) * itemCount,

getOffsetForIndexAndAlignment: (
{ direction, height, itemCount, itemSize, width }: Props,
{ direction, height, itemCount, itemSize, width }: Props<any>,
index: number,
align: ScrollToAlign,
scrollOffset: number
Expand Down Expand Up @@ -53,7 +53,7 @@ const FixedSizeList = createListComponent({
},

getStartIndexForOffset: (
{ itemCount, itemSize }: Props,
{ itemCount, itemSize }: Props<any>,
offset: number
): number =>
Math.max(
Expand All @@ -62,7 +62,7 @@ const FixedSizeList = createListComponent({
),

getStopIndexForStartIndex: (
{ direction, height, itemCount, itemSize, width }: Props,
{ direction, height, itemCount, itemSize, width }: Props<any>,
startIndex: number,
scrollOffset: number
): number => {
Expand All @@ -80,13 +80,13 @@ const FixedSizeList = createListComponent({
);
},

initInstanceProps(props: Props): any {
initInstanceProps(props: Props<any>): any {
// Noop
},

shouldResetStyleCacheOnItemSizeChange: true,

validateProps: ({ itemSize }: Props): void => {
validateProps: ({ itemSize }: Props<any>): void => {
if (process.env.NODE_ENV !== 'production') {
if (typeof itemSize !== 'number') {
throw Error(
Expand Down
40 changes: 20 additions & 20 deletions src/VariableSizeGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const DEFAULT_ESTIMATED_ITEM_SIZE = 50;
type VariableSizeProps = {|
estimatedColumnWidth: number,
estimatedRowHeight: number,
...Props,
...Props<any>,
|};

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

const getEstimatedTotalHeight = (
{ rowCount }: Props,
{ rowCount }: Props<any>,
{ rowMetadataMap, estimatedRowHeight, lastMeasuredRowIndex }: InstanceProps
) => {
let totalSizeOfMeasuredRows = 0;
Expand All @@ -47,7 +47,7 @@ const getEstimatedTotalHeight = (
};

const getEstimatedTotalWidth = (
{ columnCount }: Props,
{ columnCount }: Props<any>,
{
columnMetadataMap,
estimatedColumnWidth,
Expand All @@ -69,7 +69,7 @@ const getEstimatedTotalWidth = (

const getItemMetadata = (
itemType: ItemType,
props: Props,
props: Props<any>,
index: number,
instanceProps: InstanceProps
): ItemMetadata => {
Expand Down Expand Up @@ -114,7 +114,7 @@ const getItemMetadata = (

const findNearestItem = (
itemType: ItemType,
props: Props,
props: Props<any>,
instanceProps: InstanceProps,
offset: number
) => {
Expand Down Expand Up @@ -156,7 +156,7 @@ const findNearestItem = (

const findNearestItemBinarySearch = (
itemType: ItemType,
props: Props,
props: Props<any>,
instanceProps: InstanceProps,
high: number,
low: number,
Expand Down Expand Up @@ -189,7 +189,7 @@ const findNearestItemBinarySearch = (

const findNearestItemExponentialSearch = (
itemType: ItemType,
props: Props,
props: Props<any>,
instanceProps: InstanceProps,
index: number,
offset: number
Expand Down Expand Up @@ -217,7 +217,7 @@ const findNearestItemExponentialSearch = (

const getOffsetForIndexAndAlignment = (
itemType: ItemType,
props: Props,
props: Props<any>,
index: number,
align: ScrollToAlign,
scrollOffset: number,
Expand Down Expand Up @@ -260,19 +260,19 @@ const getOffsetForIndexAndAlignment = (

const VariableSizeGrid = createGridComponent({
getColumnOffset: (
props: Props,
props: Props<any>,
index: number,
instanceProps: InstanceProps
): number => getItemMetadata('column', props, index, instanceProps).offset,

getColumnStartIndexForOffset: (
props: Props,
props: Props<any>,
scrollLeft: number,
instanceProps: InstanceProps
): number => findNearestItem('column', props, instanceProps, scrollLeft),

getColumnStopIndexForStartIndex: (
props: Props,
props: Props<any>,
startIndex: number,
scrollLeft: number,
instanceProps: InstanceProps
Expand All @@ -299,7 +299,7 @@ const VariableSizeGrid = createGridComponent({
},

getColumnWidth: (
props: Props,
props: Props<any>,
index: number,
instanceProps: InstanceProps
): number => instanceProps.columnMetadataMap[index].size,
Expand All @@ -308,7 +308,7 @@ const VariableSizeGrid = createGridComponent({
getEstimatedTotalWidth,

getOffsetForColumnAndAlignment: (
props: Props,
props: Props<any>,
index: number,
align: ScrollToAlign,
scrollOffset: number,
Expand All @@ -324,7 +324,7 @@ const VariableSizeGrid = createGridComponent({
),

getOffsetForRowAndAlignment: (
props: Props,
props: Props<any>,
index: number,
align: ScrollToAlign,
scrollOffset: number,
Expand All @@ -340,25 +340,25 @@ const VariableSizeGrid = createGridComponent({
),

getRowOffset: (
props: Props,
props: Props<any>,
index: number,
instanceProps: InstanceProps
): number => getItemMetadata('row', props, index, instanceProps).offset,

getRowHeight: (
props: Props,
props: Props<any>,
index: number,
instanceProps: InstanceProps
): number => instanceProps.rowMetadataMap[index].size,

getRowStartIndexForOffset: (
props: Props,
props: Props<any>,
scrollTop: number,
instanceProps: InstanceProps
): number => findNearestItem('row', props, instanceProps, scrollTop),

getRowStopIndexForStartIndex: (
props: Props,
props: Props<any>,
startIndex: number,
scrollTop: number,
instanceProps: InstanceProps
Expand All @@ -384,7 +384,7 @@ const VariableSizeGrid = createGridComponent({
return stopIndex;
},

initInstanceProps(props: Props, instance: any): InstanceProps {
initInstanceProps(props: Props<any>, instance: any): InstanceProps {
const {
estimatedColumnWidth,
estimatedRowHeight,
Expand Down Expand Up @@ -451,7 +451,7 @@ const VariableSizeGrid = createGridComponent({

shouldResetStyleCacheOnItemSizeChange: false,

validateProps: ({ columnWidth, rowHeight }: Props): void => {
validateProps: ({ columnWidth, rowHeight }: Props<any>): void => {
if (process.env.NODE_ENV !== 'production') {
if (typeof columnWidth !== 'function') {
throw Error(
Expand Down
Loading