UNPKG

4.09 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _isEqual2 = require('lodash/isEqual');
8
9var _isEqual3 = _interopRequireDefault(_isEqual2);
10
11var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
12
13var _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; }; }();
14
15var _react = require('react');
16
17var _react2 = _interopRequireDefault(_react);
18
19var _reactabularTable = require('reactabular-table');
20
21var _types = require('./types');
22
23function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
25function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
26
27function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
28
29function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
30
31var BodyRow = function (_React$Component) {
32 _inherits(BodyRow, _React$Component);
33
34 function BodyRow(props) {
35 _classCallCheck(this, BodyRow);
36
37 var _this = _possibleConstructorReturn(this, (BodyRow.__proto__ || Object.getPrototypeOf(BodyRow)).call(this, props));
38
39 _this.ref = null;
40
41 _this.updateHeight = _this.updateHeight.bind(_this);
42 return _this;
43 }
44
45 _createClass(BodyRow, [{
46 key: 'componentDidMount',
47 value: function componentDidMount() {
48 this.updateHeight();
49 }
50 }, {
51 key: 'componentDidUpdate',
52 value: function componentDidUpdate() {
53 // Capture height data only during initial measurement for performance.
54 // This loses some accuracy if row height changes, but it's good enough
55 // for most purposes.
56 if (this.context.initialMeasurement) {
57 this.updateHeight();
58 }
59 }
60 }, {
61 key: 'render',
62 value: function render() {
63 var _this2 = this;
64
65 return _react2.default.createElement('tr', _extends({}, this.props, {
66 ref: function ref(e) {
67 if (e) {
68 _this2.ref = e;
69 }
70 }
71 }));
72 }
73 }, {
74 key: 'updateHeight',
75 value: function updateHeight() {
76 this.context.updateHeight(this.props['data-rowkey'], this.ref.offsetHeight);
77 }
78 }]);
79
80 return BodyRow;
81}(_react2.default.Component);
82
83BodyRow.contextTypes = _types.bodyRowContextTypes;
84process.env.NODE_ENV !== "production" ? BodyRow.propTypes = _types.bodyRowTypes : void 0;
85
86BodyRow.shouldComponentUpdate = function (nextProps) {
87 var previousProps = this.props;
88
89 // Update only if a row has not been measured and either
90 // columns or rowData hasn't changed
91 if (nextProps.rowData._measured) {
92 return !((0, _reactabularTable.columnsAreEqual)(previousProps.columns, nextProps.columns) && (0, _isEqual3.default)(previousProps.rowData, nextProps.rowData));
93 }
94
95 return true;
96};
97
98exports.default = BodyRow;
\No newline at end of file