Redux 1.0.11

Predictable state container for .NET C#

Install-Package Redux -Version 1.0.11
dotnet add package Redux --version 1.0.11
<PackageReference Include="Redux" Version="1.0.11" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Redux --version 1.0.11
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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&lt;string, object&gt; 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)));

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&lt;string, object&gt; 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)));

Release Notes

Reducers types check has been added to StoreImpl constructor. canGet method has been defined in StoreValueProvider.

  • .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.

Version History

Version Downloads Last updated
1.0.11 273 11/7/2019
1.0.10 88 11/3/2019
1.0.9 108 11/3/2019
1.0.6 297 7/7/2019
1.0.5 153 7/6/2019
1.0.3 163 7/2/2019
1.0.2 170 6/24/2019
1.0.1 188 6/15/2019
1.0.0 402 1/9/2019