Skip to content

Commit 7ae9604

Browse files
committed
refactor: 代码内聚
1 parent 852f9ca commit 7ae9604

2 files changed

Lines changed: 22 additions & 13 deletions

File tree

src/components/BootstrapBlazor.DockView/Components/DockViewComponent.razor.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,7 @@ protected override void OnParametersSet()
174174
base.OnParametersSet();
175175

176176
// 同步组件状态到缓存
177-
var state = DockView.GetComponentState(Key);
178-
if (state != null)
179-
{
180-
state.Visible = Visible;
181-
state.IsLock = IsLock;
182-
}
177+
DockView.UpdateComponentState(Key, Visible, IsLock);
183178
}
184179

185180
private async Task OnClickBar()

src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,27 @@ internal void RemoveComponentState(string? key)
379379
}
380380
}
381381

382-
internal DockViewComponentState? GetComponentState(string? key)
382+
internal void UpdateComponentState(string? key, bool visible, bool? isLock)
383+
{
384+
if (Renderer == DockViewRenderMode.Always)
385+
{
386+
return;
387+
}
388+
389+
if (!string.IsNullOrEmpty(key) && _componentStates.TryGetValue(key, out var state))
390+
{
391+
state.Visible = visible;
392+
state.IsLock = isLock;
393+
}
394+
}
395+
396+
internal bool IsRender(string? key) => Renderer switch
397+
{
398+
DockViewRenderMode.OnlyWhenVisible => GetComponentState(key)?.IsRender() ?? false,
399+
_ => true
400+
};
401+
402+
private DockViewComponentState? GetComponentState(string? key)
383403
{
384404
DockViewComponentState? state = null;
385405
if (Renderer == DockViewRenderMode.OnlyWhenVisible)
@@ -393,12 +413,6 @@ internal void RemoveComponentState(string? key)
393413
return state;
394414
}
395415

396-
internal bool IsRender(string? key) => Renderer switch
397-
{
398-
DockViewRenderMode.OnlyWhenVisible => GetComponentState(key)?.IsRender() ?? false,
399-
_ => true
400-
};
401-
402416
private void Dispose(bool disposing)
403417
{
404418
if (disposing)

0 commit comments

Comments
 (0)