Thunk middleware for Redux.NET
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
redux.NET-thunk.AndroidExample Formatting Jan 15, 2016
redux.NET-thunk.Tests
redux.NET-thunk Added nuspec Jan 11, 2016
.gitignore
LICENSE Added nuspec Jan 11, 2016
README.md Added readme Jan 15, 2016
redux.NET-thunk.sln Added example project Jan 15, 2016

README.md

Redux.NET-thunk

This is an implementation of the Redux thunk middleware for use with the Redux.NET library.

NuGet

Installation

Install directly from the NuGet package, or from the Package Manager Console by running:

Install-Package redux.NET-thunk

Apply the middleware by passing it as a parameter to the Store constructor:

var store = new Store<State>(initialState, reducer, Taiste.Redux.Middleware.ThunkMiddleware);

Usage

Thunk middleware can be used to create Redux actions that dispatch other actions for conditional or asynchronous dispatching.

Example conditional dispatch:

public static IAction ConditionalIncrement ()
{
    return new ThunkAction<int> ((dispatch, getState) => {
        int state = getState ();

        if (state < 10) {
            dispatch(new IncrementAction());
        }
    });
}

...

store.Dispatch(ConditionalIncrement());

Asynchronous dispatch:

public static IAction AsyncActionCreator ()
{
    return new ThunkAction<ApplicationState> ((dispatch, getState) => {
        Task.Factory.StartNew (() => {
            var result = expensiveOperation ();
            dispatch (new ResultAction (result));
        });
    });
}

...

store.Dispatch(AsyncActionCreator());

Notes

Unlike the Javascript version, this version of the middleware considers Dispatch to be a void action, i.e. no Promise or similar is returned from Dispatch. The dispatched ThunkAction is returned to satisfy the interface.