Skip to content

Dispatch with strongly-typed promise return types #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ export type PayloadlessMutationHandler<TModuleState> =

export type ActionHandler<TModuleState, TRootState, TPayload> =
(injectee: ActionContext<TModuleState, TRootState>, payload: TPayload) => void | Promise<any>;
export type PromiseActionHandler<TModuleState, TRootState, TPayload, TPromise> =
(injectee: ActionContext<TModuleState, TRootState>, payload: TPayload) => Promise<TPromise>;
export type PayloadlessActionHandler<TModuleState, TRootState> =
(injectee: ActionContext<TModuleState, TRootState>) => void | Promise<any>;
export type PromisePayloadlessActionHandler<TModuleState, TRootState, TPromise> =
(injectee: ActionContext<TModuleState, TRootState>) => Promise<TPromise>;

export type GetterHandler<TModuleState, TRootState, TResult> =
(state: TModuleState, rootState: TRootState) => TResult;
Expand All @@ -27,6 +31,11 @@ export type DispatchAccessor<TModuleState, TRootState, TPayload> =
payload: TPayload) => Promise<any[]>;
export type PayloadlessDispatchAccessor<TModuleState, TRootState> =
(store: Store<TRootState> | ActionContext<TModuleState, TRootState>) => Promise<any[]>;
export type PromiseDispatchAccessor<TModuleState, TRootState, TPayload, TPromise> =
(store: Store<TRootState> | ActionContext<TModuleState, TRootState>,
payload: TPayload) => Promise<TPromise>;
export type PromisePayloadlessDispatchAccessor<TModuleState, TRootState, TPromise> =
(store: Store<TRootState> | ActionContext<TModuleState, TRootState>) => Promise<TPromise>;

export type CommitAccessor<TModuleState, TRootState, TPayload> =
(store: Store<TRootState> | ActionContext<TModuleState, TRootState>,
Expand All @@ -42,12 +51,18 @@ export interface StoreAccessors<TModuleState, TRootState> {
handler: PayloadlessMutationHandler<TModuleState>):
PayloadlessCommitAccessor<TModuleState, TRootState>;

dispatch<TPayload, TPromise>(
handler: PromiseActionHandler<TModuleState, TRootState, TPayload, TPromise>):
PromiseDispatchAccessor<TModuleState, TRootState, TPayload, TPromise>;
dispatch<TPayload>(
handler: ActionHandler<TModuleState, TRootState, TPayload>):
DispatchAccessor<TModuleState, TRootState, TPayload>;
dispatchNoPayload(
handler: PayloadlessActionHandler<TModuleState, TRootState>):
PayloadlessDispatchAccessor<TModuleState, TRootState>;
dispatchNoPayload<TPromise>(
handler: PromisePayloadlessActionHandler<TModuleState, TRootState, TPromise>):
PromisePayloadlessDispatchAccessor<TModuleState, TRootState, TPromise>;

read<TResult>(
handler: GetterHandler<TModuleState, TRootState, TResult>):
Expand Down