mrpmorris / Fluxor

Fluxor is a zero boilerplate Flux/Redux library for Microsoft .NET and Blazor.
MIT License
1.22k stars 139 forks source link

Subscribing external events #467

Closed alperenbelgic closed 3 months ago

alperenbelgic commented 5 months ago

I am considering to propose the library for a project / development team. It's a complex WPF application handling several external hardware resources/sensors and providing visuals / UIs with complex user interactions.

I used the library on multiple Blazor applications before and it worked just perfect.

For this new use case, I am not quite sure how to handle external event subscriptions within Fluxor.

When making HTTP requests on a web app we use effects but I am not sure if I need to make external event subscriptions within UI controls and make action dispatches or if there's any way to keep the life cycle of subscription/unsubscription in effects.

stagep commented 4 months ago

The Fluxor.Blazor.Web library provides FluxorComponent and FluxorLayout which handles updating the UI automatically.

If you do not inherit from FluxorComponent or FluxorLayout in a Blazor application, you need to subscribe to the StateChanged event and update the UI in your code by calling InvokeAsync(StateHasChanged). Also, on disposal of a component you must unsubscribe from the StateChanged event.

The same concept of subscribing / unsubscribing to the StateChanged event can be used with your WPF application.

mrpmorris commented 4 months ago

However your app usually listens for events, just do that. When they happen then dispatch actions with the new data in.

If it's fast paced streaming data then it might be better to use ReactiveX or something. At least worth checking, anyway.