Skip to content

Commit 0947e68

Browse files
authored
feat(FlipClock): add value argument on Reset method (#7662)
* refactor: 增加重置值参数 * test: 增加单元测试 * chore: bump version 10.3.2-beta04
1 parent d49a9e8 commit 0947e68

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>10.3.2-beta03</Version>
4+
<Version>10.3.2-beta04</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/FlipClock/FlipClock.razor.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public partial class FlipClock
151151
/// <para lang="en">Gets or sets Start Time for Countdown or Count <see cref="FlipClockViewMode.Count"/> Default Effective in <see cref="FlipClockViewMode.CountDown" /> Mode</para>
152152
/// </summary>
153153
[Parameter]
154-
public TimeSpan? StartValue { get; set; }
154+
public TimeSpan StartValue { get; set; }
155155

156156
private string? ClassString => CssBuilder.Default("bb-flip-clock")
157157
.AddClassFromAttributes(AdditionalAttributes)
@@ -175,21 +175,26 @@ public partial class FlipClock
175175
/// <summary>
176176
/// <inheritdoc/>
177177
/// </summary>
178-
protected override Task InvokeInitAsync() => Reset();
179-
180-
private double GetTicks() => StartValue?.TotalMilliseconds ?? 0;
178+
protected override Task InvokeInitAsync() => Reset(StartValue);
181179

182180
/// <summary>
183181
/// <para lang="zh">重置方法</para>
184182
/// <para lang="en">Reset method</para>
185183
/// </summary>
186184
/// <returns></returns>
187-
public Task Reset() => InvokeVoidAsync("init", Id, Interop, new
185+
public Task Reset(TimeSpan? value = null)
188186
{
189-
OnCompleted = nameof(OnCompleted),
190-
ViewMode = ViewMode.ToString(),
191-
StartValue = GetTicks()
192-
});
187+
if (value == null)
188+
{
189+
value = TimeSpan.Zero;
190+
}
191+
return InvokeVoidAsync("init", Id, Interop, new
192+
{
193+
OnCompleted = nameof(OnCompleted),
194+
ViewMode = ViewMode.ToString(),
195+
StartValue = value.Value.TotalMilliseconds
196+
});
197+
}
193198

194199
/// <summary>
195200
/// <para lang="zh">倒计时结束回调方法由 JSInvoke 调用</para>

test/UnitTest/Components/FlipClockTest.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ public async Task ViewMode_Ok()
102102
await cut.InvokeAsync(() => cut.Instance.OnCompleted());
103103
Assert.True(completed);
104104

105-
cut.Render(pb =>
106-
{
107-
pb.Add(a => a.StartValue, null);
108-
});
105+
await cut.InvokeAsync(() => cut.Instance.Reset());
109106
}
110107

111108
[Theory]

0 commit comments

Comments
 (0)