Add redux-promise-middleware

This commit is contained in:
Ian Ker-Seymer
2016-01-07 22:25:28 -05:00
parent 81b951f1ac
commit e7df72296e
2 changed files with 58 additions and 0 deletions
@@ -0,0 +1,46 @@
/// <reference path="../redux/redux.d.ts" />
/// <reference path="./redux-promise-middleware.d.ts" />
import { createStore, applyMiddleware, Store, Dispatch } from "redux";
import promiseMiddleware from "redux-promise-middleware";
declare var rootReducer: Function;
declare var Promise: any;
declare var doSomethingAsyncAndReturnPromise: any;
declare var someActionCreator: any;
const createStoreWithMiddleware = applyMiddleware(
promiseMiddleware()
)(createStore);
const store: Store = createStoreWithMiddleware(rootReducer);
export function myAsyncActionCreator(data: any) {
return {
type: "ACTION",
payload: {
promise: doSomethingAsyncAndReturnPromise(data),
data: data
}
};
}
const actionCreator1 = () => ({
type: "FIRST_ACTION_TYPE",
payload: {
promise: Promise.resolve({
type: "SECOND_ACTION_TYPE",
payload: "...",
})
}
});
const actionCreator2 = () => ({
type: "FIRST_ACTION_TYPE",
payload: {
promise: Promise.resolve((action: string, dispatch: Redux.Dispatch, getState: Function) => {
dispatch({ type: "SECEOND_ACTION_TYPE", payload: "..." });
dispatch(someActionCreator());
})
}
});
+12
View File
@@ -0,0 +1,12 @@
// Type definitions for redux-promise-middleware
// Project: https://github.com/pburtchaell/redux-promise-middleware
// Definitions by: ianks <https://github.com/ianks>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path='../redux/redux.d.ts' />
declare module "redux-promise-middleware" {
function promiseMiddleware(config?: { promiseTypeSuffixes: string[] }): Redux.Middleware;
export default promiseMiddleware;
}