Skip to content

Commit e2b9974

Browse files
authored
types: add subscribe options type (#1724)
1 parent 38c11dc commit e2b9974

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

types/index.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export declare class Store<S> {
1818
dispatch: Dispatch;
1919
commit: Commit;
2020

21-
subscribe<P extends MutationPayload>(fn: (mutation: P, state: S) => any): () => void;
22-
subscribeAction<P extends ActionPayload>(fn: SubscribeActionOptions<P, S>): () => void;
21+
subscribe<P extends MutationPayload>(fn: (mutation: P, state: S) => any, options?: SubscribeOptions): () => void;
22+
subscribeAction<P extends ActionPayload>(fn: SubscribeActionOptions<P, S>, options?: SubscribeOptions): () => void;
2323
watch<T>(getter: (state: S, getters: any) => T, cb: (value: T, oldValue: T) => void, options?: WatchOptions): () => void;
2424

2525
registerModule<T>(path: string, module: Module<T, S>, options?: ModuleOptions): void;
@@ -72,6 +72,10 @@ export interface ActionPayload extends Payload {
7272
payload: any;
7373
}
7474

75+
export interface SubscribeOptions {
76+
prepend?: boolean
77+
}
78+
7579
export type ActionSubscriber<P, S> = (action: P, state: S) => any;
7680

7781
export interface ActionSubscribersObject<P, S> {

types/test/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ namespace StoreInstance {
3939
state.value;
4040
});
4141

42+
store.subscribe(() => {}, { prepend: true });
43+
4244
store.subscribeAction((action, state) => {
4345
action.type;
4446
action.payload;
@@ -74,6 +76,8 @@ namespace StoreInstance {
7476
}
7577
});
7678

79+
store.subscribeAction({}, { prepend: true });
80+
7781
store.replaceState({ value: 10 });
7882
}
7983

0 commit comments

Comments
 (0)