Преглед на файлове

Add MutationPayload type (#869)

* Add MutationPayload type

On the subscribe function, the mutation object was only having the `type` property and missing the payload

* Add tests for MutationPayload
Alex Jover преди 7 години
родител
ревизия
fd2b188fe5
променени са 2 файла, в които са добавени 6 реда и са изтрити 1 реда
  1. 5 1
      types/index.d.ts
  2. 1 0
      types/test/index.ts

+ 5 - 1
types/index.d.ts

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

+ 1 - 0
types/test/index.ts

@@ -35,6 +35,7 @@ namespace StoreInstance {
 
 
   store.subscribe((mutation, state) => {
   store.subscribe((mutation, state) => {
     mutation.type;
     mutation.type;
+    mutation.payload;
     state.value;
     state.value;
   });
   });