BlazorFocused 1.0.0-alpha1

This is a prerelease version of BlazorFocused.
There is a newer version of this package available.
See the version list below for details.
Install-Package BlazorFocused -Version 1.0.0-alpha1
dotnet add package BlazorFocused --version 1.0.0-alpha1
<PackageReference Include="BlazorFocused" Version="1.0.0-alpha1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BlazorFocused --version 1.0.0-alpha1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: BlazorFocused, 1.0.0-alpha1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install BlazorFocused as a Cake Addin
#addin nuget:?package=BlazorFocused&version=1.0.0-alpha1&prerelease

// Install BlazorFocused as a Cake Tool
#tool nuget:?package=BlazorFocused&version=1.0.0-alpha1&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

BlazorFocused

Adding Reactive Programming and Flux Architecture to Blazor Components with Microsoft.Extensions.DependencyInjection

Register

Integrate basic store in Startup.cs:

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllersWithViews();
    services.AddRazorPages();

    // initialized instance of the store's data
    var testClass = new TestClass { FieldOne = "Test" };

    // add store in DI
    services.AddStore(testClass);
}

Integrate store with reducers in Startup.cs:

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllersWithViews();
    services.AddRazorPages();

    // initialized instance of the store's data
    var testClass = new TestClass { FieldOne = "Test" };

    // add store in DI
    serviceCollection.AddStore(testClass, builder =>
    {
        builder.RegisterReducer(new TestReducer());
    });
}

State

Retrieve static state value from store:

@inject IStore<TestClass> store;

...

store.GetState().FieldOne;

Retrieve state value and subscribe to store updates:

@inject IStore<TestClass> store;

...
TestClass currentState = default;

store.Subscribe((newState) => {
    // update state used in page
    currentState = newState;

    // inform blazor page to refresh with state update
    StateHasChanged();
});

Reducers

Subscribe to reduced value from store:

@inject IStore<TestClass> store;

...
TestClassSubset currentState = default;

store.Reduce<TestClassSubset>(reducedState =>
{
    currentState = reducedState;

    // inform blazor page to refresh with state update
    StateHasChanged();
});

Actions

Register custom actions

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllersWithViews();
    services.AddRazorPages();

    // initialized instance of the store's data
    var testClass = new TestClass { FieldOne = "Test" };

    // add store in DI
    serviceCollection.AddStore(testClass, builder =>
    {
        builder.RegisterAction(new TestAction());
    });
}

Execute actions to update store:

@inject IStore<TestClass> store;

...
TestClass currentState = default;

// call action to be committed
store.Dispatch<TestAction>();

store.Subscribe((newState) => {
    // update state used in page
    currentState = newState;

    // inform blazor page to refresh with state update
    StateHasChanged();
});

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.2 117 8/25/2021
1.2.1 97 8/24/2021
1.2.0 95 8/22/2021
1.1.2 170 7/16/2021
1.1.1 128 3/27/2021
1.1.0 113 3/27/2021
1.0.1 96 2/19/2021
1.0.0 123 2/15/2021
1.0.0-beta1 170 1/17/2021
1.0.0-alpha2 113 1/16/2021
1.0.0-alpha1 143 1/12/2021

Initial library submission