perf: table rerender #1705
parent
2501ac3a0e
commit
3cb68f5ec6
|
@ -1,3 +1,3 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
devComponent: 'input',
|
devComponent: 'table',
|
||||||
};
|
};
|
||||||
|
|
|
@ -197,6 +197,12 @@ export function getEvents(child) {
|
||||||
}
|
}
|
||||||
return { ...events };
|
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) {
|
export function getClass(ele) {
|
||||||
let data = {};
|
let data = {};
|
||||||
if (ele.data) {
|
if (ele.data) {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import Checkbox from '../checkbox';
|
||||||
import Radio from '../radio';
|
import Radio from '../radio';
|
||||||
import { SelectionBoxProps } from './interface';
|
import { SelectionBoxProps } from './interface';
|
||||||
import BaseMixin from '../_util/BaseMixin';
|
import BaseMixin from '../_util/BaseMixin';
|
||||||
import { getOptionProps } from '../_util/props-util';
|
import { getOptionProps, getListeners } from '../_util/props-util';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'SelectionBox',
|
name: 'SelectionBox',
|
||||||
|
@ -48,14 +48,13 @@ export default {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { type, rowIndex, ...rest } = getOptionProps(this);
|
const { type, rowIndex, ...rest } = getOptionProps(this);
|
||||||
const { checked, $attrs, $listeners } = this;
|
const { checked } = this;
|
||||||
const checkboxProps = {
|
const checkboxProps = {
|
||||||
props: {
|
props: {
|
||||||
checked,
|
checked,
|
||||||
...rest,
|
...rest,
|
||||||
},
|
},
|
||||||
attrs: $attrs,
|
on: getListeners(this),
|
||||||
on: $listeners,
|
|
||||||
};
|
};
|
||||||
if (type === 'radio') {
|
if (type === 'radio') {
|
||||||
checkboxProps.props.value = rowIndex;
|
checkboxProps.props.value = rowIndex;
|
||||||
|
|
|
@ -17,6 +17,7 @@ import {
|
||||||
filterEmpty,
|
filterEmpty,
|
||||||
getAllProps,
|
getAllProps,
|
||||||
getComponentFromProp,
|
getComponentFromProp,
|
||||||
|
getListeners,
|
||||||
} from '../_util/props-util';
|
} from '../_util/props-util';
|
||||||
import BaseMixin from '../_util/BaseMixin';
|
import BaseMixin from '../_util/BaseMixin';
|
||||||
import { ConfigConsumerProps } from '../config-provider';
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
|
@ -1117,7 +1118,7 @@ export default {
|
||||||
expandIconAsCell,
|
expandIconAsCell,
|
||||||
emptyText: !(loading.props && loading.props.spinning) && mergedLocale.emptyText,
|
emptyText: !(loading.props && loading.props.spinning) && mergedLocale.emptyText,
|
||||||
},
|
},
|
||||||
on: this.$listeners,
|
on: getListeners(this),
|
||||||
class: classString,
|
class: classString,
|
||||||
};
|
};
|
||||||
return <VcTable {...vcTableProps} />;
|
return <VcTable {...vcTableProps} />;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
|
|
||||||
import { Store } from './createStore';
|
import { Store } from './createStore';
|
||||||
|
import { getListeners } from '../_util/props-util';
|
||||||
|
|
||||||
const BodyRowProps = {
|
const BodyRowProps = {
|
||||||
store: Store,
|
store: Store,
|
||||||
|
@ -48,7 +49,7 @@ export default function createTableRow(Component = 'tr') {
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Component class={className} {...{ on: this.$listeners }}>
|
<Component class={className} {...{ on: getListeners(this) }}>
|
||||||
{this.$slots.default}
|
{this.$slots.default}
|
||||||
</Component>
|
</Component>
|
||||||
);
|
);
|
||||||
|
|
|
@ -9,6 +9,7 @@ import {
|
||||||
getSlotOptions,
|
getSlotOptions,
|
||||||
camelize,
|
camelize,
|
||||||
getSlots,
|
getSlots,
|
||||||
|
getListeners,
|
||||||
} from '../_util/props-util';
|
} from '../_util/props-util';
|
||||||
import Base from '../base';
|
import Base from '../base';
|
||||||
|
|
||||||
|
@ -82,7 +83,7 @@ const Table = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
const { $listeners, $slots, normalize, $scopedSlots } = this;
|
const { $slots, normalize, $scopedSlots } = this;
|
||||||
const props = getOptionProps(this);
|
const props = getOptionProps(this);
|
||||||
const columns = props.columns ? this.updateColumns(props.columns) : normalize($slots.default);
|
const columns = props.columns ? this.updateColumns(props.columns) : normalize($slots.default);
|
||||||
let { title, footer } = props;
|
let { title, footer } = props;
|
||||||
|
@ -101,7 +102,7 @@ const Table = {
|
||||||
footer,
|
footer,
|
||||||
expandedRowRender,
|
expandedRowRender,
|
||||||
},
|
},
|
||||||
on: $listeners,
|
on: getListeners(this),
|
||||||
};
|
};
|
||||||
return <T {...tProps} />;
|
return <T {...tProps} />;
|
||||||
},
|
},
|
||||||
|
|
|
@ -11,6 +11,7 @@ import {
|
||||||
getSlotOptions,
|
getSlotOptions,
|
||||||
camelize,
|
camelize,
|
||||||
getSlots,
|
getSlots,
|
||||||
|
getListeners,
|
||||||
} from '../_util/props-util';
|
} from '../_util/props-util';
|
||||||
const Table = {
|
const Table = {
|
||||||
name: 'Table',
|
name: 'Table',
|
||||||
|
@ -52,7 +53,7 @@ const Table = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
const { $listeners, $slots, normalize } = this;
|
const { $slots, normalize } = this;
|
||||||
const props = getOptionProps(this);
|
const props = getOptionProps(this);
|
||||||
const columns = props.columns || normalize($slots.default);
|
const columns = props.columns || normalize($slots.default);
|
||||||
const tProps = {
|
const tProps = {
|
||||||
|
@ -60,7 +61,7 @@ const Table = {
|
||||||
...props,
|
...props,
|
||||||
columns,
|
columns,
|
||||||
},
|
},
|
||||||
on: $listeners,
|
on: getListeners(this),
|
||||||
};
|
};
|
||||||
return <T {...tProps} />;
|
return <T {...tProps} />;
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,7 +4,7 @@ import ColGroup from './ColGroup';
|
||||||
import TableHeader from './TableHeader';
|
import TableHeader from './TableHeader';
|
||||||
import TableRow from './TableRow';
|
import TableRow from './TableRow';
|
||||||
import ExpandableRow from './ExpandableRow';
|
import ExpandableRow from './ExpandableRow';
|
||||||
import { mergeProps } from '../../_util/props-util';
|
import { mergeProps, getListeners } from '../../_util/props-util';
|
||||||
import { connect } from '../../_util/store';
|
import { connect } from '../../_util/store';
|
||||||
function noop() {}
|
function noop() {}
|
||||||
const BaseTable = {
|
const BaseTable = {
|
||||||
|
@ -49,16 +49,15 @@ const BaseTable = {
|
||||||
prefixCls,
|
prefixCls,
|
||||||
childrenColumnName,
|
childrenColumnName,
|
||||||
rowClassName,
|
rowClassName,
|
||||||
// rowRef,
|
customRow = noop,
|
||||||
$listeners: {
|
} = this.table;
|
||||||
|
const {
|
||||||
rowClick: onRowClick = noop,
|
rowClick: onRowClick = noop,
|
||||||
rowDoubleclick: onRowDoubleClick = noop,
|
rowDoubleclick: onRowDoubleClick = noop,
|
||||||
rowContextmenu: onRowContextMenu = noop,
|
rowContextmenu: onRowContextMenu = noop,
|
||||||
rowMouseenter: onRowMouseEnter = noop,
|
rowMouseenter: onRowMouseEnter = noop,
|
||||||
rowMouseleave: onRowMouseLeave = noop,
|
rowMouseleave: onRowMouseLeave = noop,
|
||||||
},
|
} = getListeners(this.table);
|
||||||
customRow = noop,
|
|
||||||
} = this.table;
|
|
||||||
const { getRowKey, fixed, expander, isAnyColumnsFixed } = this;
|
const { getRowKey, fixed, expander, isAnyColumnsFixed } = this;
|
||||||
|
|
||||||
const rows = [];
|
const rows = [];
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { connect } from '../../_util/store';
|
||||||
import shallowEqual from 'shallowequal';
|
import shallowEqual from 'shallowequal';
|
||||||
import TableRow from './TableRow';
|
import TableRow from './TableRow';
|
||||||
import { remove } from './utils';
|
import { remove } from './utils';
|
||||||
import { initDefaultProps, getOptionProps } from '../../_util/props-util';
|
import { initDefaultProps, getOptionProps, getListeners } from '../../_util/props-util';
|
||||||
|
|
||||||
export const ExpandableTableProps = () => ({
|
export const ExpandableTableProps = () => ({
|
||||||
expandIconAsCell: PropTypes.bool,
|
expandIconAsCell: PropTypes.bool,
|
||||||
|
@ -227,7 +227,7 @@ const ExpandableTable = {
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { data, childrenColumnName, $scopedSlots, $listeners } = this;
|
const { data, childrenColumnName, $scopedSlots } = this;
|
||||||
const props = getOptionProps(this);
|
const props = getOptionProps(this);
|
||||||
const needIndentSpaced = data.some(record => record[childrenColumnName]);
|
const needIndentSpaced = data.some(record => record[childrenColumnName]);
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ const ExpandableTable = {
|
||||||
$scopedSlots.default &&
|
$scopedSlots.default &&
|
||||||
$scopedSlots.default({
|
$scopedSlots.default({
|
||||||
props,
|
props,
|
||||||
on: $listeners,
|
on: getListeners(this),
|
||||||
needIndentSpaced,
|
needIndentSpaced,
|
||||||
renderRows: this.renderRows,
|
renderRows: this.renderRows,
|
||||||
handleExpandChange: this.handleExpandChange,
|
handleExpandChange: this.handleExpandChange,
|
||||||
|
|
|
@ -10,7 +10,7 @@ import ColumnManager from './ColumnManager';
|
||||||
import HeadTable from './HeadTable';
|
import HeadTable from './HeadTable';
|
||||||
import BodyTable from './BodyTable';
|
import BodyTable from './BodyTable';
|
||||||
import ExpandableTable from './ExpandableTable';
|
import ExpandableTable from './ExpandableTable';
|
||||||
import { initDefaultProps, getOptionProps } from '../../_util/props-util';
|
import { initDefaultProps, getOptionProps, getListeners } from '../../_util/props-util';
|
||||||
import BaseMixin from '../../_util/BaseMixin';
|
import BaseMixin from '../../_util/BaseMixin';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -143,7 +143,7 @@ export default {
|
||||||
['rowClick', 'rowDoubleclick', 'rowContextmenu', 'rowMouseenter', 'rowMouseleave'].forEach(
|
['rowClick', 'rowDoubleclick', 'rowContextmenu', 'rowMouseenter', 'rowMouseleave'].forEach(
|
||||||
name => {
|
name => {
|
||||||
warningOnce(
|
warningOnce(
|
||||||
this.$listeners[name] === undefined,
|
getListeners(this)[name] === undefined,
|
||||||
`${name} is deprecated, please use customRow instead.`,
|
`${name} is deprecated, please use customRow instead.`,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -509,7 +509,7 @@ export default {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const props = getOptionProps(this);
|
const props = getOptionProps(this);
|
||||||
const { $listeners, columnManager, getRowKey } = this;
|
const { columnManager, getRowKey } = this;
|
||||||
const prefixCls = props.prefixCls;
|
const prefixCls = props.prefixCls;
|
||||||
let className = props.prefixCls;
|
let className = props.prefixCls;
|
||||||
if (props.useFixedHeader || (props.scroll && props.scroll.y)) {
|
if (props.useFixedHeader || (props.scroll && props.scroll.y)) {
|
||||||
|
@ -529,7 +529,7 @@ export default {
|
||||||
columnManager,
|
columnManager,
|
||||||
getRowKey,
|
getRowKey,
|
||||||
},
|
},
|
||||||
on: { ...$listeners },
|
on: getListeners(this),
|
||||||
scopedSlots: {
|
scopedSlots: {
|
||||||
default: expander => {
|
default: expander => {
|
||||||
this.expander = expander;
|
this.expander = expander;
|
||||||
|
|
Loading…
Reference in New Issue