Skip to content

Commit

Permalink
Blazor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Oct 1, 2024
1 parent 39dc034 commit 965c587
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion samples/Sample.Blazor/Contracts/DoThing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Sample.Blazor.Contracts;

public record DoThing : IRequest;
public record DoThing(string Text) : IRequest;
2 changes: 1 addition & 1 deletion samples/Sample.Blazor/Contracts/TheThing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Sample.Blazor.Contracts;

public class TheThing : IEvent;
public class TheThing(string Text) : IEvent;
2 changes: 1 addition & 1 deletion samples/Sample.Blazor/Handlers/DoThingRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ namespace Sample.Blazor.Handlers;
public class DoThingRequestHandler(IMediator mediator) : IRequestHandler<DoThing>
{
public Task Handle(DoThing request, CancellationToken cancellationToken)
=> mediator.Publish(new TheThing(), cancellationToken);
=> mediator.Publish(new TheThing(request.Text), cancellationToken);
}
13 changes: 12 additions & 1 deletion samples/Sample.Blazor/Pages/Home.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@page "/"
@using Sample.Blazor.Contracts
@using Shiny.Mediator
@using Shiny.Mediator.Infrastructure
@inject IInternetService internet
@inject IMediator mediator
@implements IEventHandler<Sample.Blazor.Contracts.TheThing>

Expand All @@ -10,14 +12,23 @@

Welcome to your new app.

<input type="text" @bind-value="this.text" />
<button @onclick="TestSend">Test Send</button>

@if (this.text != null)
{
<br />
<text>Text from Mediator: @this.text</text>
}


@code {
string text;


async Task TestSend()
{
await mediator.Send(new DoThing());
await mediator.Send(new DoThing(this.text));
}

public Task Handle(TheThing @event, CancellationToken cancellationToken)
Expand Down
1 change: 1 addition & 0 deletions samples/Sample.Blazor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddShinyMediator(x => x.UseBlazor());
builder.Services.AddDiscoveredMediatorHandlersFromSample_Blazor();

await builder.Build().RunAsync();
5 changes: 2 additions & 3 deletions samples/Sample.Blazor/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Shiny Mediator</title>
<base href="/" />
<link rel="stylesheet" href="css/app.css" />

<script src="_content/Shiny.Mediator.Blazor/Mediator.js"></script>
<link rel="stylesheet" href="css/app.css" />
</head>

<body>
Expand All @@ -26,6 +24,7 @@
<a class="dismiss">🗙</a>
</div>
<script src="_framework/blazor.webassembly.js"></script>
<script src="_content/Shiny.Mediator.Blazor/Mediator.js"></script>
</body>

</html>
2 changes: 1 addition & 1 deletion src/Shiny.Mediator.Blazor/Shiny.Mediator.Blazor.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand Down

0 comments on commit 965c587

Please sign in to comment.