MentorLake.Redux 1.0.4

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

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

Getting Started

Create your state types:

public record PersonState(string FirstName, string LastName);
public record AddressState(string ZipCode);

Create action types:

public record UpdateFirstNameAction(string FirstName);
public record UpdateLastNameAction(string LastName);
public record ZipCodeUpdatedAction(string ZipCode);

Create the store and register your reducers:

var store = new ReduxStore();

store.RegisterReducers(new FeatureReducerCollection()
{
	FeatureReducer.Build(new PersonState("Hello", "World"))
		.On<UpdateFirstNameAction>((state, action) => state with { FirstName = action.FirstName })
		.On<UpdateLastNameAction>((state, action) => state with { LastName = action.LastName }),
	FeatureReducer.Build(new AddressState(12345))
		.On<ZipCodeUpdatedAction>((state, action) => state with { ZipCode = action.ZipCode })
});

Dispatch actions:

store.Dispatch(new UpdateFirstNameAction("Bob"));

Selectors

Creating selectors:

public class MySelectors
{
	public static readonly ISelector<PersonState> Person = SelectorFactory.CreateFeatureSelector<PersonState>();
	public static readonly ISelector<string> FirstName = SelectorFactory.CreateSelector(Person, s => s.FirstName);

	public static readonly ISelector<AddressState> Address = SelectorFactory.CreateFeatureSelector<AddressState>();
	public static readonly ISelector<string> ZipCode = SelectorFactory.CreateSelector(Address, s => s.ZipCode);
}

Using the selector:

store.Select(MySelectors.FirstName).Subscribe(firstName => Console.WriteLine(firstName));

Effects

public class MyEffects(PersonService personService) : IEffectsFactory
{
	public IEnumerable<Effect> Create() => new[]
	{
		EffectsFactory.CreateEffect<SaveUserAction>(action => personService.SaveUser(action.User));
	};
}

It's best to register effects by resolving them from a DI container. For example:

store.RegisterEffects(host.Services.GetServices<IEffectsFactory>().ToArray());
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
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.1.2 133 1/26/2024
1.1.1 75 1/25/2024
1.0.8 82 1/22/2024
1.0.7 83 1/20/2024
1.0.5 79 1/19/2024
1.0.4 73 1/19/2024
1.0.2 74 1/19/2024
1.0.1 63 1/19/2024
1.0.0 90 1/19/2024
0.1.9 73 1/19/2024