Skip to content

Commit

Permalink
perf: table rerender #1705
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed Jan 18, 2020
1 parent 2501ac3 commit 3cb68f5
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion build/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
devComponent: 'input',
devComponent: 'table',
};
6 changes: 6 additions & 0 deletions components/_util/props-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ export function getEvents(child) {
}
return { ...events };
}

// use getListeners instead this.$listeners
// https://github.com/vueComponent/ant-design-vue/issues/1705
export function getListeners(context) {
return context.$vnode ? context.$vnode.componentOptions.listeners || {} : context.$listeners;
}
export function getClass(ele) {
let data = {};
if (ele.data) {
Expand Down
7 changes: 3 additions & 4 deletions components/table/SelectionBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Checkbox from '../checkbox';
import Radio from '../radio';
import { SelectionBoxProps } from './interface';
import BaseMixin from '../_util/BaseMixin';
import { getOptionProps } from '../_util/props-util';
import { getOptionProps, getListeners } from '../_util/props-util';

export default {
name: 'SelectionBox',
Expand Down Expand Up @@ -48,14 +48,13 @@ export default {

render() {
const { type, rowIndex, ...rest } = getOptionProps(this);
const { checked, $attrs, $listeners } = this;
const { checked } = this;
const checkboxProps = {
props: {
checked,
...rest,
},
attrs: $attrs,
on: $listeners,
on: getListeners(this),
};
if (type === 'radio') {
checkboxProps.props.value = rowIndex;
Expand Down
3 changes: 2 additions & 1 deletion components/table/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
filterEmpty,
getAllProps,
getComponentFromProp,
getListeners,
} from '../_util/props-util';
import BaseMixin from '../_util/BaseMixin';
import { ConfigConsumerProps } from '../config-provider';
Expand Down Expand Up @@ -1117,7 +1118,7 @@ export default {
expandIconAsCell,
emptyText: !(loading.props && loading.props.spinning) && mergedLocale.emptyText,
},
on: this.$listeners,
on: getListeners(this),
class: classString,
};
return <VcTable {...vcTableProps} />;
Expand Down
3 changes: 2 additions & 1 deletion components/table/createBodyRow.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PropTypes from '../_util/vue-types';

import { Store } from './createStore';
import { getListeners } from '../_util/props-util';

const BodyRowProps = {
store: Store,
Expand Down Expand Up @@ -48,7 +49,7 @@ export default function createTableRow(Component = 'tr') {
};

return (
<Component class={className} {...{ on: this.$listeners }}>
<Component class={className} {...{ on: getListeners(this) }}>
{this.$slots.default}
</Component>
);
Expand Down
5 changes: 3 additions & 2 deletions components/table/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getSlotOptions,
camelize,
getSlots,
getListeners,
} from '../_util/props-util';
import Base from '../base';

Expand Down Expand Up @@ -82,7 +83,7 @@ const Table = {
},
},
render() {
const { $listeners, $slots, normalize, $scopedSlots } = this;
const { $slots, normalize, $scopedSlots } = this;
const props = getOptionProps(this);
const columns = props.columns ? this.updateColumns(props.columns) : normalize($slots.default);
let { title, footer } = props;
Expand All @@ -101,7 +102,7 @@ const Table = {
footer,
expandedRowRender,
},
on: $listeners,
on: getListeners(this),
};
return <T {...tProps} />;
},
Expand Down
5 changes: 3 additions & 2 deletions components/vc-table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getSlotOptions,
camelize,
getSlots,
getListeners,
} from '../_util/props-util';
const Table = {
name: 'Table',
Expand Down Expand Up @@ -52,15 +53,15 @@ const Table = {
},
},
render() {
const { $listeners, $slots, normalize } = this;
const { $slots, normalize } = this;
const props = getOptionProps(this);
const columns = props.columns || normalize($slots.default);
const tProps = {
props: {
...props,
columns,
},
on: $listeners,
on: getListeners(this),
};
return <T {...tProps} />;
},
Expand Down
17 changes: 8 additions & 9 deletions components/vc-table/src/BaseTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ColGroup from './ColGroup';
import TableHeader from './TableHeader';
import TableRow from './TableRow';
import ExpandableRow from './ExpandableRow';
import { mergeProps } from '../../_util/props-util';
import { mergeProps, getListeners } from '../../_util/props-util';
import { connect } from '../../_util/store';
function noop() {}
const BaseTable = {
Expand Down Expand Up @@ -49,16 +49,15 @@ const BaseTable = {
prefixCls,
childrenColumnName,
rowClassName,
// rowRef,
$listeners: {
rowClick: onRowClick = noop,
rowDoubleclick: onRowDoubleClick = noop,
rowContextmenu: onRowContextMenu = noop,
rowMouseenter: onRowMouseEnter = noop,
rowMouseleave: onRowMouseLeave = noop,
},
customRow = noop,
} = this.table;
const {
rowClick: onRowClick = noop,
rowDoubleclick: onRowDoubleClick = noop,
rowContextmenu: onRowContextMenu = noop,
rowMouseenter: onRowMouseEnter = noop,
rowMouseleave: onRowMouseLeave = noop,
} = getListeners(this.table);
const { getRowKey, fixed, expander, isAnyColumnsFixed } = this;

const rows = [];
Expand Down
6 changes: 3 additions & 3 deletions components/vc-table/src/ExpandableTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { connect } from '../../_util/store';
import shallowEqual from 'shallowequal';
import TableRow from './TableRow';
import { remove } from './utils';
import { initDefaultProps, getOptionProps } from '../../_util/props-util';
import { initDefaultProps, getOptionProps, getListeners } from '../../_util/props-util';

export const ExpandableTableProps = () => ({
expandIconAsCell: PropTypes.bool,
Expand Down Expand Up @@ -227,15 +227,15 @@ const ExpandableTable = {
},

render() {
const { data, childrenColumnName, $scopedSlots, $listeners } = this;
const { data, childrenColumnName, $scopedSlots } = this;
const props = getOptionProps(this);
const needIndentSpaced = data.some(record => record[childrenColumnName]);

return (
$scopedSlots.default &&
$scopedSlots.default({
props,
on: $listeners,
on: getListeners(this),
needIndentSpaced,
renderRows: this.renderRows,
handleExpandChange: this.handleExpandChange,
Expand Down
8 changes: 4 additions & 4 deletions components/vc-table/src/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ColumnManager from './ColumnManager';
import HeadTable from './HeadTable';
import BodyTable from './BodyTable';
import ExpandableTable from './ExpandableTable';
import { initDefaultProps, getOptionProps } from '../../_util/props-util';
import { initDefaultProps, getOptionProps, getListeners } from '../../_util/props-util';
import BaseMixin from '../../_util/BaseMixin';

export default {
Expand Down Expand Up @@ -143,7 +143,7 @@ export default {
['rowClick', 'rowDoubleclick', 'rowContextmenu', 'rowMouseenter', 'rowMouseleave'].forEach(
name => {
warningOnce(
this.$listeners[name] === undefined,
getListeners(this)[name] === undefined,
`${name} is deprecated, please use customRow instead.`,
);
},
Expand Down Expand Up @@ -509,7 +509,7 @@ export default {

render() {
const props = getOptionProps(this);
const { $listeners, columnManager, getRowKey } = this;
const { columnManager, getRowKey } = this;
const prefixCls = props.prefixCls;
let className = props.prefixCls;
if (props.useFixedHeader || (props.scroll && props.scroll.y)) {
Expand All @@ -529,7 +529,7 @@ export default {
columnManager,
getRowKey,
},
on: { ...$listeners },
on: getListeners(this),
scopedSlots: {
default: expander => {
this.expander = expander;
Expand Down

0 comments on commit 3cb68f5

Please sign in to comment.