Reputation: 312
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?
Upvotes: 0
Views: 2264
Reputation: 23224
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.
Upvotes: 1
Reputation: 11744
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.
Upvotes: 1