From d918f4b45a790aa424d81e3f4f2182cac7dc0690 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Thu, 20 Sep 2018 16:32:35 +0200 Subject: [PATCH] flowtype: allow middleware to use async/await + add new action type (PayloadAction) --- src/flowtype/index.js | 2 ++ src/flowtype/npm/redux_v3.x.x.js | 16 +++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/flowtype/index.js b/src/flowtype/index.js index ece6a996..6217abe3 100644 --- a/src/flowtype/index.js +++ b/src/flowtype/index.js @@ -6,6 +6,7 @@ import type { MiddlewareAPI as ReduxMiddlewareAPI, Middleware as ReduxMiddleware, ThunkAction as ReduxThunkAction, + PayloadAction as ReduxPayloadAction, AsyncAction as ReduxAsyncAction, PromiseAction as ReduxPromiseAction, ThunkDispatch as ReduxThunkDispatch, @@ -164,6 +165,7 @@ export type MiddlewareAPI = ReduxMiddlewareAPI; export type Middleware = ReduxMiddleware; export type ThunkAction = ReduxThunkAction; +export type PayloadAction = ReduxPayloadAction; export type AsyncAction = ReduxAsyncAction; export type PromiseAction = ReduxPromiseAction; diff --git a/src/flowtype/npm/redux_v3.x.x.js b/src/flowtype/npm/redux_v3.x.x.js index cdd88212..5e42f2f1 100644 --- a/src/flowtype/npm/redux_v3.x.x.js +++ b/src/flowtype/npm/redux_v3.x.x.js @@ -2,7 +2,6 @@ declare module 'redux' { /* - S = State A = Action D = Dispatch @@ -16,28 +15,27 @@ declare module 'redux' { declare export type ThunkAction = (dispatch: ReduxDispatch, getState: () => S) => void; declare export type AsyncAction = (dispatch: ReduxDispatch, getState: () => S) => Promise; declare export type PromiseAction = (dispatch: ReduxDispatch, getState: () => S) => Promise; + declare export type PayloadAction = (dispatch: ReduxDispatch, getState: () => S) => R; declare export type ThunkDispatch = (action: ThunkAction) => void; declare export type AsyncDispatch = (action: AsyncAction) => Promise; declare export type PromiseDispatch = (action: PromiseAction) => Promise; + declare export type PayloadDispatch = (action: PayloadAction) => R; declare export type PlainDispatch}> = DispatchAPI; /* NEW: Dispatch is now a combination of these different dispatch types */ - declare export type ReduxDispatch = PlainDispatch & ThunkDispatch & AsyncDispatch & PromiseDispatch; + declare export type ReduxDispatch = PlainDispatch & ThunkDispatch & AsyncDispatch & PromiseDispatch & PayloadDispatch; declare export type MiddlewareAPI = { - // dispatch: Dispatch; - // dispatch: (action: A | ThunkAction) => A | void; - // dispatch: PlainDispatch | () => A; - // dispatch: ( A | ThunkAction | void ) => void; dispatch: ReduxDispatch; - // dispatch: Dispatch; - // dispatch: D; getState(): S; }; + declare export type ReduxDispatchAPI = (action: A) => Promise; + declare export type Middleware = (api: MiddlewareAPI) => - (next: PlainDispatch) => PlainDispatch; + (next: PlainDispatch) => + (PlainDispatch | (action: A) => Promise); declare export type Store> = { // rewrite MiddlewareAPI members in order to get nicer error messages (intersections produce long messages)