Skip to content

Instantly share code, notes, and snippets.

@Martin-Andersen
Last active February 23, 2023 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Martin-Andersen/6047a68025366644104e5ecd8a154563 to your computer and use it in GitHub Desktop.
Save Martin-Andersen/6047a68025366644104e5ecd8a154563 to your computer and use it in GitHub Desktop.
Fluxor for a SignalR hub
using Fluxor;
using Ibex.Shared.DTO;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.SignalR.Client;
namespace Ibex.Client.Store;
public record CertificateToApproveState
{
public CertificateToApproveState()
{
TradeRequestsLights = new();
}
public CertificateToApproveState(List<CertificateTradeRequestsLight> tradeRequestsLights)
{
TradeRequestsLights = tradeRequestsLights;
}
public List<CertificateTradeRequestsLight> TradeRequestsLights { get; set; } = new();
};
public class CertificateToApproveHubFeature : Feature<CertificateToApproveState>
{
public override string GetName() => "CertificateToApproveHub";
protected override CertificateToApproveState GetInitialState()
{
return new CertificateToApproveState();
}
}
public class CertificateToApproveHubEffects
{
private readonly HubConnection _hubConnection;
public CertificateToApproveHubEffects(NavigationManager navigationManager)
{
_hubConnection = new HubConnectionBuilder()
.WithUrl(navigationManager.ToAbsoluteUri("/CertificateToApproveHub"))
.WithAutomaticReconnect()
.Build();
}
[EffectMethod(typeof(CertificateToApproveHubStartAction))]
public async Task Start(IDispatcher dispatcher)
{
await _hubConnection.StartAsync();
_hubConnection.On<List<CertificateTradeRequestsLight>>("CertificateToApprove",
approvals => dispatcher.Dispatch(new CertificateToApproveHubReceivedAction(approvals)));
}
}
public record CertificateToApproveHubReceivedAction(List<CertificateTradeRequestsLight> TradeRequestsLights);
public record CertificateToApproveHubStartAction;
@Martin-Andersen
Copy link
Author

Martin-Andersen commented Feb 23, 2023

This is all what it takes 😍

@inherits FluxorComponent

Then add this in OnInitializedAsync

SubscribeToAction<CertificateToApproveHubReceivedAction>(state => UpdateGridOnNewApprovals(state));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment