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.
<PackageVersion Include="RG.Redux" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="RG.Redux" />
                    
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 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.
#addin nuget:?package=RG.Redux&version=1.0.5
                    
Install RG.Redux as a Cake Addin
#tool nuget:?package=RG.Redux&version=1.0.5
                    
Install RG.Redux as a Cake Tool

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.  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. 
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 221 11/13/2024
1.0.4 1,463 1/6/2023
1.0.3 345 1/6/2023
1.0.2 317 1/6/2023
1.0.1 348 12/10/2022
1.0.0 297 12/10/2022