MentorLake.Redux
1.0.4
There is a newer version of this package available.
See the version list below for details.
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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 | Versions 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.
-
net8.0
- System.Reactive (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.