Tree: improve performance (#14881)

pull/15221/head
ChenZhuoSteve 2019-04-23 10:52:02 +08:00 committed by hetech
parent 6ae9f0838f
commit 0e0a506193
4 changed files with 12 additions and 4 deletions

View File

@ -71,6 +71,7 @@ export default class Node {
this.expanded = false;
this.parent = null;
this.visible = true;
this.isCurrent = false;
for (let name in options) {
if (options.hasOwnProperty(name)) {
@ -123,6 +124,7 @@ export default class Node {
if (key && store.currentNodeKey !== undefined && this.key === store.currentNodeKey) {
store.currentNode = this;
store.currentNode.isCurrent = true;
}
if (store.lazy) {

View File

@ -314,8 +314,13 @@ export default class TreeStore {
return this.currentNode;
}
setCurrentNode(node) {
this.currentNode = node;
setCurrentNode(currentNode) {
const prevCurrentNode = this.currentNode;
if (prevCurrentNode) {
prevCurrentNode.isCurrent = false;
}
this.currentNode = currentNode;
this.currentNode.isCurrent = true;
}
setUserCurrentNode(node) {
@ -331,7 +336,7 @@ export default class TreeStore {
}
const node = this.getNode(key);
if (node) {
this.currentNode = node;
this.setCurrentNode(node);
}
}
};

View File

@ -6,7 +6,7 @@
v-show="node.visible"
:class="{
'is-expanded': expanded,
'is-current': tree.store.currentNode === node,
'is-current': node.isCurrent,
'is-hidden': !node.visible,
'is-focusable': !node.disabled,
'is-checked': !node.disabled && node.checked

1
types/tree.d.ts vendored
View File

@ -36,6 +36,7 @@ export interface TreeNode<K, D> {
label: string;
nextSibling: TreeNode<K, D> | null;
previousSibling: TreeNode<K, D> | null;
isCurrent: boolean;
}
/** incomplete, you can convert to any to use other properties */