Skip to content

Instantly share code, notes, and snippets.

@emyann
Created January 5, 2019 20:10
Show Gist options
  • Save emyann/2cdd4e260a04fa5fe3bfa0587cdda3ee to your computer and use it in GitHub Desktop.
Save emyann/2cdd4e260a04fa5fe3bfa0587cdda3ee to your computer and use it in GitHub Desktop.
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