Redux 1.0.6
See the version list below for details.
dotnet add package Redux --version 1.0.6
NuGet\Install-Package Redux -Version 1.0.6
<PackageReference Include="Redux" Version="1.0.6" />
paket add Redux --version 1.0.6
#r "nuget: Redux, 1.0.6"
// Install Redux as a Cake Addin #addin nuget:?package=Redux&version=1.0.6 // Install Redux as a Cake Tool #tool nuget:?package=Redux&version=1.0.6
Redux mini for .NET
It's simple "application state" container implementation like Redux for JavaScript.
How does it work?
Application state container is just plain IDictionary<string, object>
instance.
You can manage application state with just three methods of Store instance:
public interface Store
{
void Dispatch(Message message);
IDictionary<string, object> GetState();
Action Subscribe(Action<Message> handler);
}
"Send" Message
to Store
with Dispatch
method:
string type = "User";
User user = new User()
{
Email = "joedoe@mail.local"
};
Message message = new Message(type, user);
store.Dispatch(message);
Get application container state from Store
with GetState
method:
IDictionary<string, object> state = store.GetState();
User user = state["User"] as User;
Know about application state change with Subscribe
method:
public class CustomHandler
{
private Store store;
public CustomHandler(Store store)
{
this.store = store;
}
public void Handle(Message message)
{
IDictionary<string, object> state = this.store.GetState();
/// React state change here
}
}
CustomHandler handler = new CustomHandler(store);
Action unsubscribe = store.Subscribe(handler.Handle);
How to configure own application container?
Make a collection of Reducer
-s with built-in tools:
List<Reducer> reducers = new List<Reducer>();
reducers.Add(new ReducerImpl("Order"));
reducers.Add(new ReducerImpl("Payment"));
reducers.Add(new ReducerImpl("Withdrawal"));
reducers.Add(new ExceptionReducerImpl());
/// And pass it to constructor of
/// built-in Store implementation
Store store = new StoreImpl(reducers);
And you are ready to play with your application container. As you can see it knows about four Message
types:
- "Order"
- "Payment"
- "Withdrawal"
- "Exception"
It will ignore any other unknown type Message
-s.
Tool to get value from state container
There is built-in StoreValueProvider
utility:
Order order = new Order();
Message message = new Message("Order", order);
store.Dispatch(message);
StoreValueProvider provider = new StoreValueProviderImpl();
provider.setStore(store);
provider.setKey("Order");
Assert.Equal(order, provider.get<Order>());
Assert.Equal(order, provider.get(typeof(Order)));
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. |
.NET Core | netcoreapp2.2 is compatible. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
This package has 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.
Typed 'object get(Type type)' method has been implemented in StoreValueProviderImpl.