mrpmorris / Fluxor

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

Fluxor.Blazor.Web.Components.FluxorComponent does not work in .NET 8 #461

Closed p6laris closed 7 months ago

p6laris commented 7 months ago

i've tried to inherit from Fluxor.Blazor.Web.Components.FluxorComponent, aslo tried manully subscribe to StateChange event. But it does'nt work

I'm using .NET 8 WASM

My component code:

@code {

    [Inject]
    public IState<LanguageDropdownState>? State { get; set; }

    [Inject]
    public IDispatcher? dispatcher { get; set; }

    private Language SelectedLanguage { get; set; } = Language.Kurdish;

    protected override void OnAfterRender(bool firstRender)
    {
        if (firstRender)
        {
            State!.StateChanged += ToggleStateChanged;
        }
    }

    private void ToggleStateChanged(object? sender, EventArgs args)
    {
        InvokeAsync(StateHasChanged);
    }
    private void ToggleMenu()
    {
        var action = new LanguageDropdwonToggleAction(!State!.Value.IsOpened);
        dispatcher!.Dispatch(action);
    }

    public void ChangeLanguage(Language language)
    {
        SelectedLanguage = language;
        var action = new LanguageDropdwonToggleAction(false);
        dispatcher!.Dispatch(action);
    }

    void IDisposable.Dispose()
    {
        State!.StateChanged -= ToggleStateChanged;
    }
}
stagep commented 7 months ago

There is a lot going on here so I will suggest some simplification. I would remove all the ! and ? as there is an expectation that the injected values will not be null and it would be helpful to know if the injected values are null when they should not be. Also, I wire up events in OnInitializedAsync().

p6laris commented 7 months ago

Sorry for the confusion sir, it is working properly now I just misused the component.