ReduxSharp 1.0.0
dotnet add package ReduxSharp --version 1.0.0
NuGet\Install-Package ReduxSharp -Version 1.0.0
<PackageReference Include="ReduxSharp" Version="1.0.0" />
<PackageVersion Include="ReduxSharp" Version="1.0.0" />
<PackageReference Include="ReduxSharp" />
paket add ReduxSharp --version 1.0.0
#r "nuget: ReduxSharp, 1.0.0"
#:package ReduxSharp@1.0.0
#addin nuget:?package=ReduxSharp&version=1.0.0
#tool nuget:?package=ReduxSharp&version=1.0.0
ReduxSharp
Unidirectional Data Flow in C# - Inspired by Redux
About
There is a library in JavaScript called Redux. If you have ever developed a Single Page Application with React, you may have used it. For more information on Redux, please read the official documentation.
ReduxSharp is a port of Redux to C#.
Installation
First, install Nuget. Then, install ReduxSharp from the package manager console:
PM> Install-Package ReduxSharp
Quick-start
State
Define a class that represents a state of the app.
namespace HelloWorld
{
public class AppState
{
public AppState(int count) => Count = count;
public int Count { get; }
}
}
Actions
Define actions. Actions are payloads of information that send data from your application to your store.
namespace HelloWorld
{
public readonly struct Increment
{
}
public readonly struct Decrement
{
}
}
Reducers
Define a reducer.
A reducer need to implement the interface IReducer<TState>.
It describes how an action transforms the state into the next state.
using System;
using ReduxSharp;
namespace HelloWorld
{
public class AppReducer : IReducer<AppState>
{
public AppState Invoke<TAction>(AppState state, TAction action)
{
switch (action)
{
case Increment _:
return new AppState(state.Count + 1);
case Decrement _:
return new AppState(state.Count - 1);
default:
return state;
}
}
}
}
Store
Build a store using StoreBuilder<TState>.
The Store<TState> is the class that bring actions and reducer together.
The store has the following responsibilities:
- Holds application state of type TState.
- Allows state to be update via
Dispatch<TAction>(TAction action). - Registers listeners via
Subscribe(IObserver observer).TheStore<TState>class implements IObservable.
Pass the initial state to the builder and the reducer to Build.
using System;
using ReduxSharp;
namespace HelloWorld
{
class Program : IObserver<AppState>
{
static void Main(string[] args)
{
Store<AppState> store = new StoreBuilder<AppState>(new AppState(0)).Build(new AppReducer());
var observer = new Program();
using (store.Subscribe(observer))
{
// Prints 1.
store.Dispatch(new Increment());
// Prints 2.
store.Dispatch(new Increment());
// Prints 1.
store.Dispatch(new Decrement());
// Prints 2.
store.Dispatch(new Increment());
}
}
public void OnNext(AppState value) =>
Console.WriteLine(value.Count);
public void OnCompleted()
{
}
public void OnError(Exception error)
{
}
}
}
Middleware
Register factories in execution order with Use, then call Build.
Each store builds the chain once per dispatched action type and caches it.
The factory can capture per-store, per-action-type data when building the delegate.
using System;
using ReduxSharp;
public sealed class ConsoleLoggingMiddleware<TState> : IMiddlewareFactory<TState>
{
public Action<TAction> Build<TAction>(IStore<TState> store, Action<TAction> next)
{
string actionName = typeof(TAction).Name;
return action =>
{
Console.WriteLine($"Dispatching {actionName}");
next(action);
Console.WriteLine($"Dispatched {actionName}");
};
}
}
Store<AppState> store = new StoreBuilder<AppState>(new AppState(0))
.Use(new ConsoleLoggingMiddleware<AppState>())
.Build(new AppReducer());
store.Dispatch(new Increment());
Registration extensions can accept and return IStoreBuilder<TState>. See the
logging extension.
Migrating from the old API. Replace new Store<TState>(reducer, state) with
new StoreBuilder<TState>(state).Build(reducer). For each old middleware,
move the per-dispatch body of IMiddleware.Invoke into the delegate returned by
IMiddlewareFactory.Build, as shown above. Replace next.Invoke(action) with
next(action) to continue the current chain. To send another action type, call
store.Dispatch(otherAction) to start its pipeline at the first middleware.
Existing reducers and async action creators can be reused.
Examples
Publishing to NuGet.org
Publishing a GitHub Release runs the Publish NuGet package workflow for the
release commit. Both stable and prerelease versions are supported. Creating or
pushing a tag alone does not publish a package.
One-time setup
- On NuGet.org, sign in as an owner of the
ReduxSharppackage and add a Trusted Publishing policy with repository ownertnakamura, repositoryReduxSharp, and workflow filepublish-nuget.yml(the filename only). Leave the environment empty. In Glob Patterns and Packages (Separate by a new line), enterReduxSharpon a single line to restrict publishing to this package ID. Do not include a version number or a.nupkgextension. - In the GitHub repository's Settings > Secrets and variables > Actions, add
the repository secret
NUGET_USERcontaining that owner's NuGet.org username (not an email address). No long-lived NuGet API key is required. - Merge the publishing workflow before creating a release tag so the tagged commit includes the workflow.
Publish a version
- Update
Versioninsrc/ReduxSharp/ReduxSharp.csproj, then commit and merge the change.AssemblyVersionandFileVersionare derived automatically fromVersionwithout its prerelease suffix (for example,1.0.0becomes1.0.0.0). - Create and push a tag matching
Versionexactly, such as0.6.0or0.6.0-beta.1. Use three numeric components without leading zeroes, optionally followed by a SemVer prerelease suffix; do not add avprefix or build metadata. - Create a GitHub Release using that tag, prepare its release notes, and select Publish release. For a prerelease version, mark the release as a prerelease.
- Check the workflow in Actions. It validates the tag against the evaluated project version, builds, checks formatting, runs tests, and validates the generated package versions before obtaining a short-lived publishing key.
The workflow saves .nupkg and .snupkg files as Actions artifacts and publishes
both to NuGet.org. If a run fails, fix the setup issue and use Re-run failed jobs;
already published packages are skipped, and symbols are pushed separately so a
partial publication can be retried. A published NuGet version cannot be replaced;
code changes require a new version and release. Keep release tags unchanged.
License
| Product | Versions 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. 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. |
| .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. |
-
.NETStandard 2.0
- No dependencies.
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.0 | 100 | 11/19/2026 |
| 0.5.1 | 1,850 | 10/8/2019 |
| 0.5.0 | 1,598 | 9/18/2019 |
| 0.4.1 | 1,668 | 9/13/2019 |
| 0.4.0 | 1,651 | 9/12/2019 |
| 0.4.0-beta2 | 1,456 | 9/11/2019 |
| 0.4.0-beta | 1,506 | 9/11/2019 |
| 0.4.0-alpha | 1,465 | 9/10/2019 |
| 0.3.0 | 2,414 | 5/18/2018 |
| 0.2.0 | 2,462 | 9/4/2017 |
| 0.1.0 | 2,197 | 4/28/2017 |
| 0.0.9 | 2,199 | 3/27/2017 |
| 0.0.8 | 2,163 | 3/24/2017 |
| 0.0.7 | 2,291 | 3/13/2017 |
| 0.0.6 | 2,232 | 3/1/2017 |
| 0.0.5 | 2,534 | 11/8/2016 |
| 0.0.4 | 2,246 | 10/14/2016 |
| 0.0.3 | 2,244 | 10/7/2016 |
| 0.0.2 | 2,356 | 9/20/2016 |
| 0.0.1 | 2,528 | 9/20/2016 |