فهرست منبع

types: add subscribe options type (#1724)

Kia King Ishii 5 سال پیش
والد
کامیت
e2b9974f9d
2فایلهای تغییر یافته به همراه10 افزوده شده و 2 حذف شده
  1. 6 2
      types/index.d.ts
  2. 4 0
      types/test/index.ts

+ 6 - 2
types/index.d.ts

@@ -18,8 +18,8 @@ export declare class Store<S> {
   dispatch: Dispatch;
   commit: Commit;
 
-  subscribe<P extends MutationPayload>(fn: (mutation: P, state: S) => any): () => void;
-  subscribeAction<P extends ActionPayload>(fn: SubscribeActionOptions<P, S>): () => void;
+  subscribe<P extends MutationPayload>(fn: (mutation: P, state: S) => any, options?: SubscribeOptions): () => void;
+  subscribeAction<P extends ActionPayload>(fn: SubscribeActionOptions<P, S>, options?: SubscribeOptions): () => 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;
@@ -72,6 +72,10 @@ export interface ActionPayload extends Payload {
   payload: any;
 }
 
+export interface SubscribeOptions {
+  prepend?: boolean
+}
+
 export type ActionSubscriber<P, S> = (action: P, state: S) => any;
 
 export interface ActionSubscribersObject<P, S> {

+ 4 - 0
types/test/index.ts

@@ -39,6 +39,8 @@ namespace StoreInstance {
     state.value;
   });
 
+  store.subscribe(() => {}, { prepend: true });
+
   store.subscribeAction((action, state) => {
     action.type;
     action.payload;
@@ -74,6 +76,8 @@ namespace StoreInstance {
     }
   });
 
+  store.subscribeAction({}, { prepend: true });
+
   store.replaceState({ value: 10 });
 }