Blazor State with using Fluxor: ActionSubscriber or SubscribeToAction what is better to use?

1.6k views Asked by At

I'm novice with using Blazor and Fluxor, and I trying to deside what is better to use

IActionSubscriber - manually inject, subscribe and unsubscribe

or

inherit FluxorComponent - and use the ActionSubscriber

What is the best solution? What is benefits and disadvantages?

2

There are 2 answers

0
Peter Morris On

Descending from FluxorComponent will mean your component automatically subscribes to StateChanged on any IState<T> property - when triggered it will call InvokeAsync(StateHasChanged to ensure the UI is updated.

IActionSubscriber isn't meant for determining when to update the UI, but to allow the UI to catch data that doesn't get reduced into the store. For example, an editable DTO from a server API for the current page to edit.

0
Eric King On

Inheriting from FluxorComponent has a couple of advantages, in that you don't need to manually call StateHasChanged all the time and you don't have to inject the IActionSubscriber, as it in included for free, and you don't have to remember to unsubscribe on disposing the component.

Functionality-wise, I don't think there's any difference, except that the FluxorComponent takes care of some work for you.

The only disadvantage I can think of is if inheriting from FluxorComponent keeps you from inheriting from another base component class.

As for myself, I just inherit from FluxorComponent and go. It's working very well.