Skip to content

Commit 1492373

Browse files
committed
feat: Update Fusion to v1.5.7
1 parent 3a993d2 commit 1492373

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+310
-132
lines changed

docs/tutorial/Part03.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.Extensions.DependencyInjection;
55
using Stl.Async;
66
using Stl.Fusion;
7+
using Stl.Fusion.UI;
78
using static System.Console;
89

910
namespace Tutorial
@@ -83,7 +84,7 @@ public static async Task LiveState()
8384
WriteLine("Creating state.");
8485
using var state = stateFactory.NewComputed<string>(
8586
options => {
86-
options.UpdateDelayer = new UpdateDelayer(1.0); // 1 second update delay
87+
options.UpdateDelayer = new UpdateDelayer(UICommandTracker.None, 1.0); // 1 second update delay
8788
options.EventConfigurator += state1 => {
8889
// A shortcut to attach 3 event handlers: Invalidated, Updating, Updated
8990
state1.AddEventHandler(StateEventKind.All,

docs/tutorial/Part04.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Stl.Fusion;
1818
using Stl.Fusion.Client;
1919
using Stl.Fusion.Server;
20+
using Stl.Fusion.UI;
2021
using static System.Console;
2122

2223
namespace Tutorial
@@ -229,7 +230,7 @@ public static async Task LiveStateFromReplica()
229230
var stateFactory = services.StateFactory();
230231
using var state = stateFactory.NewComputed<string>(
231232
options => {
232-
options.UpdateDelayer = new UpdateDelayer(1.0); // 1 second update delay
233+
options.UpdateDelayer = new UpdateDelayer(UICommandTracker.None, 1.0); // 1 second update delay
233234
options.EventConfigurator += state1 => {
234235
// A shortcut to attach 3 event handlers: Invalidated, Updating, Updated
235236
state1.AddEventHandler(StateEventKind.All,

docs/tutorial/Tutorial.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="Stl.Fusion.Client" Version="1.4.3" />
22-
<PackageReference Include="Stl.Fusion.Server" Version="1.4.3" />
21+
<PackageReference Include="Stl.Fusion.Client" Version="1.5.7" />
22+
<PackageReference Include="Stl.Fusion.Server" Version="1.5.7" />
2323
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20303.1" />
2424
<PackageReference Include="System.CommandLine.DragonFruit" Version="0.3.0-alpha.20303.1" />
2525
</ItemGroup>

src/Blazor/Abstractions/Abstractions.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="5.0.8" />
1414
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="5.0.0" />
1515
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
16-
<PackageReference Include="Stl.Fusion.Client" Version="1.4.3" />
16+
<PackageReference Include="Stl.Fusion.Client" Version="1.5.7" />
1717
</ItemGroup>
1818

1919
</Project>

src/Blazor/Client/Client.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<ItemGroup>
1313
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="5.0.0" />
1414
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
15-
<PackageReference Include="Stl.Fusion.Client" Version="1.4.3" />
15+
<PackageReference Include="Stl.Fusion.Client" Version="1.5.7" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

src/Blazor/ConsoleClient/ConsoleClient.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Stl.Fusion.Client" Version="1.4.3" />
13+
<PackageReference Include="Stl.Fusion.Client" Version="1.5.7" />
1414
</ItemGroup>
1515

1616
<ItemGroup>

src/Blazor/ConsoleClient/Program.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Stl.Fusion;
99
using Stl.Fusion.Client;
1010
using Stl.Fusion.Extensions;
11+
using Stl.Fusion.UI;
1112
using static System.Console;
1213

1314
var services = CreateServiceProvider();
@@ -61,7 +62,7 @@ static IServiceProvider CreateServiceProvider()
6162
fusionClient.AddReplicaService<ISumService, ISumClientDef>();
6263

6364
// Default update delay is 0.1s
64-
services.AddTransient<IUpdateDelayer>(_ => new UpdateDelayer(0.1));
65+
services.AddTransient<IUpdateDelayer>(c => new UpdateDelayer(c.UICommandTracker(), 0.1));
6566

6667
return services.BuildServiceProvider();
6768
}

src/Blazor/Server/Server.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.8" />
1919
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3" />
2020
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta11" />
21-
<PackageReference Include="Stl.Fusion.Server" Version="1.4.3" />
22-
<PackageReference Include="Stl.Fusion.EntityFramework" Version="1.4.3" />
21+
<PackageReference Include="Stl.Fusion.Server" Version="1.5.7" />
22+
<PackageReference Include="Stl.Fusion.EntityFramework" Version="1.5.7" />
2323
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4" />
2424
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
2525
</ItemGroup>

src/Blazor/Server/Services/ChatService.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Reactive;
5+
using System.Security.Authentication;
56
using System.Threading;
67
using System.Threading.Tasks;
78
using Microsoft.EntityFrameworkCore;
@@ -53,7 +54,7 @@ public virtual async Task<ChatMessage> Post(
5354
text = await NormalizeText(text, cancellationToken);
5455
var user = await GetCurrentUser(session, cancellationToken);
5556
if (user == null)
56-
throw new InvalidOperationException("No current ChatUser. Call SetUserNameAsync to create it.");
57+
throw new AuthenticationException("Please sign in first.");
5758

5859
await using var dbContext = await CreateCommandDbContext(cancellationToken);
5960
var message = new ChatMessage() {

src/Blazor/UI/Pages/Authentication.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<h1>Authentication</h1>
2121

22-
<WhenException Title="Update error:" Exception="@error"></WhenException>
22+
<WhenUpdateError Exception="@error" />
2323

2424
<Note>
2525
<Div Margin="Margin.Is1.FromBottom">

src/Blazor/UI/Pages/Chat.razor

+13-26
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
@page "/chat"
22
@using System.Threading
3-
@using Stl.CommandR
43
@using Stl.Fusion.Authentication.Commands
54
@inherits MixedStateComponent<Chat.Model, Chat.LocalsModel>
65
@inject Session Session
7-
@inject ICommander Commander
86
@inject IChatService ChatService
7+
@inject UICommandRunner CommandRunner
98
@inject NavigationManager Navigator
9+
@inject ILogger<Chat> Log
1010

1111
@{
1212
var locals = MutableState.Value;
@@ -33,8 +33,7 @@
3333
in another window to see everything is updated in sync in real time.
3434
</Note>
3535

36-
<WhenException Title="Action failed:" Exception="@locals.Error"/>
37-
<WhenException Title="Update error:" Exception="@error"/>
36+
<WhenUpdateError Exception="@error"/>
3837

3938
<AuthorizeView>
4039
<Authorized>
@@ -110,7 +109,6 @@
110109

111110
public bool IsNameModified { get; set; }
112111
public string Message { get; set; } = "";
113-
public Exception? Error { get; set; }
114112
}
115113

116114
public class Model
@@ -148,49 +146,38 @@
148146

149147
private async Task SetName()
150148
{
151-
ResetError();
152149
var locals = MutableState.Value;
150+
var command = new EditUserCommand(Session, locals.Name ?? "");
153151
try {
154-
var command = new EditUserCommand(Session, locals.Name ?? "");
155-
if (command.Name!.Length < 4)
156-
throw new ApplicationException("The name should be at least 4 character long.");
157-
await Commander.Call(command);
152+
await CommandRunner.Run(new LocalCommand(() => {
153+
if (command.Name!.Length < 4)
154+
throw new ApplicationException("The name should be at least 4 character long.");
155+
}), true);
156+
await CommandRunner.Run(command, true);
158157
}
159158
catch (Exception e) {
160-
SetError(e);
159+
Log.LogError(e, "Error!");
161160
}
162161
}
163162

164163
private async Task Post()
165164
{
166-
ResetError();
167165
try {
168-
if (State.ValueOrDefault?.ChatUser?.IsValid != true)
169-
throw new ApplicationException("Please sign in first.");
170-
await ChatService.Post(new(MutableState.Value.Message, Session));
166+
await CommandRunner.Run(new IChatService.PostCommand(MutableState.Value.Message, Session), true);
171167
MutableState.Value.Message = "";
172168
MutableState.Invalidate();
173169
}
174170
catch (Exception e) {
175-
SetError(e);
171+
Log.LogError(e, "Error!");
176172
}
177173
}
178174

179175
// Convenience shortcuts
180176
181-
private void ResetError()
182-
=> SetError(null);
183-
184177
private void ResetName(string name)
185178
{
186179
MutableState.Value.Name = name;
187180
MutableState.Value.IsNameModified = false;
188181
MutableState.Invalidate();
189182
}
190-
191-
private void SetError(Exception? error)
192-
{
193-
MutableState.Value.Error = error;
194-
MutableState.Invalidate();
195-
}
196-
}
183+
}

src/Blazor/UI/Pages/Composition.razor

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
<StateOfStateBadge State="@State" />
2525

26-
<WhenException Title="Update error:" Exception="@error"/>
26+
<WhenUpdateError Exception="@error"/>
2727

2828
<Addons>
2929
<Addon AddonType="AddonType.Start">
@@ -53,7 +53,7 @@
5353
}
5454

5555
protected override void ConfigureState(ComputedState<Model>.Options options)
56-
=> options.UpdateDelayer = new UpdateDelayer(0.5);
56+
=> options.UpdateDelayer = new UpdateDelayer(Services.UICommandTracker(), 0.5);
5757

5858
protected override async Task<Model> ComputeState(CancellationToken cancellationToken)
5959
{

src/Blazor/UI/Pages/ServerScreen.razor

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<h1>Server Screen</h1>
1313

14-
<WhenException Title="Update error:" Exception="@error"/>
14+
<WhenUpdateError Exception="@error"/>
1515

1616
<Addons>
1717
<Addon AddonType="AddonType.Start"><AddonLabel>Screenshot width (in pixels):</AddonLabel></Addon>
@@ -34,7 +34,7 @@
3434
=> await State.Update(); // An example showing how to load the State before the first render
3535
3636
protected override void ConfigureState(ComputedState<Screenshot>.Options options)
37-
=> options.UpdateDelayer = UpdateDelayer.ZeroUpdateDelay;
37+
=> options.UpdateDelayer = UpdateDelayer.ZeroDelay;
3838

3939
protected override Task<Screenshot> ComputeState(CancellationToken cancellationToken)
4040
=> ScreenshotService.GetScreenshot(ActualWidth, cancellationToken);

src/Blazor/UI/Pages/ServerTime.razor

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<h1>Server Time</h1>
1212

13-
<WhenException Title="Update error:" Exception="@error"/>
13+
<WhenUpdateError Exception="@error"/>
1414

1515
<StateOfStateBadge State="@State" />
1616

@@ -21,7 +21,7 @@
2121

2222
@code {
2323
protected override void ConfigureState(ComputedState<DateTime>.Options options)
24-
=> options.UpdateDelayer = new UpdateDelayer(0.5);
24+
=> options.UpdateDelayer = new UpdateDelayer(Services.UICommandTracker(), 0.5);
2525

2626
protected override Task<DateTime> ComputeState(CancellationToken cancellationToken)
2727
=> Time.GetTime(cancellationToken);

src/Blazor/UI/Program.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Stl.DependencyInjection;
1616
using Stl.Fusion.Blazor;
1717
using Stl.Fusion.Extensions;
18+
using Stl.Fusion.UI;
1819

1920
namespace Samples.Blazor.UI
2021
{
@@ -75,7 +76,7 @@ public static void ConfigureSharedServices(IServiceCollection services)
7576
fusion.AddComputeService<ILocalComposerService, LocalComposerService>();
7677

7778
// Default update delay is 0.1s
78-
services.AddTransient<IUpdateDelayer>(_ => new UpdateDelayer(0.1));
79+
services.AddTransient<IUpdateDelayer>(c => new UpdateDelayer(c.UICommandTracker(), 0.1));
7980
}
8081
}
8182
}

src/Blazor/UI/Shared/AccumulatorCard.razor

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
@using System.Threading
22
@using System.Reflection
3+
@using Stl
4+
@using System.Reactive
35
@inherits MixedStateComponent<double, AccumulatorCard.LocalModel>
46
@inject ISumService SumService
7+
@inject UICommandRunner CommandRunner
58

69
@{
710
var accumulator = State.LatestNonErrorValue;
@@ -15,7 +18,7 @@
1518
<CardBody>
1619
<StateOfStateBadge State="@State" />
1720

18-
<WhenException Title="Update error:" Exception="@error"/>
21+
<WhenUpdateError Exception="@error"/>
1922

2023
<Paragraph Margin="Margin.Is3.OnY">
2124
Value: <b>@accumulator</b>
@@ -50,25 +53,21 @@
5053
public TimeSpan UpdateDelay { get; set; } = TimeSpan.FromSeconds(1);
5154

5255
protected override void OnParametersSet()
53-
=> State.UpdateDelayer = new UpdateDelayer(UpdateDelay);
56+
=> State.UpdateDelayer = new UpdateDelayer(Services.UICommandTracker(), UpdateDelay);
5457

5558
protected override void ConfigureState(ComputedState<double>.Options options)
56-
=> options.UpdateDelayer = new UpdateDelayer(UpdateDelay);
59+
=> options.UpdateDelayer = new UpdateDelayer(Services.UICommandTracker(), UpdateDelay);
5760

5861
protected override Task<double> ComputeState(CancellationToken cancellationToken)
5962
=> SumService.GetAccumulator(cancellationToken);
6063

6164
// Action handlers
6265
6366
private async Task Reset()
64-
{
65-
await SumService.Reset();
66-
await State.ApplyUserCausedUpdate();
67-
}
67+
=> await CommandRunner.Run(new LocalCommand(
68+
() => SumService.Reset()));
6869

6970
private async Task Accumulate()
70-
{
71-
await SumService.Accumulate(MutableState.Value.Value);
72-
await State.ApplyUserCausedUpdate();
73-
}
71+
=> await CommandRunner.Run(new LocalCommand(
72+
() => SumService.Accumulate(MutableState.Value.Value)));
7473
}

src/Blazor/UI/Shared/Error.razor

+21-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1-
<Alert Color="Color.Danger" Visible="true" Margin="Margin.Is3.OnY">
2-
<AlertMessage>@Title</AlertMessage>
3-
<AlertDescription>@ChildContent</AlertDescription>
4-
</Alert>
1+
@if (!_isClosed) {
2+
<Alert Class="@CssClass" Color="@Color" Margin="Margin.Is3.OnY" Visible="true">
3+
<AlertMessage>@Title</AlertMessage>
4+
<AlertDescription>@ChildContent</AlertDescription>
5+
<CloseButton Clicked="Close"/>
6+
</Alert>
7+
}
58

69
@code {
10+
private bool _isClosed;
11+
12+
[Parameter]
13+
public string CssClass { get; set; } = "";
14+
[Parameter]
15+
public Color Color { get; set; } = Color.Danger;
716
[Parameter]
817
public string Title { get; set; } = "Error:";
918
[Parameter]
19+
public EventCallback Dismissed { get; set; }
20+
[Parameter]
1021
public RenderFragment? ChildContent { get; set; }
22+
23+
private Task Close()
24+
{
25+
_isClosed = true;
26+
return Dismissed.InvokeAsync(null);
27+
}
1128
}

0 commit comments

Comments
 (0)