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

Extracted CellMeasurer public interface #1058

Merged
merged 5 commits into from
Apr 7, 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
2 changes: 1 addition & 1 deletion .babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (env === 'commonjs' || env === 'es') {
],
plugins: [
'transform-runtime',
['flow-react-proptypes', {deadCode: true}],
['flow-react-proptypes', {deadCode: true, useESModules: true}],
['transform-react-remove-prop-types', {mode: 'wrap'}],
],
presets: [['env', {modules: false}], 'react', 'flow', 'stage-2'],
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"jsnext:main": "dist/es/index.js",
"license": "MIT",
"scripts": {
"build:types": "flow-copy-source --ignore \"**/*.{jest,e2e,ssr,example}.js\" source/WindowScroller dist/es/WindowScroller && flow-copy-source --ignore \"**/*.{jest,e2e,ssr,example}.js\" source/AutoSizer dist/es/AutoSizer ",
"build:types": "flow-copy-source --ignore \"**/*.{jest,e2e,ssr,example}.js\" source/WindowScroller dist/es/WindowScroller && flow-copy-source --ignore \"**/*.{jest,e2e,ssr,example}.js\" source/AutoSizer dist/es/AutoSizer",
"build": "npm run build:commonjs && npm run build:css && npm run build:es && npm run build:demo && npm run build:umd",
"build:commonjs": "npm run clean:commonjs && cross-env NODE_ENV=commonjs babel source --out-dir dist/commonjs",
"build:css": "postcss source/styles.css -o styles.css --use autoprefixer",
Expand Down Expand Up @@ -102,7 +102,7 @@
"babel-eslint": "^8.1.2",
"babel-jest": "^22.0.4",
"babel-loader": "7.1.2",
"babel-plugin-flow-react-proptypes": "^13.0.0",
"babel-plugin-flow-react-proptypes": "^21.0.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.12",
"babel-plugin-transform-runtime": "^6.23.0",
Expand Down
4 changes: 2 additions & 2 deletions source/CellMeasurer/CellMeasurer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @flow */
import * as React from 'react';
import {findDOMNode} from 'react-dom';
import CellMeasurerCache from './CellMeasurerCache.js';
import type {CellMeasureCache} from './types';

type Children = (params: {measure: () => void}) => React.Element<*>;

Expand All @@ -11,7 +11,7 @@ type Cell = {
};

type Props = {
cache: CellMeasurerCache,
cache: CellMeasureCache,
children: Children | React.Element<*>,
columnIndex?: number,
index?: number,
Expand Down
11 changes: 9 additions & 2 deletions source/CellMeasurer/CellMeasurerCache.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/** @flow */

import type {CellMeasureCache} from './types';

export const DEFAULT_HEIGHT = 30;
export const DEFAULT_WIDTH = 100;

Expand Down Expand Up @@ -28,7 +30,7 @@ type IndexParam = {
/**
* Caches measurements for a given cell.
*/
export default class CellMeasurerCache {
export default class CellMeasurerCache implements CellMeasureCache {
_cellHeightCache: Cache = {};
_cellWidthCache: Cache = {};
_columnWidthCache: Cache = {};
Expand Down Expand Up @@ -174,7 +176,12 @@ export default class CellMeasurerCache {
: this._defaultHeight;
};

set(rowIndex: number, columnIndex: number, width: number, height: number) {
set(
rowIndex: number,
columnIndex: number,
width: number,
height: number,
): void {
const key = this._keyMapper(rowIndex, columnIndex);

if (columnIndex >= this._columnCount) {
Expand Down
15 changes: 15 additions & 0 deletions source/CellMeasurer/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @flow

export interface CellMeasureCache {
hasFixedWidth(): boolean;
hasFixedHeight(): boolean;
has(rowIndex: number, columnIndex: number): boolean;
set(
rowIndex: number,
columnIndex: number,
width: number,
height: number,
): void;
getHeight(rowIndex: number, columnIndex?: number): number;
getWidth(rowIndex: number, columnIndex?: number): number;
}
Loading