UNPKG

react-virtualized

Version:

React components for efficiently rendering large, scrollable lists and tabular data

97 lines (84 loc) 3.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Default CellMeasurer `cellSizeCache` implementation. * Permanently caches all cell sizes (identified by column and row index) unless explicitly cleared. * Can be configured to handle uniform cell widths and/or heights as a way of optimizing certain use cases. */ var CellSizeCache = function () { function CellSizeCache() { var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; var _ref$uniformRowHeight = _ref.uniformRowHeight; var uniformRowHeight = _ref$uniformRowHeight === undefined ? false : _ref$uniformRowHeight; var _ref$uniformColumnWid = _ref.uniformColumnWidth; var uniformColumnWidth = _ref$uniformColumnWid === undefined ? false : _ref$uniformColumnWid; _classCallCheck(this, CellSizeCache); this._uniformRowHeight = uniformRowHeight; this._uniformColumnWidth = uniformColumnWidth; this._cachedColumnWidths = {}; this._cachedRowHeights = {}; } _createClass(CellSizeCache, [{ key: "clearAllColumnWidths", value: function clearAllColumnWidths() { this._cachedColumnWidth = undefined; this._cachedColumnWidths = {}; } }, { key: "clearAllRowHeights", value: function clearAllRowHeights() { this._cachedRowHeight = undefined; this._cachedRowHeights = {}; } }, { key: "clearColumnWidth", value: function clearColumnWidth(index) { this._cachedColumnWidth = undefined; delete this._cachedColumnWidths[index]; } }, { key: "clearRowHeight", value: function clearRowHeight(index) { this._cachedRowHeight = undefined; delete this._cachedRowHeights[index]; } }, { key: "getColumnWidth", value: function getColumnWidth(index) { return this._uniformColumnWidth ? this._cachedColumnWidth : this._cachedColumnWidths[index]; } }, { key: "getRowHeight", value: function getRowHeight(index) { return this._uniformRowHeight ? this._cachedRowHeight : this._cachedRowHeights[index]; } }, { key: "hasColumnWidth", value: function hasColumnWidth(index) { return this._uniformColumnWidth ? !!this._cachedColumnWidth : !!this._cachedColumnWidths[index]; } }, { key: "hasRowHeight", value: function hasRowHeight(index) { return this._uniformRowHeight ? !!this._cachedRowHeight : !!this._cachedRowHeights[index]; } }, { key: "setColumnWidth", value: function setColumnWidth(index, width) { this._cachedColumnWidth = width; this._cachedColumnWidths[index] = width; } }, { key: "setRowHeight", value: function setRowHeight(index, height) { this._cachedRowHeight = height; this._cachedRowHeights[index] = height; } }]); return CellSizeCache; }(); exports.default = CellSizeCache;