| 31 | * Caches measurements for a given cell. |
| 32 | */ |
| 33 | export default class CellMeasurerCache implements CellMeasureCache { |
| 34 | _cellHeightCache: Cache = {}; |
| 35 | _cellWidthCache: Cache = {}; |
| 36 | _columnWidthCache: Cache = {}; |
| 37 | _rowHeightCache: Cache = {}; |
| 38 | _defaultHeight: number; |
| 39 | _defaultWidth: number; |
| 40 | _minHeight: number; |
| 41 | _minWidth: number; |
| 42 | _keyMapper: KeyMapper; |
| 43 | _hasFixedHeight: boolean; |
| 44 | _hasFixedWidth: boolean; |
| 45 | _columnCount = 0; |
| 46 | _rowCount = 0; |
| 47 | |
| 48 | constructor(params: CellMeasurerCacheParams = {}) { |
| 49 | const { |
| 50 | defaultHeight, |
| 51 | defaultWidth, |
| 52 | fixedHeight, |
| 53 | fixedWidth, |
| 54 | keyMapper, |
| 55 | minHeight, |
| 56 | minWidth, |
| 57 | } = params; |
| 58 | |
| 59 | this._hasFixedHeight = fixedHeight === true; |
| 60 | this._hasFixedWidth = fixedWidth === true; |
| 61 | this._minHeight = minHeight || 0; |
| 62 | this._minWidth = minWidth || 0; |
| 63 | this._keyMapper = keyMapper || defaultKeyMapper; |
| 64 | |
| 65 | this._defaultHeight = Math.max( |
| 66 | this._minHeight, |
| 67 | typeof defaultHeight === 'number' ? defaultHeight : DEFAULT_HEIGHT, |
| 68 | ); |
| 69 | this._defaultWidth = Math.max( |
| 70 | this._minWidth, |
| 71 | typeof defaultWidth === 'number' ? defaultWidth : DEFAULT_WIDTH, |
| 72 | ); |
| 73 | |
| 74 | if (process.env.NODE_ENV !== 'production') { |
| 75 | if (this._hasFixedHeight === false && this._hasFixedWidth === false) { |
| 76 | console.warn( |
| 77 | "CellMeasurerCache should only measure a cell's width or height. " + |
| 78 | 'You have configured CellMeasurerCache to measure both. ' + |
| 79 | 'This will result in poor performance.', |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | if (this._hasFixedHeight === false && this._defaultHeight === 0) { |
| 84 | console.warn( |
| 85 | 'Fixed height CellMeasurerCache should specify a :defaultHeight greater than 0. ' + |
| 86 | 'Failing to do so will lead to unnecessary layout and poor performance.', |
| 87 | ); |
| 88 | } |
| 89 | |
| 90 | if (this._hasFixedWidth === false && this._defaultWidth === 0) { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…