mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 14:13:37 +08:00
Improve transfer perfermance, close #2112
This commit is contained in:
parent
48e8c513f5
commit
3c408e0d22
@ -55,13 +55,28 @@ export default class Transfer extends React.Component {
|
|||||||
}
|
}
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
const { leftCheckedKeys, rightCheckedKeys } = this.state;
|
const { leftCheckedKeys, rightCheckedKeys } = this.state;
|
||||||
const { leftDataSource, rightDataSource } = this.splitDataSource(nextProps);
|
if (nextProps.targetKeys !== this.props.targetKeys ||
|
||||||
this.setState({
|
nextProps.dataSource !== this.props.dataSource) {
|
||||||
leftCheckedKeys: leftCheckedKeys.filter(data => leftDataSource.filter(leftData => leftData.key === data).length),
|
// clear cached splited dataSource
|
||||||
rightCheckedKeys: rightCheckedKeys.filter(data => rightDataSource.filter(rightData => rightData.key === data).length),
|
this.splitedDataSource = null;
|
||||||
});
|
|
||||||
|
const { dataSource, targetKeys } = nextProps;
|
||||||
|
// clear key nolonger existed
|
||||||
|
// clear checkedKeys according to targetKeys
|
||||||
|
this.setState({
|
||||||
|
leftCheckedKeys: leftCheckedKeys
|
||||||
|
.filter(data => dataSource.filter(item => item.key === data).length)
|
||||||
|
.filter(data => targetKeys.filter(key => key === data).length === 0),
|
||||||
|
rightCheckedKeys: rightCheckedKeys
|
||||||
|
.filter(data => dataSource.filter(item => item.key === data).length)
|
||||||
|
.filter(data => targetKeys.filter(key => key === data).length > 0),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
splitDataSource(props) {
|
splitDataSource(props) {
|
||||||
|
if (this.splitedDataSource) {
|
||||||
|
return this.splitedDataSource;
|
||||||
|
}
|
||||||
const { targetKeys } = props;
|
const { targetKeys } = props;
|
||||||
let { dataSource } = props;
|
let { dataSource } = props;
|
||||||
|
|
||||||
@ -86,10 +101,12 @@ export default class Transfer extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
this.splitedDataSource = {
|
||||||
leftDataSource,
|
leftDataSource,
|
||||||
rightDataSource,
|
rightDataSource,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return this.splitedDataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
moveTo = (direction) => {
|
moveTo = (direction) => {
|
||||||
@ -194,7 +211,7 @@ export default class Transfer extends React.Component {
|
|||||||
|
|
||||||
handleSelect = (direction, selectedItem, checked) => {
|
handleSelect = (direction, selectedItem, checked) => {
|
||||||
const { leftCheckedKeys, rightCheckedKeys } = this.state;
|
const { leftCheckedKeys, rightCheckedKeys } = this.state;
|
||||||
const holder = direction === 'left' ? leftCheckedKeys : rightCheckedKeys;
|
const holder = direction === 'left' ? [...leftCheckedKeys] : [...rightCheckedKeys];
|
||||||
let index;
|
let index;
|
||||||
holder.forEach((key, i) => {
|
holder.forEach((key, i) => {
|
||||||
if (key === selectedItem.key) {
|
if (key === selectedItem.key) {
|
||||||
|
@ -3,6 +3,7 @@ import Checkbox from '../checkbox';
|
|||||||
import Search from './search';
|
import Search from './search';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import Animate from 'rc-animate';
|
import Animate from 'rc-animate';
|
||||||
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
||||||
|
|
||||||
function noop() {
|
function noop() {
|
||||||
}
|
}
|
||||||
@ -60,6 +61,10 @@ export default class TransferList extends React.Component {
|
|||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shouldComponentUpdate(...args) {
|
||||||
|
return PureRenderMixin.shouldComponentUpdate.apply(this, args);
|
||||||
|
}
|
||||||
|
|
||||||
handleSelectAll = () => {
|
handleSelectAll = () => {
|
||||||
this.props.handleSelectAll();
|
this.props.handleSelectAll();
|
||||||
}
|
}
|
||||||
@ -128,7 +133,6 @@ export default class TransferList extends React.Component {
|
|||||||
} else {
|
} else {
|
||||||
itemText = renderResult;
|
itemText = renderResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
const filterResult = this.matchFilter(itemText, filter);
|
const filterResult = this.matchFilter(itemText, filter);
|
||||||
return !!filterResult;
|
return !!filterResult;
|
||||||
}).map((item) => {
|
}).map((item) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user