RG.Redux 1.0.5

dotnet add package RG.Redux --version 1.0.5                
NuGet\Install-Package RG.Redux -Version 1.0.5                
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="RG.Redux" Version="1.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RG.Redux --version 1.0.5                
#r "nuget: RG.Redux, 1.0.5"                
#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 RG.Redux as a Cake Addin
#addin nuget:?package=RG.Redux&version=1.0.5

// Install RG.Redux as a Cake Tool
#tool nuget:?package=RG.Redux&version=1.0.5                

RG.Redux

NuGet

A minimal Redux implementation

Creating Events, Reducer, and Store

// Events
public interface IFooEvent : IEvent { }
public record FooIncremented() : IFooEvent;
public record FooDecremented() : IFooEvent;
public record FooIncrementedBy(int Value) : IFooEvent;
public record FooReset() : IFooEvent;

// Store and Reducer
public record FooStore() : Store<int, IFooEvent>(
    reducer: (state, action) =>
        action switch {
            FooIncremented => state + 1,
            FooDecremented => state - 1,
            FooIncrementedBy { Value: var val } => state + val,
            FooReset => 0,
            _ => state
        }.
    initialState: 0
);

// Creating a Store instance
var fooStore = new FooStore();

Reading State

var state = fooStore.State;

Dispatching Event

fooStore.Dispatch(new FooDecremented());

Subscribing to Store updates

var subscription = fooStore.Subscribe(value => {
    Console.WriteLine(value);
});

Unsubscribing from Store updates

subscription.Dispose();

Querying Store updates using Reactive.Linq

var query = from value in fooStore
            where value % 2 == 0
            select value / 2;

var subscription = query.Subscribe(value => {
    Console.WriteLine(value);
});

Don't need event types?

Just mutate the State property

public record FooStore() : Store<int>(initialState: 0) {
    public void Increment() => State++;
    public void Decrement() => State--;
    public void IncrementBy(int x) => State += x;
    public void Reset() => State = 0;
}
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible. 
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
1.0.5 55 11/13/2024
1.0.4 1,442 1/6/2023
1.0.3 325 1/6/2023
1.0.2 297 1/6/2023
1.0.1 327 12/10/2022
1.0.0 277 12/10/2022