mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-03 19:51:53 +00:00
Add redux-promise-middleware
This commit is contained in:
@@ -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());
|
||||
})
|
||||
}
|
||||
});
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user