Last active
February 23, 2023 15:55
-
-
Save Martin-Andersen/6047a68025366644104e5ecd8a154563 to your computer and use it in GitHub Desktop.
Fluxor for a SignalR hub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is all what it takes 😍
@inherits FluxorComponent
Then add this in OnInitializedAsync
SubscribeToAction<CertificateToApproveHubReceivedAction>(state => UpdateGridOnNewApprovals(state));