1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 | var _typeof3 = require("@babel/runtime/helpers/typeof");
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.default = useCellRender;
|
9 | var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
10 | var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
11 | var _useMemo = _interopRequireDefault(require("rc-util/lib/hooks/useMemo"));
|
12 | var _isEqual = _interopRequireDefault(require("rc-util/lib/isEqual"));
|
13 | var _get = _interopRequireDefault(require("rc-util/lib/utils/get"));
|
14 | var _warning = _interopRequireDefault(require("rc-util/lib/warning"));
|
15 | var React = _interopRequireWildcard(require("react"));
|
16 | var _PerfContext = _interopRequireDefault(require("../context/PerfContext"));
|
17 | var _valueUtil = require("../utils/valueUtil");
|
18 | var _TableContext = require("../context/TableContext");
|
19 | function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
20 | function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
21 | function isRenderCell(data) {
|
22 | return data && (0, _typeof2.default)(data) === 'object' && !Array.isArray(data) && ! React.isValidElement(data);
|
23 | }
|
24 | function useCellRender(record, dataIndex, renderIndex, children, render, shouldCellUpdate) {
|
25 |
|
26 | var perfRecord = React.useContext(_PerfContext.default);
|
27 | var mark = (0, _TableContext.useImmutableMark)();
|
28 |
|
29 |
|
30 | var retData = (0, _useMemo.default)(function () {
|
31 | if ((0, _valueUtil.validateValue)(children)) {
|
32 | return [children];
|
33 | }
|
34 | var path = dataIndex === null || dataIndex === undefined || dataIndex === '' ? [] : Array.isArray(dataIndex) ? dataIndex : [dataIndex];
|
35 | var value = (0, _get.default)(record, path);
|
36 |
|
37 |
|
38 | var returnChildNode = value;
|
39 | var returnCellProps = undefined;
|
40 | if (render) {
|
41 | var renderData = render(value, record, renderIndex);
|
42 | if (isRenderCell(renderData)) {
|
43 | if (process.env.NODE_ENV !== 'production') {
|
44 | (0, _warning.default)(false, '`columns.render` return cell props is deprecated with perf issue, please use `onCell` instead.');
|
45 | }
|
46 | returnChildNode = renderData.children;
|
47 | returnCellProps = renderData.props;
|
48 | perfRecord.renderWithProps = true;
|
49 | } else {
|
50 | returnChildNode = renderData;
|
51 | }
|
52 | }
|
53 | return [returnChildNode, returnCellProps];
|
54 | }, [
|
55 |
|
56 | mark,
|
57 |
|
58 | record, children, dataIndex, render, renderIndex], function (prev, next) {
|
59 | if (shouldCellUpdate) {
|
60 | var _prev = (0, _slicedToArray2.default)(prev, 2),
|
61 | prevRecord = _prev[1];
|
62 | var _next = (0, _slicedToArray2.default)(next, 2),
|
63 | nextRecord = _next[1];
|
64 | return shouldCellUpdate(nextRecord, prevRecord);
|
65 | }
|
66 |
|
67 |
|
68 | if (perfRecord.renderWithProps) {
|
69 | return true;
|
70 | }
|
71 | return !(0, _isEqual.default)(prev, next, true);
|
72 | });
|
73 | return retData;
|
74 | } |
\ | No newline at end of file |