Apparatus.Blazor.State 1.0.758

There is a newer version of this package available.
See the version list below for details.
dotnet add package Apparatus.Blazor.State --version 1.0.758
                    
NuGet\Install-Package Apparatus.Blazor.State -Version 1.0.758
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Apparatus.Blazor.State" Version="1.0.758" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Apparatus.Blazor.State" Version="1.0.758" />
                    
Directory.Packages.props
<PackageReference Include="Apparatus.Blazor.State" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Apparatus.Blazor.State --version 1.0.758
                    
#r "nuget: Apparatus.Blazor.State, 1.0.758"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Apparatus.Blazor.State@1.0.758
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Apparatus.Blazor.State&version=1.0.758
                    
Install as a Cake Addin
#tool nuget:?package=Apparatus.Blazor.State&version=1.0.758
                    
Install as a Cake Tool

Apparatus.Blazor.State

Apparatus.Blazor.State is library which provides centralized state management for Blazor webassembly based implementations.

Build Status

Getting Started

1. Create Blazor webassembly project by running:

dotnet new blazorwasm -o BlazorWebAssemblyApp

2. Install the standard Nuget package into your ASP.NET Blazor project.

    Package Manager : Install-Package Apparatus.Blazor.State 
    CLI : dotnet add package Apparatus.Blazor.State

3. In Program.cs add below line to register the service:

	builder.Services.AddStateManagement(typeof(Program).Assembly);

4. Under States folder, create CounterState.cs class which shousl represent Counter page/component state, also all states should inherit Apparatus.Blazor.State.Contracts.IState interface.

    public class CounterState : IState
    {
        public int CurrentCount { get; set; }
    }

5. Create IncrementCount.cs action in "Actions" folder - all actions should inherit Apparatus.Blazor.State.Contracts.IAction interface.

    public class IncrementCount : IAction
    {
        public int IncrementBy { get; set; }
    }

6. Inherit BlazorStateComponent in Counter.razor page/component, reference CounterState in the component and implement Action Dispatcher:

	@inherits Apparatus.Blazor.State.BlazorStateComponent
    ....
<p role="status">Current count: @State.CurrentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
    CounterState State => GetState<CounterState>(); 
    [Inject] IActionDispatcher Dispatcher { get; set; }

    private void IncrementCount()
    {
        Dispatcher.Dispatch(new IncrementCount { /*IncrementBy = 2*/ });
    }
}

7. Implement Action Handler - Under "Handlers" folder create IncrementCountHandler.cs

  public class IncrementCountHandler : IActionHandler<IncrementCount>
    {
        private IStore<CounterState> _counterStore;
        public IncrementCountHandler(IStore<CounterState> counterStore)
        {
            _counterStore = counterStore; 
        }
        
        public Task Handle(IncrementCount action)
        {
            var newState = _counterStore.State;
            newState.CurrentCount++;
            /*
             * or use action property for increment value
             * newState.CurrentCount = newState.CurrentCount + action.IncrementBy;
             */
            return _counterStore.SetState(newState); 
        }
    }

In this way you can keep your states separated from logic and components/pages. For more complex use cases please check SampleApp available in the repository.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.1.44 152 12/28/2024
2.1.43 124 12/28/2024
2.1.42 150 12/28/2024
2.1.41 139 12/28/2024
2.1.40 135 12/28/2024
2.1.39 148 12/28/2024
2.1.38 145 12/28/2024
2.1.37 148 12/28/2024
2.1.36 147 12/28/2024
2.1.35 136 12/28/2024
2.1.34 124 12/28/2024
2.1.33 146 12/28/2024
2.1.32 136 12/28/2024
2.1.31 135 12/28/2024
2.1.30 157 12/28/2024
2.1.29 139 12/28/2024
2.1.26 159 10/28/2024
2.1.25 143 10/28/2024
2.1.24 162 6/10/2024
2.1.23 297 12/11/2023
2.1.22 181 12/11/2023
2.1.21 181 12/11/2023
2.1.17 185 12/10/2023
2.1.16 183 12/10/2023
2.1.15 195 12/10/2023
2.1.14 198 12/10/2023
2.1.13 189 12/10/2023
2.1.12 191 12/10/2023
2.1.11 207 12/10/2023
2.0.1 440 11/19/2022
1.0.764 424 11/11/2022
1.0.763 433 11/6/2022
1.0.762 427 11/6/2022
1.0.759 430 11/6/2022
1.0.758 410 11/5/2022
1.0.757 442 11/5/2022
1.0.756 451 11/5/2022
1.0.755 431 11/5/2022
1.0.754 420 11/5/2022
1.0.753 444 11/5/2022
1.0.752 428 11/5/2022
1.0.751 443 11/5/2022
1.0.750 442 11/5/2022
1.0.749 436 11/5/2022
1.0.748 460 11/4/2022
1.0.747 446 11/4/2022
1.0.746 445 11/4/2022
1.0.745 450 11/4/2022
1.0.744 435 11/4/2022
1.0.743 450 11/4/2022
1.0.742 472 11/4/2022
1.0.741 453 11/4/2022
1.0.740 454 11/4/2022
1.0.739 444 11/4/2022
1.0.738 430 11/4/2022
1.0.737 461 11/4/2022
1.0.736 425 11/3/2022
1.0.735 465 11/3/2022