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

View File

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

View File

@ -6,7 +6,7 @@
v-show="node.visible" v-show="node.visible"
:class="{ :class="{
'is-expanded': expanded, 'is-expanded': expanded,
'is-current': tree.store.currentNode === node, 'is-current': node.isCurrent,
'is-hidden': !node.visible, 'is-hidden': !node.visible,
'is-focusable': !node.disabled, 'is-focusable': !node.disabled,
'is-checked': !node.disabled && node.checked '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; label: string;
nextSibling: TreeNode<K, D> | null; nextSibling: TreeNode<K, D> | null;
previousSibling: TreeNode<K, D> | null; previousSibling: TreeNode<K, D> | null;
isCurrent: boolean;
} }
/** incomplete, you can convert to any to use other properties */ /** incomplete, you can convert to any to use other properties */