How do you feel about reduction flow?

I am currently doing the following:

export type Action =
   { type: 'FOO' }
 | { type: 'BAR' }

export type Thunk = (dispatch: Dispatch, getState: GetState) => Action | Thunk 

export type Dispatch = ReduxDispatch<Action> & (action: Thunk) => void

but if you send directly to store, this will not work without re-creating store:

export type Store = ReduxStore<State, Action>

All in all, my thunk solution has other minor issues. Does anyone have a working library definition for redux-thunk? I can’t find anything.

+4
source share
1 answer

The best example I have found so far are those used in the F8 Facebook app here .

It is very similar to yours:

export type Dispatch = (action: Action | ThunkAction | PromiseAction | Array<Action>) => any;
export type GetState = () => Object;
export type ThunkAction = (dispatch: Dispatch, getState: GetState) => any;
export type PromiseAction = Promise<Action>;

In my project, it worked very well, although I do not send it directly to the store.

+4

Source: https://habr.com/ru/post/1667484/


All Articles