StateR 0.1.2-gf4cdb713c1

This is a prerelease version of StateR.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package StateR --version 0.1.2-gf4cdb713c1                
NuGet\Install-Package StateR -Version 0.1.2-gf4cdb713c1                
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="StateR" Version="0.1.2-gf4cdb713c1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StateR --version 0.1.2-gf4cdb713c1                
#r "nuget: StateR, 0.1.2-gf4cdb713c1"                
#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.
// Install StateR as a Cake Addin
#addin nuget:?package=StateR&version=0.1.2-gf4cdb713c1&prerelease

// Install StateR as a Cake Tool
#tool nuget:?package=StateR&version=0.1.2-gf4cdb713c1&prerelease                

StateR

This is an experiment of a Redux-inspired .NET/C# 9.0 (preview) library. It works well with Blazor and MobileBlazorBindings, including sharing states between the Xamarin part and the Blazor part of a hybrid app. It should also work with any other .NET stateful client model.

This project uses:

  • C# 9 (preview) record classes to ensure immutability and to simplify reducers.
  • MediatR, under the hood, to mediate actions.
  • Dependency Injection to manage states

How to install?

Name NuGet.org feedz.io
dotnet add package StateR NuGet.org feedz.io
dotnet add package StateR.Blazor NuGet.org feedz.io

Counter sample

The following snippet represent a feature, surrounding a counter, where you can Increment, Decrement, and Set the value of the Count property of that Counter.State. The snippet also include the InitialState of that counter.

using StateR;

namespace BlazorMobileHybridExperiments.Features
{
    public class Counter
    {
        public record State(int Count) : StateBase;

        public class InitialState : IInitialState<State>
        {
            public State Value => new State(0);
        }

        public record Set(int Value) : IAction;
        public record Increment : IAction;
        public record Decrement : IAction;

        public class Reducers : IReducer<State, Set>, IReducer<State, Increment>, IReducer<State, Decrement>
        {
            public State Reduce(State state, Set action) => state with { Count = action.Value };
            public State Reduce(State state, Increment action) => state with { Count = state.Count + 1 };
            public State Reduce(State state, Decrement action) => state with { Count = state.Count - 1 };
        }
    }
}

Then from a Blazor component that inherits from StatorComponent, we can dispatch those actions.

@page "/counter"
@inherits StateR.Blazor.StatorComponent
@inject IState<Features.Counter.State> CounterState

<h1>Counter</h1>

<p>Current count: @CounterState.Current.Count</p>

<button class="btn btn-primary" @onclick="@(async () => await DispatchAsync(new Features.Counter.Increment()))">+</button>
<button class="btn btn-primary" @onclick="@(async () => await DispatchAsync(new Features.Counter.Decrement()))">-</button>

<hr />

<input @bind="SetTo" />
<button class="btn btn-secondary" @onclick="@(async () => await DispatchAsync(new Features.Counter.Set(SetTo)))">Set</button>

@code
{
    private int SetTo;
}

The origin

I played around with a few other libraries that aim at the same goal (another project) and I was not 100% satisfied with how they did stuff, so while playing around with MobileBlazorBindings and the new hybrid apps, I tough that C# 9 records were a great fit for this and I started experimenting and ended up with this project.

The name

Why the name? StateR, pronounced stator, is written this way as a wink to MediatR.

Definition of a stator

The stator is the stationary part of a rotary system [...]. Energy flows through a stator to or from the rotating component of the system.

Source: wikipedia

Why Redux?

After hearing about it for a while, I read about it and found the concept brilliant.

What is different from the other libraries?

This library is based on the concepts introduced by Redux, but .NET is not JavaScript and .NET Core is built around Dependency Injection (DI), so I decided to take advantage of that.

There is no type and no DI in JavaScript, so it make sense that the folks there did not take that into account when they built Redux.

To be continued

...

Found a bug or have a feature request?

Please open an issue and be as clear as possible; see How to contribute? for more information.

How to contribute?

If you would like to contribute to the project, first, thank you for your interest, and please read Contributing to ForEvolve open source projects for more information.

Contributor Covenant Code of Conduct

Also, please read the Contributor Covenant Code of Conduct that applies to all ForEvolve repositories.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on StateR:

Package Downloads
StateR.Blazor

Blazor components and utilities for use with the StateR library.

StateR.Experiments

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.78-gfb4c0ccd5c 291 4/11/2021
0.1.77-g217647b22f 155 4/11/2021
0.1.76-g922f75249d 177 4/9/2021
0.1.75-g6d04dc05f9 174 4/9/2021
0.1.74-g9e914e5fa4 188 4/9/2021
0.1.73-gea9f90e4b4 471 11/28/2020
0.1.71-g1b1884cf87 350 11/28/2020
0.1.61-gd36c7b8eff 269 10/23/2020
0.1.5-g3590a1f16d 308 9/25/2020
0.1.4-g873d087793 255 9/24/2020
0.1.3-g8b258c3f3d 243 9/24/2020
0.1.2-gf4cdb713c1 280 9/24/2020