Skip to content

Commit 385f908

Browse files
author
AiZhen
committed
优化节点缓存操作的比较逻辑。
1 parent df71110 commit 385f908

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/BootstrapBlazor/Misc/ExpandableNodeCache.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public virtual async Task ToggleNodeAsync(TNode node, Func<TNode, Task<IEnumerab
5151
ExpandedNodeCache.Add(node.Value);
5252

5353
// 收缩节点缓存移除此节点
54-
CollapsedNodeCache.Remove(node.Value);
54+
CollapsedNodeCache.RemoveWhere(x => EqualityComparer.Equals(x, node.Value));
5555

5656
// 无子项时通过回调方法延时加载
5757
if (node.HasChildren && !node.Items.Any())
@@ -67,7 +67,7 @@ public virtual async Task ToggleNodeAsync(TNode node, Func<TNode, Task<IEnumerab
6767
else
6868
{
6969
// 展开节点缓存移除此节点
70-
ExpandedNodeCache.Remove(node.Value);
70+
ExpandedNodeCache.RemoveWhere(x => EqualityComparer.Equals(x, node.Value));
7171

7272
// 收缩节点缓存添加此节点
7373
CollapsedNodeCache.Add(node.Value);
@@ -85,7 +85,7 @@ public async Task CheckExpandAsync(TNode node, Func<TNode, Task<IEnumerable<IExp
8585
if (node.IsExpand)
8686
{
8787
// 已收缩
88-
if (CollapsedNodeCache.Contains(node.Value))
88+
if (CollapsedNodeCache.Contains(node.Value, EqualityComparer))
8989
{
9090
node.IsExpand = false;
9191
}
@@ -96,7 +96,7 @@ public async Task CheckExpandAsync(TNode node, Func<TNode, Task<IEnumerable<IExp
9696
else
9797
{
9898
var needRemove = true;
99-
if (ExpandedNodeCache.Contains(node.Value))
99+
if (ExpandedNodeCache.Contains(node.Value, EqualityComparer))
100100
{
101101
// 原来是展开状态,
102102
if (node.HasChildren || node.Items.Any())
@@ -117,7 +117,7 @@ public async Task CheckExpandAsync(TNode node, Func<TNode, Task<IEnumerable<IExp
117117
}
118118
if (needRemove)
119119
{
120-
ExpandedNodeCache.Remove(node.Value);
120+
ExpandedNodeCache.RemoveWhere(x => EqualityComparer.Equals(x, node.Value));
121121
}
122122
}
123123
}

0 commit comments

Comments
 (0)