Redux 1.0.11
dotnet add package Redux --version 1.0.11
NuGet\Install-Package Redux -Version 1.0.11
<PackageReference Include="Redux" Version="1.0.11" />
paket add Redux --version 1.0.11
#r "nuget: Redux, 1.0.11"
// Install Redux as a Cake Addin #addin nuget:?package=Redux&version=1.0.11 // Install Redux as a Cake Tool #tool nuget:?package=Redux&version=1.0.11
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.True(provider.canGet<Order>());
Assert.True(provider.canGet(typeof(Order)));
Assert.Equal(order, provider.get<Order>());
Assert.Equal(order, provider.get(typeof(Order)));
Assert.False(provider.canGet<User>());
Assert.False(provider.canGet(typeof(User)));
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.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 is compatible. netcoreapp3.0 is compatible. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.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. |
-
.NETCoreApp 2.2
- No dependencies.
-
.NETCoreApp 3.0
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- 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.
Reducers types check has been added to StoreImpl constructor. canGet method has been defined in StoreValueProvider.