Skip to content

Commit 15c0f90

Browse files
author
Ben Crowl
committed
Add optional names to commit/dispatch
1 parent f2ee61b commit 15c0f90

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/index.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import { ActionContext, ActionTree, GetterTree, Module, MutationTree, Store } fr
44
const useRootNamespace = { root: true }
55

66
export type MutationHandler<S, P> = (state: S, payload: P) => void
7-
// export type PayloadlessMutationHandler<S> = (state: S) => void
8-
97
export type ActionHandler<S, R, P, T> = (context: BareActionContext<S, R>, payload: P) => Promise<T>
10-
// export type PayloadlessActionHandler<S, R, T> = (context: BareActionContext<S, R>) => Promise<T>
11-
// export type VoidActionHandler<S, R, P> = (context: BareActionContext<S, R>, payload: P) => void
12-
// export type VoidPayloadlessActionHandler<S, R> = (context: BareActionContext<S, R>) => void
138
export type GetterHandler<S, R, T> = (state: S, rootState: R) => T
149

1510
export interface BareActionContext<S, R>
@@ -34,19 +29,25 @@ export class ModuleBuilder<S, R> {
3429

3530
commit<P>(handler: MutationHandler<S, void>): () => void
3631
commit<P>(handler: MutationHandler<S, P>): (payload: P) => void
37-
commit<P>(handler: MutationHandler<S, P>)
32+
commit<P>(handler: MutationHandler<S, void>, name: string): () => void
33+
commit<P>(handler: MutationHandler<S, P>, name: string): (payload: P) => void
34+
commit<P>(handler: MutationHandler<S, P>, name?: string)
3835
{
39-
const key = qualifyKey(handler, this.namespace)
36+
const key = qualifyKey(handler, this.namespace, name)
4037
return ((payload: P) => this.store.commit(key, payload, useRootNamespace)) as any
4138
}
4239

4340
dispatch<P, T>(handler: ActionHandler<S, R, void, void>): () => Promise<void>
4441
dispatch<P, T>(handler: ActionHandler<S, R, P, void>): (payload: P) => Promise<void>
4542
dispatch<P, T>(handler: ActionHandler<S, R, void, T>): () => Promise<T>
4643
dispatch<P, T>(handler: ActionHandler<S, R, P, T>): (payload: P) => Promise<T>
47-
dispatch<P, T>(handler: any): any
44+
dispatch<P, T>(handler: ActionHandler<S, R, void, void>, name: string): () => Promise<void>
45+
dispatch<P, T>(handler: ActionHandler<S, R, P, void>, name: string): (payload: P) => Promise<void>
46+
dispatch<P, T>(handler: ActionHandler<S, R, void, T>, name: string): () => Promise<T>
47+
dispatch<P, T>(handler: ActionHandler<S, R, P, T>, name: string): (payload: P) => Promise<T>
48+
dispatch<P, T>(handler: any, name?: string): any
4849
{
49-
const key = qualifyKey(handler, this.namespace)
50+
const key = qualifyKey(handler, this.namespace, name)
5051
return (payload: P) => this.store.dispatch(key, payload, useRootNamespace)
5152
}
5253

0 commit comments

Comments
 (0)