mrpmorris / Fluxor

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

Breaking change: Removed IState<TState> generic StateChanged event. #259

Closed kjdamen closed 2 years ago

kjdamen commented 2 years ago

Hi,

In release 5.0 the following has changed:

In my OnInitializedAsync I have included the following code.

_protected override async Task OnInitializedAsync()
{
    // Register a state change to assign a newly created product id
    ProductState.StateChanged += (sender, state) =>
    {
        if (ProductValidationModel.Id == 0 && state.SelectedProduct != null)
        {
            ProductValidationModel.Id = state.SelectedProduct.Id;
            StateHasChanged();
        }
    };
}_

Here I can no longer read the SelectedProduct property from state. How can I apply this code in the 5.0 release?

Regards, Kevin

mrpmorris commented 2 years ago

You'll need to typecast it.

What are you trying to achieve?

kjdamen commented 2 years ago

In the tutorial of the link below you will see a similar code in the component TodoDetail.razor.

state-management-with-blazor-using-fluxor-part-2

In the OnInitialized function the TodosState.StateChanged does not work anymore since version 5.0. State here is of type eventargs and it is not possible to typecast.

mrpmorris commented 2 years ago

The blog is now outdated. The correct way to obtain the new state is to inject IState<T> and read it from there.