MentorLake.Redux
1.0.8
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.8
NuGet\Install-Package MentorLake.Redux -Version 1.0.8
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.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MentorLake.Redux --version 1.0.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MentorLake.Redux, 1.0.8"
#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.8
// Install MentorLake.Redux as a Cake Tool
#tool nuget:?package=MentorLake.Redux&version=1.0.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Getting Started
Create 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 reducers:
public static class MyReducers
{
public static readonly FeatureReducerCollection Reducers =
[
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 })
];
}
Create and setup redux store:
var store = new ReduxStore();
store.RegisterReducers(MyReducers.Reducers);
Dispatch actions:
store.Dispatch(new UpdateFirstNameAction("Bob"));
Selectors
Creating selectors:
public class MySelectors
{
public static readonly ISelector<PersonState> Person = SelectorFactory.CreateFeature<PersonState>();
public static readonly ISelector<string> FirstName = SelectorFactory.Create(Person, s => s.FirstName);
public static readonly ISelector<AddressState> Address = SelectorFactory.CreateFeature<AddressState>();
public static readonly ISelector<string> ZipCode = SelectorFactory.Create(Address, s => s.ZipCode);
}
Using a selector:
store.Select(MySelectors.FirstName).Subscribe(firstName => Console.WriteLine(firstName));
Custom comparison function:
private bool CompareFirstNamesOnly(PersonState x, PersonState y)
{
if (ReferenceEquals(x, y)) return true;
if (x == null || y == null) return false;
return x.FirstName.Equals(y.FirstName);
}
var personSelector = SelectorFactory.Create(MySelectors.Person, p => p, CompareFirstNamesOnly);
// or
var personSelector = SelectorFactory.Create(MySelectors.Person.WithComparer(CompareFirstNamesOnly), p => p);
Effects
public class MyEffects(PersonService personService) : IEffectsFactory
{
public IEnumerable<Effect> Create() => new[]
{
EffectsFactory.CreateEffect<SavePersonAction>(async action =>
{
await personService.SavePerson(action.Person);
return new List<object>() { new SavePersonCompleteAction() };
})
};
}
It's best to register effects by resolving them from a DI container. For example:
var serviceCollection = new ServiceCollection();
serviceCollection.AddTransient<IEffectsFactory, MyEffects>();
serviceCollection.AddTransient<PersonService>();
var serviceProvider = serviceCollection.BuildServiceProvider();
var store = new ReduxStore();
store.RegisterEffects(serviceProvider.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.