Skip to content

Commit 3cb68f5

Browse files
committed
perf: table rerender #1705
1 parent 2501ac3 commit 3cb68f5

File tree

10 files changed

+35
-27
lines changed

10 files changed

+35
-27
lines changed

build/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
devComponent: 'input',
2+
devComponent: 'table',
33
};

components/_util/props-util.js

+6
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ export function getEvents(child) {
197197
}
198198
return { ...events };
199199
}
200+
201+
// use getListeners instead this.$listeners
202+
// https://github.com/vueComponent/ant-design-vue/issues/1705
203+
export function getListeners(context) {
204+
return context.$vnode ? context.$vnode.componentOptions.listeners || {} : context.$listeners;
205+
}
200206
export function getClass(ele) {
201207
let data = {};
202208
if (ele.data) {

components/table/SelectionBox.jsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Checkbox from '../checkbox';
22
import Radio from '../radio';
33
import { SelectionBoxProps } from './interface';
44
import BaseMixin from '../_util/BaseMixin';
5-
import { getOptionProps } from '../_util/props-util';
5+
import { getOptionProps, getListeners } from '../_util/props-util';
66

77
export default {
88
name: 'SelectionBox',
@@ -48,14 +48,13 @@ export default {
4848

4949
render() {
5050
const { type, rowIndex, ...rest } = getOptionProps(this);
51-
const { checked, $attrs, $listeners } = this;
51+
const { checked } = this;
5252
const checkboxProps = {
5353
props: {
5454
checked,
5555
...rest,
5656
},
57-
attrs: $attrs,
58-
on: $listeners,
57+
on: getListeners(this),
5958
};
6059
if (type === 'radio') {
6160
checkboxProps.props.value = rowIndex;

components/table/Table.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
filterEmpty,
1818
getAllProps,
1919
getComponentFromProp,
20+
getListeners,
2021
} from '../_util/props-util';
2122
import BaseMixin from '../_util/BaseMixin';
2223
import { ConfigConsumerProps } from '../config-provider';
@@ -1117,7 +1118,7 @@ export default {
11171118
expandIconAsCell,
11181119
emptyText: !(loading.props && loading.props.spinning) && mergedLocale.emptyText,
11191120
},
1120-
on: this.$listeners,
1121+
on: getListeners(this),
11211122
class: classString,
11221123
};
11231124
return <VcTable {...vcTableProps} />;

components/table/createBodyRow.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import PropTypes from '../_util/vue-types';
22

33
import { Store } from './createStore';
4+
import { getListeners } from '../_util/props-util';
45

56
const BodyRowProps = {
67
store: Store,
@@ -48,7 +49,7 @@ export default function createTableRow(Component = 'tr') {
4849
};
4950

5051
return (
51-
<Component class={className} {...{ on: this.$listeners }}>
52+
<Component class={className} {...{ on: getListeners(this) }}>
5253
{this.$slots.default}
5354
</Component>
5455
);

components/table/index.jsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
getSlotOptions,
1010
camelize,
1111
getSlots,
12+
getListeners,
1213
} from '../_util/props-util';
1314
import Base from '../base';
1415

@@ -82,7 +83,7 @@ const Table = {
8283
},
8384
},
8485
render() {
85-
const { $listeners, $slots, normalize, $scopedSlots } = this;
86+
const { $slots, normalize, $scopedSlots } = this;
8687
const props = getOptionProps(this);
8788
const columns = props.columns ? this.updateColumns(props.columns) : normalize($slots.default);
8889
let { title, footer } = props;
@@ -101,7 +102,7 @@ const Table = {
101102
footer,
102103
expandedRowRender,
103104
},
104-
on: $listeners,
105+
on: getListeners(this),
105106
};
106107
return <T {...tProps} />;
107108
},

components/vc-table/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
getSlotOptions,
1212
camelize,
1313
getSlots,
14+
getListeners,
1415
} from '../_util/props-util';
1516
const Table = {
1617
name: 'Table',
@@ -52,15 +53,15 @@ const Table = {
5253
},
5354
},
5455
render() {
55-
const { $listeners, $slots, normalize } = this;
56+
const { $slots, normalize } = this;
5657
const props = getOptionProps(this);
5758
const columns = props.columns || normalize($slots.default);
5859
const tProps = {
5960
props: {
6061
...props,
6162
columns,
6263
},
63-
on: $listeners,
64+
on: getListeners(this),
6465
};
6566
return <T {...tProps} />;
6667
},

components/vc-table/src/BaseTable.jsx

+8-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ColGroup from './ColGroup';
44
import TableHeader from './TableHeader';
55
import TableRow from './TableRow';
66
import ExpandableRow from './ExpandableRow';
7-
import { mergeProps } from '../../_util/props-util';
7+
import { mergeProps, getListeners } from '../../_util/props-util';
88
import { connect } from '../../_util/store';
99
function noop() {}
1010
const BaseTable = {
@@ -49,16 +49,15 @@ const BaseTable = {
4949
prefixCls,
5050
childrenColumnName,
5151
rowClassName,
52-
// rowRef,
53-
$listeners: {
54-
rowClick: onRowClick = noop,
55-
rowDoubleclick: onRowDoubleClick = noop,
56-
rowContextmenu: onRowContextMenu = noop,
57-
rowMouseenter: onRowMouseEnter = noop,
58-
rowMouseleave: onRowMouseLeave = noop,
59-
},
6052
customRow = noop,
6153
} = this.table;
54+
const {
55+
rowClick: onRowClick = noop,
56+
rowDoubleclick: onRowDoubleClick = noop,
57+
rowContextmenu: onRowContextMenu = noop,
58+
rowMouseenter: onRowMouseEnter = noop,
59+
rowMouseleave: onRowMouseLeave = noop,
60+
} = getListeners(this.table);
6261
const { getRowKey, fixed, expander, isAnyColumnsFixed } = this;
6362

6463
const rows = [];

components/vc-table/src/ExpandableTable.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { connect } from '../../_util/store';
44
import shallowEqual from 'shallowequal';
55
import TableRow from './TableRow';
66
import { remove } from './utils';
7-
import { initDefaultProps, getOptionProps } from '../../_util/props-util';
7+
import { initDefaultProps, getOptionProps, getListeners } from '../../_util/props-util';
88

99
export const ExpandableTableProps = () => ({
1010
expandIconAsCell: PropTypes.bool,
@@ -227,15 +227,15 @@ const ExpandableTable = {
227227
},
228228

229229
render() {
230-
const { data, childrenColumnName, $scopedSlots, $listeners } = this;
230+
const { data, childrenColumnName, $scopedSlots } = this;
231231
const props = getOptionProps(this);
232232
const needIndentSpaced = data.some(record => record[childrenColumnName]);
233233

234234
return (
235235
$scopedSlots.default &&
236236
$scopedSlots.default({
237237
props,
238-
on: $listeners,
238+
on: getListeners(this),
239239
needIndentSpaced,
240240
renderRows: this.renderRows,
241241
handleExpandChange: this.handleExpandChange,

components/vc-table/src/Table.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import ColumnManager from './ColumnManager';
1010
import HeadTable from './HeadTable';
1111
import BodyTable from './BodyTable';
1212
import ExpandableTable from './ExpandableTable';
13-
import { initDefaultProps, getOptionProps } from '../../_util/props-util';
13+
import { initDefaultProps, getOptionProps, getListeners } from '../../_util/props-util';
1414
import BaseMixin from '../../_util/BaseMixin';
1515

1616
export default {
@@ -143,7 +143,7 @@ export default {
143143
['rowClick', 'rowDoubleclick', 'rowContextmenu', 'rowMouseenter', 'rowMouseleave'].forEach(
144144
name => {
145145
warningOnce(
146-
this.$listeners[name] === undefined,
146+
getListeners(this)[name] === undefined,
147147
`${name} is deprecated, please use customRow instead.`,
148148
);
149149
},
@@ -509,7 +509,7 @@ export default {
509509

510510
render() {
511511
const props = getOptionProps(this);
512-
const { $listeners, columnManager, getRowKey } = this;
512+
const { columnManager, getRowKey } = this;
513513
const prefixCls = props.prefixCls;
514514
let className = props.prefixCls;
515515
if (props.useFixedHeader || (props.scroll && props.scroll.y)) {
@@ -529,7 +529,7 @@ export default {
529529
columnManager,
530530
getRowKey,
531531
},
532-
on: { ...$listeners },
532+
on: getListeners(this),
533533
scopedSlots: {
534534
default: expander => {
535535
this.expander = expander;

0 commit comments

Comments
 (0)