using System; namespace Unity.UIWidgets.Redux { public static class ReduxThunk { public static Middleware create() { return store => next => new DispatcherImpl(action => { var thunkAction = action as ThunkAction; if (thunkAction != null && thunkAction.action != null) { return thunkAction.action(store.dispatcher, store.getState); } return next.dispatch(action); }); } } public sealed class ThunkAction { public readonly Func, object> action; public readonly string displayName; public ThunkAction( Func, object> action = null, string displayName = null) { this.action = action; this.displayName = displayName ?? ""; } public override string ToString() { return "ThunkAction(" + displayName + ")"; } } }