add a scanner, but this seems to be a wrong solution. Change open-source head
This commit is contained in:
@@ -1,33 +1,25 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="PanelStateSample"
|
||||
// Project: StgSharp
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
|
||||
namespace StgSharp.UserInterface.Sample
|
||||
{
|
||||
public sealed class PanelStateSample : PanelState
|
||||
{
|
||||
|
||||
public const string SampleStatePath = nameof(PanelStateSample) + "." + nameof(SampleState);
|
||||
|
||||
private int sampleState;
|
||||
|
||||
public PanelStateSample()
|
||||
: base(nameof(PanelStateSample))
|
||||
{
|
||||
}
|
||||
public PanelStateSample() : base(nameof(PanelStateSample)) { }
|
||||
|
||||
public int SampleState => sampleState;
|
||||
|
||||
// 生成器拆分后,这里相当于某个节点 handler 的 guard,
|
||||
// 对应 ICommand 语义中的 CanExecute。
|
||||
private static bool CanApplySampleStateChange(
|
||||
int origin,
|
||||
int current,
|
||||
StateValueCommand<int> command
|
||||
)
|
||||
{
|
||||
return string.Equals(command.StatePath, SampleStatePath, StringComparison.Ordinal)
|
||||
&& current >= 0
|
||||
&& origin != current;
|
||||
}
|
||||
|
||||
// 实际项目里这整个 StateChangeHandler 都由源生成器产出;
|
||||
// 这里手写展开,只是为了展示“没有生成器时 VSS 代码长什么样”。
|
||||
public void ApplySampleStateChangeCommand(
|
||||
@@ -38,8 +30,7 @@ namespace StgSharp.UserInterface.Sample
|
||||
|
||||
int origin = sampleState;
|
||||
int current = command.Value;
|
||||
if (!CanApplySampleStateChange(origin, current, command))
|
||||
{
|
||||
if (!CanApplySampleStateChange(origin, current, command)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -50,8 +41,8 @@ namespace StgSharp.UserInterface.Sample
|
||||
// 生成器拆分后,这里相当于某个节点写入后的 post-change hook,
|
||||
// 对应手写体系里常见的 OnChange 位置。
|
||||
private static void BroadcastSampleStateChanged(
|
||||
int origin,
|
||||
int current
|
||||
int origin,
|
||||
int current
|
||||
)
|
||||
{
|
||||
_ = origin;
|
||||
@@ -61,5 +52,18 @@ namespace StgSharp.UserInterface.Sample
|
||||
// 这里只能继续手写内部同步/广播逻辑;正式版本由生成器织入。
|
||||
}
|
||||
|
||||
// 生成器拆分后,这里相当于某个节点 handler 的 guard,
|
||||
// 对应 ICommand 语义中的 CanExecute。
|
||||
private static bool CanApplySampleStateChange(
|
||||
int origin,
|
||||
int current,
|
||||
StateValueCommand<int> command
|
||||
)
|
||||
{
|
||||
return string.Equals(command.StatePath, SampleStatePath, StringComparison.Ordinal) &&
|
||||
current >= 0 &&
|
||||
origin != current;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user