Created
January 5, 2019 20:10
-
-
Save emyann/2cdd4e260a04fa5fe3bfa0587cdda3ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Action } from 'redux'; | |
import { ThunkAction } from 'redux-thunk'; | |
import { AppState } from '../reducers'; | |
export type AppAction<A = Action, P = any> = A & { payload: P }; | |
export function makeActionCreator<P, T extends string = string>(type: T) { | |
function actionCreator(payload?: P): AppAction<Action<typeof type>, P> { | |
return { | |
type, | |
payload: payload ? payload : ({} as any), | |
}; | |
} | |
return actionCreator; | |
} | |
export function makeAsyncActionCreator<P, T>(callback: ThunkAction<any, AppState, any, AppAction<Action<T>, P>>) { | |
return () => callback; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment