/Logixware.AspNet.Blazor.Fluxor

Extensions for Blazor Fluxor (https://github.com/mrpmorris/blazor-fluxor)

Primary LanguageC#MIT LicenseMIT

Build status

Introduction

Extensions for Blazor Fluxor.

1. Reactive extensions

Usage

On app init:

services.AddFluxor(options => options
   ....
   .AddReactiveMiddleware(services)
);

State inside a component:

@inject IReactiveStore Store

protected override void OnInit()
{
    this.Store.States

        .TakeUntil(this._IsDisposed)
        .TakeState<SidebarsState>()
        .Where(state => state.Sidebars.ContainsKey(this.SidebarPosition))
        .Subscribe(state =>
        {
            if (this._IsMobile)
            {
                this._IsFullScreen = state.Sidebars[this.SidebarPosition].IsOpen;
                base.StateHasChanged();
            }
        });
}

Actions inside a component:

@inject IReactiveStore Store

protected override void OnInit()
{
    this.Store.Actions

        .TakeAction<OpenMobileSidebarAction>()
        .Where(action => action.SidebarPosition == this.SidebarPosition)
        .Subscribe(action =>
        {
            this._IsFullScreen = this._IsMobile;
            base.StateHasChanged();
        });

    this.Store.Actions

        .TakeAction<CloseMobileSidebarAction>()
        .Where(action => action.SidebarPosition == this.SidebarPosition)
        .Subscribe(action =>
        {
            this._IsFullScreen = false;
            base.StateHasChanged();
        });
}

Contribute

Feel free to open issues and issue pull requests.