Commit 0e0a5061 authored by ChenZhuoSteve's avatar ChenZhuoSteve Committed by hetech

Tree: improve performance (#14881)

parent 6ae9f083
...@@ -71,6 +71,7 @@ export default class Node { ...@@ -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 { ...@@ -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) {
......
...@@ -314,8 +314,13 @@ export default class TreeStore { ...@@ -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 { ...@@ -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);
} }
} }
}; };
...@@ -6,7 +6,7 @@ ...@@ -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
......
...@@ -36,6 +36,7 @@ export interface TreeNode<K, D> { ...@@ -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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment