1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-24 09:18:09 +00:00

flowtype: allow middleware to use async/await + add new action type (PayloadAction)

This commit is contained in:
Szymon Lesisz 2018-09-20 16:32:35 +02:00
parent c9b9359e70
commit d918f4b45a
2 changed files with 9 additions and 9 deletions

View File

@ -6,6 +6,7 @@ import type {
MiddlewareAPI as ReduxMiddlewareAPI, MiddlewareAPI as ReduxMiddlewareAPI,
Middleware as ReduxMiddleware, Middleware as ReduxMiddleware,
ThunkAction as ReduxThunkAction, ThunkAction as ReduxThunkAction,
PayloadAction as ReduxPayloadAction,
AsyncAction as ReduxAsyncAction, AsyncAction as ReduxAsyncAction,
PromiseAction as ReduxPromiseAction, PromiseAction as ReduxPromiseAction,
ThunkDispatch as ReduxThunkDispatch, ThunkDispatch as ReduxThunkDispatch,
@ -164,6 +165,7 @@ export type MiddlewareAPI = ReduxMiddlewareAPI<State, Action>;
export type Middleware = ReduxMiddleware<State, Action>; export type Middleware = ReduxMiddleware<State, Action>;
export type ThunkAction = ReduxThunkAction<State, Action>; export type ThunkAction = ReduxThunkAction<State, Action>;
export type PayloadAction<R> = ReduxPayloadAction<State, Action, R>;
export type AsyncAction = ReduxAsyncAction<State, Action>; export type AsyncAction = ReduxAsyncAction<State, Action>;
export type PromiseAction<R> = ReduxPromiseAction<State, Action, R>; export type PromiseAction<R> = ReduxPromiseAction<State, Action, R>;

View File

@ -2,7 +2,6 @@
declare module 'redux' { declare module 'redux' {
/* /*
S = State S = State
A = Action A = Action
D = Dispatch D = Dispatch
@ -16,28 +15,27 @@ declare module 'redux' {
declare export type ThunkAction<S, A> = (dispatch: ReduxDispatch<S, A>, getState: () => S) => void; declare export type ThunkAction<S, A> = (dispatch: ReduxDispatch<S, A>, getState: () => S) => void;
declare export type AsyncAction<S, A> = (dispatch: ReduxDispatch<S, A>, getState: () => S) => Promise<void>; declare export type AsyncAction<S, A> = (dispatch: ReduxDispatch<S, A>, getState: () => S) => Promise<void>;
declare export type PromiseAction<S, A, R> = (dispatch: ReduxDispatch<S, A>, getState: () => S) => Promise<R>; declare export type PromiseAction<S, A, R> = (dispatch: ReduxDispatch<S, A>, getState: () => S) => Promise<R>;
declare export type PayloadAction<S, A, R> = (dispatch: ReduxDispatch<S, A>, getState: () => S) => R;
declare export type ThunkDispatch<S, A> = (action: ThunkAction<S, A>) => void; declare export type ThunkDispatch<S, A> = (action: ThunkAction<S, A>) => void;
declare export type AsyncDispatch<S, A> = (action: AsyncAction<S, A>) => Promise<void>; declare export type AsyncDispatch<S, A> = (action: AsyncAction<S, A>) => Promise<void>;
declare export type PromiseDispatch<S, A> = <R>(action: PromiseAction<S, A, R>) => Promise<R>; declare export type PromiseDispatch<S, A> = <R>(action: PromiseAction<S, A, R>) => Promise<R>;
declare export type PayloadDispatch<S, A> = <R>(action: PayloadAction<S, A, R>) => R;
declare export type PlainDispatch<A: {type: $Subtype<string>}> = DispatchAPI<A>; declare export type PlainDispatch<A: {type: $Subtype<string>}> = DispatchAPI<A>;
/* NEW: Dispatch is now a combination of these different dispatch types */ /* NEW: Dispatch is now a combination of these different dispatch types */
declare export type ReduxDispatch<S, A> = PlainDispatch<A> & ThunkDispatch<S, A> & AsyncDispatch<S, A> & PromiseDispatch<S, A>; declare export type ReduxDispatch<S, A> = PlainDispatch<A> & ThunkDispatch<S, A> & AsyncDispatch<S, A> & PromiseDispatch<S, A> & PayloadDispatch<S, A>;
declare export type MiddlewareAPI<S, A> = { declare export type MiddlewareAPI<S, A> = {
// dispatch: Dispatch<S, A>;
// dispatch: (action: A | ThunkAction<S, A>) => A | void;
// dispatch: PlainDispatch<A> | () => A;
// dispatch: ( A | ThunkAction<S, A> | void ) => void;
dispatch: ReduxDispatch<S, A>; dispatch: ReduxDispatch<S, A>;
// dispatch: Dispatch<S, A>;
// dispatch: D;
getState(): S; getState(): S;
}; };
declare export type ReduxDispatchAPI<A> = (action: A) => Promise<A>;
declare export type Middleware<S, A> = declare export type Middleware<S, A> =
(api: MiddlewareAPI<S, A>) => (api: MiddlewareAPI<S, A>) =>
(next: PlainDispatch<A>) => PlainDispatch<A>; (next: PlainDispatch<A>) =>
(PlainDispatch<A> | (action: A) => Promise<A>);
declare export type Store<S, A, D = ReduxDispatch<S, A>> = { declare export type Store<S, A, D = ReduxDispatch<S, A>> = {
// rewrite MiddlewareAPI members in order to get nicer error messages (intersections produce long messages) // rewrite MiddlewareAPI members in order to get nicer error messages (intersections produce long messages)