Quellcode durchsuchen

Add subscribeAction in index.d.ts fixes #1066 (#1067)

Casey Corcoran vor 7 Jahren
Ursprung
Commit
ca64c3f455
2 geänderte Dateien mit 11 neuen und 0 gelöschten Zeilen
  1. 5 0
      types/index.d.ts
  2. 6 0
      types/test/index.ts

+ 5 - 0
types/index.d.ts

@@ -17,6 +17,7 @@ export declare class Store<S> {
   commit: Commit;
   commit: Commit;
 
 
   subscribe<P extends MutationPayload>(fn: (mutation: P, state: S) => any): () => void;
   subscribe<P extends MutationPayload>(fn: (mutation: P, state: S) => any): () => void;
+  subscribeAction<P extends ActionPayload>(fn: (action: P, state: S) => any): () => void;
   watch<T>(getter: (state: S, getters: any) => T, cb: (value: T, oldValue: T) => void, options?: WatchOptions): () => void;
   watch<T>(getter: (state: S, getters: any) => T, cb: (value: T, oldValue: T) => void, options?: WatchOptions): () => void;
 
 
   registerModule<T>(path: string, module: Module<T, S>, options?: ModuleOptions): void;
   registerModule<T>(path: string, module: Module<T, S>, options?: ModuleOptions): void;
@@ -62,6 +63,10 @@ export interface MutationPayload extends Payload {
   payload: any;
   payload: any;
 }
 }
 
 
+export interface ActionPayload extends Payload {
+  payload: any;
+}
+
 export interface DispatchOptions {
 export interface DispatchOptions {
   root?: boolean;
   root?: boolean;
 }
 }

+ 6 - 0
types/test/index.ts

@@ -39,6 +39,12 @@ namespace StoreInstance {
     state.value;
     state.value;
   });
   });
 
 
+  store.subscribeAction((mutation, state) => {
+    mutation.type;
+    mutation.payload;
+    state.value;
+  });
+
   store.replaceState({ value: 10 });
   store.replaceState({ value: 10 });
 }
 }